-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.coffee
More file actions
55 lines (37 loc) · 1.79 KB
/
runner.coffee
File metadata and controls
55 lines (37 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
forever = require "forever"
fs = require "fs"
module.exports = class Runner
constructor: (@path,@env) ->
console.log "env is ", @env
@instance = null
@old = []
@_startInstance()
# if we get a HUP, pass it through to our instance
process.on "SIGHUP", => process.kill @instance.child.pid, "SIGHUP"
process.on "SIGTERM", =>
# need to shut down instance and any old instances
process.kill @instance.child.pid, "SIGTERM"
# set up watcher on tmp/restart.txt
# it needs to exist for us to watch it...
@watcher = fs.watchFile "#{@path}/tmp/restart.txt", => @_startInstance()
#----------
_startInstance: ->
if @instance
# need to handle graceful shutdown for an existing instance
oldinstance = @instance
# keep track of the instance
@old.push oldinstance
# send TERM signal to old instance, causing it to release the
# listening port
oldinstance.forceStop = true
process.kill oldinstance.child.pid, "SIGTERM"
@instance = null
# now start our new process
@instance = new (forever.Monitor) "#{@path}/node_modules/StreamMachine/index.js", options:["--config=#{@path}/config/#{@env}.json"]
@instance.on "restart", (forever) =>
console.log "got restart event of ", forever
@instance.on "start", (ever) =>
console.log "got start with ", ever
@instance.start()
#forever.startServer(@instance)
console.log "instance is ", @instance.child.pid