-
Notifications
You must be signed in to change notification settings - Fork 24
/
tempalias.js
45 lines (39 loc) · 1.07 KB
/
tempalias.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require.paths.unshift('lib');
require.paths.unshift('./deps/node-paperboy/lib');
require.paths.unshift('./deps/redis-node-client/lib');
require.paths.unshift('./deps/node-smtp/lib');
var config = require('config');
var fs = require('fs');
var sys = require('sys');
process.addListener('uncaughtException', function (err) {
sys.error('Caught exception: ' + err);
sys.error(err.stack);
});
var launch = function(){
fs.writeFile(config.general.pidFile, ""+process.pid, function(err, data){
if (err){
sys.error("Failed to write PID file ("+ config.general.pidFile+"): " + err);
process.exit(1);
}
require('tempalias_http');
require('tempalias_smtp');
});
};
try{
var pd = fs.statSync(config.general.pidFile);
}catch(e){
pd = null;
}
if (pd && pd.isFile()){
sys.puts('PID file found. Attempting to kill previous instance if running');
fs.readFile(config.general.pidFile, function(err, pid){
if (!err){
try{
process.kill(parseInt(pid, 10), 'SIGTERM');
}catch(e){}
}
launch();
});
}else{
launch();
}