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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#!/bin/sh
# daemon - http://libslack.org/daemon/
#
# Copyright (C) 1999-2010 raf <raf@raf.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# or visit http://www.gnu.org/copyleft/gpl.html
#
# 20100612 raf <raf@raf.org>
# This is an example /etc/init.d script that shows how to use daemon(1)
# in that context. Note that this would need to be modified quite a bit
# to meet the usual conventions of any specific system but if you aren't
# concerned about that it should be usable. At least it's a starting point.
# The daemon's name (to ensure uniqueness and for stop, restart and status)
name="EXAMPLE"
# The path of the client executable
command="/usr/bin/EXAMPLE"
# Any command line arguments for the client executable
command_args=""
# The path of the daemon executable
daemon="/usr/bin/daemon"
[ -x "$daemon" ] || exit 0
[ -x "$command" ] || exit 0
# Note: The following daemon option arguments could be in /etc/daemon.conf
# instead. That would probably be better because if the command itself were
# there as well then we could just use the name here to start the daemon.
# Here's some code to do it here in case you prefer that.
# Any command line arguments for the daemon executable (when starting)
daemon_start_args="" # e.g. --inherit --env="ENV=VAR" --unsafe
# The pidfile directory (need to force this so status works for normal users)
pidfiles="/var/run"
# The user[:group] to run as (if not to be run as root)
user=""
# The path to chroot to (otherwise /)
chroot=""
# The path to chdir to (otherwise /)
chdir=""
# The umask to adopt, if any
umask=""
# The syslog facility or filename for the client's stdout (otherwise discarded)
stdout="daemon.info"
# The syslog facility or filename for the client's stderr (otherwise discarded)
stderr="daemon.err"
case "$1" in
start)
# This if statement isn't strictly necessary but it's user friendly
if "$daemon" --running --name "$name" --pidfiles "$pidfiles"
then
echo "$name is already running."
else
echo -n "Starting $name..."
"$daemon" --respawn $daemon_start_args \
--name "$name" --pidfiles "$pidfiles" \
${user:+--user $user} ${chroot:+--chroot $chroot} \
${chdir:+--chdir $chdir} ${umask:+--umask $umask} \
${stdout:+--stdout $stdout} ${stderr:+--stderr $stderr} \
-- \
"$command" $command_args
echo done.
fi
;;
stop)
# This if statement isn't strictly necessary but it's user friendly
if "$daemon" --running --name "$name" --pidfiles "$pidfiles"
then
echo -n "Stopping $name..."
"$daemon" --stop --name "$name" --pidfiles "$pidfiles"
echo done.
else
echo "$name is not running."
fi
;;
restart|reload)
if "$daemon" --running --name "$name" --pidfiles "$pidfiles"
then
echo -n "Restarting $name..."
"$daemon" --restart --name "$name" --pidfiles "$pidfiles"
echo done.
else
echo "$name is not running."
exit 1
fi
;;
status)
"$daemon" --running --name "$name" --pidfiles "$pidfiles" --verbose
;;
*)
echo "usage: $0 <start|stop|restart|reload|status>" >&2
exit 1
esac
exit 0
# vi:set ts=4 sw=4:
|