Debian Codegraph @

debian/init

raw
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides: camo
4 # Required-Start: $remote_fs $syslog
5 # Required-Stop: $remote_fs $syslog
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: initscript to start the camo image proxy service
9 ### END INIT INFO
10
11 # Author: Luke Faraone <[email protected]>
12
13 # PATH should only include /usr/* if it runs after the mountnfs.sh script
14 PATH=/sbin:/usr/sbin:/bin:/usr/bin
15 DESC="manage the camo image proxy service"
16 NAME=camo
17 SCRIPT_PATH=/usr/share/camo/server.js
18 DAEMON="/usr/bin/nodejs $SCRIPT_PATH"
19 PIDFILE=/var/run/$NAME.pid
20 SCRIPTNAME=/etc/init.d/$NAME
21
22 # Load the VERBOSE setting and other rcS variables
23 . /lib/init/vars.sh
24
25 # Define LSB log_* functions.
26 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
27 # and status_of_proc is working.
28 . /lib/lsb/init-functions
29
30 # Exit if the package is not installed
31 [ -e "$SCRIPT_PATH" ] || exit 0
32
33 ENABLED=yes
34
35 # Read configuration variable file if it is present
36 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
37
38 export CAMO_KEY PORT
39
40 if [ "$ENABLED" != "yes" ]; then
41 log_warning_msg "Service is disabled"
42 exit 0
43 fi
44
45 #
46 # Function that starts the daemon/service
47 #
48 do_start()
49 {
50 # Return
51 # 0 if daemon has been started
52 # 1 if daemon was already running
53 # 2 if daemon could not be started
54 start-stop-daemon --start --quiet --pidfile $PIDFILE -bm --exec $DAEMON --no-close -c nobody --test > /dev/null 2>&1 \
55 || return 1
56 start-stop-daemon --start --quiet --pidfile $PIDFILE -bm --no-close -c nobody --exec $DAEMON -- \
57 $DAEMON_ARGS >> /var/log/camo/camo.log 2>&1 \
58 || return 2
59 # Add code here, if necessary, that waits for the process to be ready
60 # to handle requests from services started subsequently which depend
61 # on this one. As a last resort, sleep for some time.
62 }
63
64 #
65 # Function that stops the daemon/service
66 #
67 do_stop()
68 {
69 # Return
70 # 0 if daemon has been stopped
71 # 1 if daemon was already stopped
72 # 2 if daemon could not be stopped
73 # other if a failure occurred
74 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON
75 RETVAL="$?"
76 [ "$RETVAL" = 2 ] && return 2
77 # Wait for children to finish too if this is a daemon that forks
78 # and if the daemon is only ever run from this initscript.
79 # If the above conditions are not satisfied then add some other code
80 # that waits for the process to drop all resources that could be
81 # needed by services started subsequently. A last resort is to
82 # sleep for some time.
83 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
84 [ "$?" = 2 ] && return 2
85 # Many daemons don't delete their pidfiles when they exit.
86 rm -f $PIDFILE
87 return "$RETVAL"
88 }
89
90 case "$1" in
91 start)
92 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
93 do_start
94 case "$?" in
95 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
96 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
97 esac
98 ;;
99 stop)
100 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
101 do_stop
102 case "$?" in
103 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
104 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
105 esac
106 ;;
107 status)
108 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
109 ;;
110 #reload|force-reload)
111 #
112 # If do_reload() is not implemented then leave this commented out
113 # and leave 'force-reload' as an alias for 'restart'.
114 #
115 #log_daemon_msg "Reloading $DESC" "$NAME"
116 #do_reload
117 #log_end_msg $?
118 #;;
119 restart|force-reload)
120 #
121 # If the "reload" option is implemented then remove the
122 # 'force-reload' alias
123 #
124 log_daemon_msg "Restarting $DESC" "$NAME"
125 do_stop
126 case "$?" in
127 0|1)
128 do_start
129 case "$?" in
130 0) log_end_msg 0 ;;
131 1) log_end_msg 1 ;; # Old process is still running
132 *) log_end_msg 1 ;; # Failed to start
133 esac
134 ;;
135 *)
136 # Failed to stop
137 log_end_msg 1
138 ;;
139 esac
140 ;;
141 *)
142 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
143 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
144 exit 3
145 ;;
146 esac
147
148 :