Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

TERM,INT,QUIT,KILL

  • Loading branch information...
commit 257250836e03f22af1011f33b6dd8c162d78c273 1 parent 57689a4
Paul Driver authored
5 README.markdown
View
@@ -59,8 +59,9 @@ some sort of stringifiable error object. Defaults to init.startFailed.
### init.stop(pidfile, cb)
-Stop your service. cb will be called after the process is killed, and defaults
-to init.stopped. If the process was running, cb's first argument will be true.
+Sends your service TERM, INT, QUIT, in that order (with 2 second delays) and
+then KILL until the process is no longer running, then calls cb (defaults to
+init.stopped). If the process was running, cb's first argument will be true.
### init.status(pidfile, cb)
11 examples/test.coffee
View
@@ -5,7 +5,16 @@ snorlax = ->
console.log if snore then "Snore..." else "Lax..."
snore = not snore
+
+start = ->
+ interval = setInterval snorlax, 4000
+ process.on 'SIGTERM', -> console.log 'Mmm,mm.'
+ process.on 'SIGINT', -> console.log 'Mmmm!.'
+ process.on 'SIGQUIT', ->
+ console.log 'Mrpmph!'
+ clearInterval interval
+
init.simple
pidfile : './test.pid'
logfile : './test.log'
- run : -> setInterval snorlax, 4000
+ run : start
16 init.coffee
View
@@ -71,15 +71,17 @@ exports.stopped = (killed) ->
exports.stop = (pidfile, cb = exports.stopped) ->
exports.status pidfile, ({pid}) ->
if pid
- n = 0
- do ->
- signal = if n > 3 then 'SIGKILL' else 'SIGTERM'
+ signals = ['TERM', 'INT', 'QUIT', 'KILL']
+ tryKill = ->
+ sig = "SIG#{ signals[0] }"
try
- process.kill pid
- n += 1
- setTimeout arguments.callee, 1000
+ # throws when the process no longer exists
+ process.kill pid, sig
+ signals.shift() if signals.length > 1
+ setTimeout (-> tryKill sig), 2000
catch e
- fs.unlink pidfile, -> cb(n > 0)
+ fs.unlink pidfile, -> cb(signals.length < 4)
+ tryKill()
else
cb false
2  package.json
View
@@ -12,7 +12,7 @@
"name" : "Paul Driver"
}
],
- "version" : "0.1.0",
+ "version" : "0.1.1",
"licences" : [
{
"url" : "http://www.opensource.org/licenses/mit-license",
Please sign in to comment.
Something went wrong with that request. Please try again.