3 # Example init.d script with LSB support.
5 # Please read this init.d carefully and modify the sections to
6 # adjust it to the program you want to run.
8 # Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
10 # This is free software; you may redistribute it and/or modify
11 # it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation; either version 2,
13 # or (at your option) any later version.
15 # This is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License with
21 # the Debian operating system, in /usr/share/common-licenses/GPL; if
22 # not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
27 # Required-Start: $network $local_fs
29 # Should-Start: $named
31 # Default-Start: 2 3 4 5
33 # Short-Description: <Enter a short description of the sortware>
34 # Description: <Enter a long description of the software>
39 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
41 DAEMON=/usr/sbin/freeside # Introduce the server's location here
42 NAME=#PACKAGE # Introduce the short server's name here
43 DESC=#PACKAGE # Introduce a short description here
44 LOGDIR=/var/log/freeside # Log directory to use
46 PIDFILE=/var/run/$NAME.pid
48 test -x $DAEMON || exit 0
49 test -x $DAEMON_WRAPPER || exit 0
51 . /lib/lsb/init-functions
53 # Default options, these can be overriden by the information
54 # at /etc/default/$NAME
55 DAEMON_OPTS="" # Additional options given to the server
57 DODTIME=10 # Time to wait for the server to die, in seconds
58 # If this value is set too low you might not
59 # let some servers to die gracefully and
60 # 'restart' will not work
62 LOGFILE=$LOGDIR/$NAME.log # Server logfile
63 #DAEMONUSER=freeside # Users to run the daemons as. If this value
64 # is set start-stop-daemon will chuid the server
66 # Include defaults if available
67 if [ -f /etc/default/$NAME ] ; then
71 # Use this if you want the user to explicitly set 'RUN' in
73 #if [ "x$RUN" != "xyes" ] ; then
74 # log_failure_msg "$NAME disabled, please adjust the configuration to your needs "
75 # log_failure_msg "and then set RUN to 'yes' in /etc/default/$NAME to enable it."
79 # Check that the user exists (if we set a user)
80 # Does the user exist?
81 if [ -n "$DAEMONUSER" ] ; then
82 if getent passwd | grep -q "^$DAEMONUSER:"; then
83 # Obtain the uid and gid
84 DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
85 DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
87 log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
96 # Check if a given process pid's cmdline matches a given name
99 [ -z "$pid" ] && return 1
100 [ ! -d /proc/$pid ] && return 1
101 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
102 # Is this the expected server
103 [ "$cmd" != "$name" ] && return 1
108 # Check if the process is running looking at /proc
109 # (works for all users)
111 # No pidfile, probably no daemon present
112 [ ! -f "$PIDFILE" ] && return 1
114 running_pid $pid $DAEMON_WRAPPER || return 1
119 # Start the process using the wrapper
120 if [ -z "$DAEMONUSER" ] ; then
121 start-stop-daemon --start --quiet --pidfile $PIDFILE \
122 --exec $DAEMON -- $DAEMON_OPTS
125 # if we are using a daemonuser then change the user id
126 start-stop-daemon --start --quiet --pidfile $PIDFILE \
127 --chuid $DAEMONUSER \
128 --exec $DAEMON -- $DAEMON_OPTS
135 # Stop the process using the wrapper
136 if [ -z "$DAEMONUSER" ] ; then
137 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
141 # if we are using a daemonuser then look for process that match
142 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
152 [ ! -f "$PIDFILE" ] && return 1
153 pid=`cat $PIDFILE` # This is the daemon's pid
160 # Force the process to die killing it manually
161 [ ! -e "$PIDFILE" ] && return
170 echo "Cannot kill $NAME (pid=$pid)!"
181 log_daemon_msg "Starting $DESC " "$NAME"
182 # Check if it's running first
184 log_progress_msg "apparently already running"
188 if start_server && running ; then
189 # It's ok, the server started and is running
192 # Either we could not start it or it is not running
194 # NOTE: Some servers might die some time after they start,
195 # this code does not try to detect this and might give
196 # a false positive (use 'status' for that)
201 log_daemon_msg "Stopping $DESC" "$NAME"
203 # Only stop the server if we see it running
207 # If it's not running don't do anything
208 log_progress_msg "apparently not running"
214 # First try to stop gracefully the program
217 # If it's still running try to kill it more forcefully
218 log_daemon_msg "Stopping (force) $DESC" "$NAME"
223 restart|force-reload)
224 log_daemon_msg "Restarting $DESC" "$NAME"
226 # Wait some sensible amount, some server need this
227 [ -n "$DIETIME" ] && sleep $DIETIME
234 log_daemon_msg "Checking status of $DESC" "$NAME"
236 log_progress_msg "running"
239 log_progress_msg "apparently not running"
244 # Use this if the daemon cannot reload
246 log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
247 log_warning_msg "cannot re-read the config file (use restart)."
249 # And this if it cann
252 # If the daemon can reload its config files on the fly
253 # for example by sending it SIGHUP, do it here.
255 # If the daemon responds to changes in its config file
256 # directly anyway, make this a do-nothing entry.
258 # log_daemon_msg "Reloading $DESC configuration files" "$NAME"
261 # if ! running ; then
262 # Process died after we tried to reload
263 # log_progress_msg "died on reload"
268 # log_progress_msg "server is not running"
276 echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2