forked from hobbyquaker/ccu.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccu.io-server.js
54 lines (44 loc) · 1.18 KB
/
ccu.io-server.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
45
46
47
48
49
50
51
52
53
54
var daemon = require("daemonize2").setup({
main: "ccu.io.js",
name: "ccu.io",
pidfile: "ccu.io.pid"
});
var fs = require('fs');
switch (process.argv[2]) {
case "start":
checkDirPermission(__dirname+"/datastore");
checkDirPermission(__dirname+"/log");
daemon.start();
break;
case "stop":
daemon.stop();
break;
case "kill":
daemon.kill();
break;
case "restart":
daemon.stop(function(err) {
checkDirPermission(__dirname+"/datastore");
checkDirPermission(__dirname+"/log");
daemon.start();
});
break;
case "status":
var pid = daemon.status();
if (pid)
console.log("Daemon running. PID: " + pid);
else
console.log("Daemon is not running.");
break;
default:
console.log("Usage: [start|stop|kill|restart|status]");
}
function checkDirPermission(path) {
try {
fs.writeFileSync(path+'/permission.test', 'test');
} catch (e) {
console.log("Error: no permission to write in "+path);
process.exit(1);
}
fs.unlinkSync(path+'/permission.test');
}