I have this init script to run uwsgi. It works, but only on the start command. All the other commands give me this error:
/etc/init.d/uwsgi: 27: /etc/init.d/uwsgi: Syntax error: ";;" unexpected
It seems like the colons should be there from the tutorials I am reading, and yet it is telling me to remove them?
#!/bin/sh
### BEGIN INIT INFO
# Provides: uwsgi
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: This script manages uWSGI.
### END INIT INFO
DAEMON=/var/www/app/venv/bin/uwsgi
PIDFILE=/var/run/uwsgi.pid
DAEMON_ARGS="--ini /var/www/app/conf/uwsgi/app.ini --pidfile /var/run/uwsgi.pid"
. /lib/init/vars.sh
. /lib/lsb/init-functions
case "$1" in
start)
echo "Starting"
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS 1> /dev/null 2>&1 \
|| return 2
esac
;;
stop)
echo "Stopping"
start-stop-daemon --stop --quiet --retry=QUIT/30/KILL/5 --pidfile $PIDFILE --name uwsgi
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
esac
;;
status)
status_of_proc "$DAEMON" "uwsgi" && exit 0 || exit $?
;;
reload)
echo "Reloading"
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name uwsgi
return 0
;;
*)
echo "Usage: /etc/init.d/uwsgi {start|stop|status|reload|force-reload}" >&2
exit 3
;;
esac
exit 0
Get rid of the esac keywords before the ;;s. There should only be one at the very end to match the initial case keyword.
Related
I am trying to log time_firstbyte and handling in a file via varnishncsa.
My /etc/init.d/varnishncsa looks like below:-
. /lib/lsb/init-functions
NAME=varnishncsa
DESC="HTTP accelerator log deamon"
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/$NAME
PIDFILE=/run/$NAME/$NAME.pid
LOGFILE=/var/log/varnish/varnishncsa.log
USER=root
LOG_FORMAT="%t %r %s %b %{Varnish:time_firstbyte}x %{Varnish:handling}x"
#VARNISHNCSA_ENABLED=1
DAEMON_OPTS="-a -w ${LOGFILE} -D -P ${PIDFILE} -F '${LOG_FORMAT}'"
# Include defaults if available
if [ -f /etc/default/$NAME ] ; then
. /etc/default/$NAME
fi
# If unset, or set to "0" or "no", exit
if [ -z "${VARNISHNCSA_ENABLED}" ] || \
[ "${VARNISHNCSA_ENABLED}" = "0" ] || \
[ "${VARNISHNCSA_ENABLED}" = "no" ]; then
exit 0;
fi
test -x $DAEMON || exit 0
start_varnishncsa() {
output=$(/bin/tempfile -s.varnish)
log_daemon_msg "Starting $DESC" "$NAME"
create_pid_directory
if start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--chuid $USER --exec ${DAEMON} -- ${DAEMON_OPTS} \
> ${output} 2>&1; then
log_end_msg 0
else
log_end_msg 1
cat $output
exit 1
fi
rm $output
}
stop_varnishncsa(){
log_daemon_msg "Stopping $DESC" "$NAME"
if start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--retry 10 --exec $DAEMON; then
log_end_msg 0
else
log_end_msg 1
fi
}
reload_varnishncsa(){
log_daemon_msg "Reloading $DESC" "$NAME"
if kill -HUP $(cat $PIDFILE) >/dev/null 2>&1; then
log_end_msg 0
else
log_end_msg 1
exit 1
fi
}
status_varnishncsa(){
status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}"
exit $?
}
create_pid_directory() {
install -o $USER -g $USER -d $(dirname $PIDFILE)
}
case "$1" in
start)
start_varnishncsa
;;
stop)
stop_varnishncsa
;;
reload)
reload_varnishncsa
;;
status)
status_varnishncsa
;;
restart|force-reload)
$0 stop
$0 start
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|force-reload|reload}"
exit 1
;;
esac
My /etc/default/varnishncsa looks like below:-
VARNISHNCSA_ENABLED=1
But while trying to do restart varnishncsa it is failing.
I am on ubuntu 12.04 with varnish 4.1.
As per this link updating my /etc/init.d/varnishncsa as below solved the issue:-
LOG_FORMAT="%h|%u|%{%Y-%m-%d}t|%{%H:%M:%S}t|%{%z}t|%m|%{Host}i|%U|%q|%s|%b|%{Referer}i|%{User-agent}i|%{Varnish:time_firstbyte}x|%T|%D|%{Varnish:handling}x|%{X-FE-Varnish-Obj-TTL}o|%{X-FE-Varnish-Backend}o|%{X-FE-Varnish-Obj-Stat}o"
DAEMON_OPTS="-a -w ${LOGFILE} -D -P ${PIDFILE} -F '${LOG_FORMAT}'"
The %T format specifier can be tricky if you are also using ntp. Because the response time can be very small - you may end up with negative values in your log file if the clock skew changes in the middle of the request. If you are post-processing your varnishncsa logs you may end up with results you were not expecting.
I try to Nginx with /etc/init.d/nginx start. It exits with value 0 and otherwise does absolutely nothing because /usr/sbin/nginx doesn't exist.
Here is /etc/init.d/nginx:
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
DESC=nginx
# Include nginx defaults if available
if [ -r /etc/default/nginx ]; then
. /etc/default/nginx
fi
test -x $DAEMON || exit 0
set -e
. /lib/lsb/init-functions
# We made the awk expression more precise:
# https://code.google.com/p/phusion-passenger/issues/detail?id=1060
PID=$(awk -F'[ \t;]+' '/[^#]\<pid/ {print $2}' /etc/nginx/nginx.conf)
if [ -z "$PID" ]
then
PID=/var/run/nginx.pid
fi
# Check if the ULIMIT is set in /etc/default/nginx
if [ -n "$ULIMIT" ]; then
# Set the ulimits
ulimit $ULIMIT
fi
test_nginx_config() {
$DAEMON -t $DAEMON_OPTS >/dev/null 2>&1
retvar=$?
if [ $retvar -ne 0 ]
then
exit $retvar
fi
}
start() {
start-stop-daemon --start --quiet --pidfile $PID \
--retry 5 --exec $DAEMON --oknodo -- $DAEMON_OPTS
}
stop() {
start-stop-daemon --stop --quiet --pidfile $PID \
--retry 5 --oknodo --exec $DAEMON
}
case "$1" in
start)
test_nginx_config
log_daemon_msg "Starting $DESC" "$NAME"
start
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
stop
log_end_msg $?
;;
restart|force-reload)
test_nginx_config
log_daemon_msg "Restarting $DESC" "$NAME"
stop
sleep 1
start
log_end_msg $?
;;
reload)
test_nginx_config
log_daemon_msg "Reloading $DESC configuration" "$NAME"
start-stop-daemon --stop --signal HUP --quiet --pidfile $PID \
--oknodo --exec $DAEMON
log_end_msg $?
;;
configtest|testconfig)
log_daemon_msg "Testing $DESC configuration"
if test_nginx_config; then
log_daemon_msg "$NAME"
else
exit $?
fi
log_end_msg $?
;;
status)
status_of_proc -p $PID "$DAEMON" nginx
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
exit 1
;;
esac
exit 0
I see that it exits with value 0 because of the test -x $DAEMON || exit 0 line. If I comment that line out then the script will stop suddenly inside of the test_nginx_config() function when it goes to run the daemon (/usr/sbin/nginx) which doesn't exist. There is no /usr/local/nginx/ directory either, for what it's worth.
I'm a total newbie at this stuff so there might be something dumb simple going on but I just need to get this started up. Any help would be greatly appreciated.
Well, if this is your start up script and nginx used to work with it then, Nginx has been removed by something or someone.
I have a mono C# mono application with a simple menu that doesn't even need an input to work. What I want to do is to start the application on startup without using StartUp for ubuntu.I'm using raspbian and want to start the application as a background process, not service.
What I have so far is the command to start it:
start-stop-daemon --start --quiet --pidfile /home/pi/pid/EDM.pid --exec /home/pi/Mono/EDM.exe --test
What I need is to run this command when the OS boots. I've tried this script:
#! /bin/sh
### BEGIN INIT INFO
# Provides: mn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
# Author:
#
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Mono Daemon"
NAME=EDM.exe
DAEMON=/home/po/Mono/EDM.exe
PIDFILE=/home/pi/pid/EDM.pid
SCRIPTNAME=/etc/init.d/mn.sh
CHUID=pi
# Exit if the package is not installed
[ -x "/home/pi/Mono/EDM.exe" ] || exit 0
# Read configuration variable file if it is present
#[ -r /etc/default/EDM.exe ] && . /etc/default/EDM.exe
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile /home/pi/pid/EDM.pid --exec /home/pi/Mono/EDM.exe --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --chuid root --pidfile /home/pi/pid/EDM.pid --exec /home/pi/Mono/EDM.exe -- \
/home/pi/Mono/EDM.exe_ARGS \
|| return 2
}
#
# 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
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile /home/pi/pid/EDM.pid --name EDM.exe
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec /home/pi/Mono/EDM.exe
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f /home/pi/pid/EDM.pid
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile /home/pi/pid/EDM.pid --name EDM.exe
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "EDM.exe"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "EDM.exe"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "EDM.exe"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "EDM.exe"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
I use update-rc.d mn defaults and it shows the following errors:
update-rc.d:
using dependency based boot sequencing
insserv: Script mn is broken: incomplete LSB comment.
insserv: missing `Provides:' entry: please add.
insserv: missing `Required-Start:' entry: please add even if empty.
insserv: missing `Required-Stop:' entry: please add even if empty.
insserv: missing `Default-Start:' entry: please add even if empty.
insserv: missing `Default-Stop:' entry: please add even if empty.
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `mn'
insserv: Default-Stop undefined, assuming empty stop runlevel(s) for script `mn'
Any ideas how to do it?
In the end the best way to do this was to make an extremely simple bash script that runs the command:
#!/bin/bash
start-stop-daemon --start --background -m --oknodo --pidfile /home/pi/pid/MonoDaemon.pid --exec /usr/bin/mono -- /home/pi/Mono/EDM.exe
After that I added a row in /etc/init.d/rc.local
/bin/bash /etc/init.d/mnw
I am creating a daemon process. This process depends on MYSQL, however my process alwasy starts at boot before mysql. How do I make my daemon start after mysql starts at boot time?
I do not see any mysql related scripts in the rc.x.d folders such that I can change the numbering.
Do I have put delays in my daemon waiting for mysql to load?
Also, how do I register the daemon such that I can just do
start mydaemon
and the process will start? I just get
"start: unknown job: mydaemon"
Is there any way to report back from the daemon whether or not startup was successful when using the "start" command?
I am using Ubuntu.
Here is my script for startup, based off Ubuntu's provided Skeleton script.
I ran the following to register the daemon already. I know it is running # startup from message log.
update-rc.d mydaemon default
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Foo Bar <foobar#baz.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Daemon"
NAME=mydaemon
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS=""
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
#
# 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
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
The SysV init system in modern Ubuntu is legacy support, the main startup system is Upstart, which allows you to specify a dependency on mysql.
start and stop are controls for daemons managed by the upstart system - the control/configuration files for these daemons go to /etc/init
I am having issues getting my homemade daemon working. This is on Ubuntu
Whenever I call
service mydaemon start
The daemon starts, but never I never get control back to the console. It is like the process is not forking or something....
Here is what I do at the beginning of my daemon process.
pid_t pid;
//fork duplicates the current process
pid = fork();
//The parent process should get a non-zero pid from fork
//The child process should get 0
if (pid < 0) //negative indicates error
{
cout << "Error starting Daemon.";
exit(EXIT_FAILURE);
}
else if (pid > 0) //parent process, exit success
{
cout << "Error starting Daemon. PID=" << pid;
exit(EXIT_SUCCESS);
}
//file permisions??
umask(0);
//Child process set to new session so it is process group leader
pid_t sid = setsid();
if(sid < 0)
{
exit(EXIT_FAILURE);
}
if(chdir("/") < 0)
{
exit(EXIT_FAILURE);
}
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
Here is my inti.d daemon config file.
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Foo Bar <foobar#baz.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="my daemon"
NAME=mydaemon
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS=""
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
for i in 0 1 2 3 4 5
do
if [ "$(pidof mysqld)" ]
then
sleep 2
break
else
sleep 2
fi
done
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
#
# 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
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
This works for me:
start)
echo "Starting $NAME"
start-stop-daemon --start -m --quiet -b --pidfile $PIDFILE --exec $DAEMON >> $LOG || exit 1
;;
stop)
echo "Stopping $NAME"
start-stop-daemon --stop --pidfile $PIDFILE || exit 1
;;;
Can't get logging to work with the above, but that's related to start-stop-daemon