-
Notifications
You must be signed in to change notification settings - Fork 1
/
node-server
96 lines (85 loc) · 2.32 KB
/
node-server
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /bin/sh
### BEGIN INIT INFO
# Provides: NodeJS
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: NodeJS HTTP Server start/stop script
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
DEAMON_NAME="node"
DAEMON_BIN="/usr/bin/$DEAMON_NAME"
DAEMON_EXEC="/etc/init.d//node-exec"
DAEMON_USER="{your-user-uid:your-user-gid}"
DAEMON_DESC="NodeJS HTTP Server"
DAEMON_PID_FILE="/var/run/$DEAMON_NAME.pid"
test -x $DAEMON_BIN || exit 0
. /lib/lsb/init-functions
do_start()
{
# --make-pidfile --pidfile $DAEMON_PID_FILE
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
log_daemon_msg "Starting $DAEMON_DESC"
start-stop-daemon --start --quiet --background --chuid $DAEMON_USER --exec $DAEMON_EXEC --test > /dev/null || return 1
start-stop-daemon --start --quiet --background --chuid $DAEMON_USER --exec $DAEMON_EXEC || return 1
return $?
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
log_daemon_msg "Stopping $DAEMON_DESC"
start-stop-daemon --stop --oknodo --retry=0/30/KILL/5 --quiet --name $DEAMON_NAME
RETVAL="$?"
test -x $DAEMON_PID_FILE && rm -f $DAEMON_PID_FILE
return $RETVAL
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
log_daemon_msg "Reloading $DAEMON_DESC"
start-stop-daemon --stop --signal 1 --quiet --name $DEAMON_NAME
return 0
}
case "$1" in
start)
do_start
log_end_msg $?
;;
stop)
do_stop
log_end_msg $?
;;
status)
status_of_proc "$DAEMON_BIN" "$DEAMON_NAME" && exit 0 || exit $?
;;
restart)
do_stop
log_end_msg $?
sleep 2
do_start
log_end_msg $?
;;
reload|force-reload)
do_reload
log_end_msg $?
;;
*)
echo "Usage: $DEAMON_NAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
: