-
Notifications
You must be signed in to change notification settings - Fork 5
/
Cakefile
68 lines (50 loc) · 1.89 KB
/
Cakefile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
{spawn, exec} = require 'child_process'
path = require 'path'
app = "emotions"
mainfile = "emotions.coffee"
option '-e', '--environment [ENVIRONMENT_NAME]', 'set the environment for `restart`'
task 'build', ->
###
task 'restart', 'Restart #{app}', (options) ->
invoke 'build'
run 'PATH=/usr/bin:/usr/local/bin:/opt/local/bin && kill -9 `pgrep -f "coffee '+mainfile+'"`'
run "coffee #{mainfile}"
###
task 'start', "Start #{app}", (options) ->
invoke 'build'
run "coffee #{mainfile}"
task 'stop', "Stop #{app}", (options) ->
run 'PATH=/usr/bin:/usr/local/bin:/opt/local/bin && kill -9 `pgrep -f "coffee '+mainfile+'"`'
task 'restart', "Restart #{app}", (options) ->
invoke 'stop'
invoke 'start'
foreverBinary = "node_modules/forever/bin/forever"
forever = (action, options) ->
invoke 'build'
options.environment or= 'production'
run "NODE_ENV=#{options.environment} " +
"#{foreverBinary} #{action} -c coffee " +
" --sourceDir ./" +
" -l #{app}.log "+
#" -o logs/#{app}.out "+
#" -e logs/#{app}.err "+
" -a" + # append logs
" #{mainfile}"
task 'forever-restart', (options) -> forever 'restart', options
task 'forever-start', (options) -> forever 'start', options
task 'forever-stop', (options) -> run "#{foreverBinary} stop -c coffee #{mainfile}"
task 'forever-list', (options) -> run "#{foreverBinary} list"
run = (args...) ->
for a in args
switch typeof a
when 'string' then command = a
when 'object'
if a instanceof Array then params = a
else options = a
when 'function' then callback = a
command += ' ' + params.join ' ' if params?
cmd = spawn '/bin/sh', ['-c', command], options
cmd.stdout.on 'data', (data) -> process.stdout.write data
cmd.stderr.on 'data', (data) -> process.stderr.write data
process.on 'SIGHUP', -> cmd.kill()
cmd.on 'exit', (code) -> callback() if callback? and code is 0