Permalink
Browse files

naught actually checks whether the process is running

instead of only relying on naught.json pidfile.
  • Loading branch information...
1 parent 4cfe36d commit b6e334c3a9a751829a6fdbd2ec6e5a3b7b063895 @andrewrk andrewrk committed Sep 19, 2012
Showing with 17 additions and 4 deletions.
  1. +0 −1 README
  2. +11 −3 src/main.co
  3. +6 −0 src/ps.co
View
1 README
@@ -8,7 +8,6 @@ features:
- TODO
* runs as daemon, providing ability to start and stop
- TODO: when stopping, first try 'shutdown', timeout to sigterm, timeout to sigkill
- - TODO: status actually checks whether the process is running
usage:
View
@@ -35,9 +35,17 @@ function chompArgv(obj, argv)
try
pids = JSON.parse(data)
catch
- console.error "Invalid pidfile: #{pidfile}"
+ console.error "Invalid pidfile: #pidfile"
process.exit(1)
- cb(pids)
+ ps = require('./ps')
+ ps.isRunning pids.master, !(err, is_running) ->
+ assert.ifError err
+ if not is_running
+ console.error "server not running"
+ fs.unlinkSync(pidfile)
+ process.exit(1)
+ return
+ cb(pids)
function getDaemonMessages (socket_path, cbs)
socket = net.connect socket_path, cbs.ready
@@ -82,7 +90,7 @@ function getDaemonMessages (socket_path, cbs)
catch e
if e.code is \ESRCH
console.error("No process killed with pid #{pids.master}.")
- console.error("`rm #{pidfile}` manually after ensuring your server is not already running.")
+ console.error("`rm #pidfile` manually after ensuring your server is not already running.")
else
throw e
View
@@ -0,0 +1,6 @@
+const {execFile} = require('child_process')
+
+# cb(err, process_is_running)
+export !function isRunning(pid, cb)
+ child = execFile 'ps', ['-p', pid, '-o', 'comm='], !(err, stdout, stderr) ->
+ cb(not err and not stderr)

0 comments on commit b6e334c

Please sign in to comment.