diff options
author | Mike Gerwitz <gerwitzm@lovullo.com> | 2017-09-12 15:29:43 -0400 |
---|---|---|
committer | Mike Gerwitz <gerwitzm@lovullo.com> | 2017-09-12 15:29:43 -0400 |
commit | 4dda515821a9a05f73da082a11049b0c302858f1 (patch) | |
tree | b46ab64106ccddb10a7680771629d7ac9b171d44 | |
parent | d1d2c4e5c99be95641713635f23f3da238ca0aaf (diff) | |
download | liza-4dda515821a9a05f73da082a11049b0c302858f1.tar.gz liza-4dda515821a9a05f73da082a11049b0c302858f1.tar.bz2 liza-4dda515821a9a05f73da082a11049b0c302858f1.zip |
Re-add pidfilev3.1.0
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.
-rw-r--r-- | bin/server.js | 19 | ||||
-rw-r--r-- | 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 }, |