-
Notifications
You must be signed in to change notification settings - Fork 1
/
api-init
executable file
·78 lines (66 loc) · 1.39 KB
/
api-init
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
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
#
# initd a node app
# Based on a script posted by https://gist.github.com/jinze at https://gist.github.com/3748766
#
# Source function library.
. /lib/lsb/init-functions
pidFile=/var/run/api.pid
logFile=/var/run/api.log
nodeApp=bin/www
start() {
echo "Starting $nodeApp"
# This is found in the library referenced at the top of the script
start_daemon
# Notice that we change the PATH because on reboot
# the PATH does not include the path to node.
# Launching forever with a full path
# does not work unless we set the PATH.
PATH=/usr/local/bin:$PATH
export NODE_ENV=production
#PORT=80
forever start --pidFile $pidFile -l $logFile -a -d $nodeApp
RETVAL=$?
}
update() {
echo "Updating..."
git fetch origin master && git reset --hard origin/master
restart
}
restart() {
echo "Restarting $nodeApp"
/usr/local/bin/forever restart $nodeApp
RETVAL=$?
}
stop() {
echo "Shutting down $nodeApp"
/usr/local/bin/forever stop $nodeApp
RETVAL=$?
}
status() {
echo "Status $nodeApp"
/usr/local/bin/forever list
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
update)
update
;;
*)
echo "Usage: {start|stop|status|restart|update}"
exit 1
;;
esac
exit $RETVAL