Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/server.js19
-rw-r--r--conf/vanilla-server.json2
2 files changed, 18 insertions, 3 deletions
diff --git a/bin/server.js b/bin/server.js
index 6929fca..e44688c 100644
--- a/bin/server.js
+++ b/bin/server.js
@@ -47,13 +47,17 @@ ConfLoader( fs, ConfStore )
.then( conf => Promise.all( [
conf.get( 'name' ),
conf.get( 'daemon' ),
+ conf.get( 'pidfile' ),
Promise.resolve( conf ),
] ) )
- .then( ([ name, daemon, conf ]) =>
+ .then( ([ name, daemon, pidfile, conf ]) =>
{
const daemon_path = conf_dir + '/' + daemon;
+ const pid_path = conf_dir + '/' + ( pidfile || ".pid" );
+
+ writePidFile( pid_path );
+ greet( name, pid_path );
- greet( name );
return require( daemon_path )( conf ).start();
} )
.catch( e => {
@@ -62,8 +66,17 @@ ConfLoader( fs, ConfStore )
} );
-function greet( name )
+function writePidFile( pid_path )
+{
+ fs.writeFile( pid_path, process.pid );
+
+ process.on( 'exit', () => fs.unlink( pid_path ) );
+}
+
+
+function greet( name, pid_path )
{
console.log( `${name} (liza-${version})`);
console.log( `Server configuration: ${conf_path}` );
+ console.log( `PID file: ${pid_path}` );
}
diff --git a/conf/vanilla-server.json b/conf/vanilla-server.json
index 14f7fc5..5e5da12 100644
--- a/conf/vanilla-server.json
+++ b/conf/vanilla-server.json
@@ -2,6 +2,8 @@
"name": "Liza Server",
"daemon": "../src/server/daemon/DevDaemon",
+ "pidfile": "",
+
"http": {
"port": 8822
},