From 4dda515821a9a05f73da082a11049b0c302858f1 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 12 Sep 2017 15:29:43 -0400 Subject: [PATCH] Re-add pidfile Configurable via the `pidfile' config option. * bin/server.js: Accept `pidfile' config. Include path in greeting. (writePidFile): Write to `pidfile' and unlink after exit. * conf/vanilla-server.json (pidfile): Add configuration key. --- bin/server.js | 19 ++++++++++++++++--- conf/vanilla-server.json | 2 ++ 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 },