commit cb19f6a87f1b238703fafcf2397d59edf504ebb5 Author: Andrew Lewman andrew@torproject.org Date: Wed Jun 22 21:28:34 2011 -0400
add tordnsel init script. --- config/tordnsel-init.d-script.sample | 169 ++++++++++++++++++++++++++++++++++ 1 files changed, 169 insertions(+), 0 deletions(-)
diff --git a/config/tordnsel-init.d-script.sample b/config/tordnsel-init.d-script.sample new file mode 100755 index 0000000..f7a7fd2 --- /dev/null +++ b/config/tordnsel-init.d-script.sample @@ -0,0 +1,169 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: TorDNSEL +# Required-Start: $local_fs $remote_fs $syslog $network $time +# Required-Stop: $local_fs $remote_fs $syslog $network $time +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts the TorDNSEL daemon process +# Description: Starts TorDNSEL, a name server that provides a +# DNSBL-style interface for detecting connections +# exiting the Tor network. +# +### END INIT INFO + +# Author: Jacob Appelbaum jacob@appelbaum.net +# Author: tup tup.tuple@googlemail.com +# +# 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="TorDNSEL daemon" +NAME=tordnsel +DAEMON=/usr/local/bin/$NAME +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME +CONFIGFILE="/etc/tordnsel.conf" +RUNTIMEDIR="/var/run/tordnsel" +USER=tordnsel +ARGS="-f $CONFIGFILE " + +# 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 + +# +# 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 -- $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" +} + +case "$1" in + start) + echo "Starting $DESC: $NAME..." + + if ! su -s /bin/sh -c "$DAEMON --verify-config $ARGS" $USER 2> /dev/null; then + echo "ABORTED: TorDNSEL configuration invalid:" >&2 + su -s /bin/sh -c "$DAEMON --verify-config $ARGS" $USER + exit 1 + fi + + do_start + case "$?" in + 0|1) echo "done." ;; + 2) + echo "FAILED." + exit 1 + ;; + esac + ;; + stop) + echo -n "Stopping $DESC: " + do_stop + case "$?" in + 0|1) echo "$NAME." ;; + 2) + echo "FAILED." + exit 1 + ;; + esac + ;; + reload|force-reload) + echo -n "Reloading $DESC configuration: " + + if ! su -s /bin/sh -c "$DAEMON --verify-config $ARGS" $USER 2> /dev/null; then + echo "ABORTED: TorDNSEL configuration invalid:" >&2 + su -s /bin/sh -c "$DAEMON --verify-config $ARGS" $USER + exit 1 + fi + + # Don't send the process a SIGHUP because it won't be able to read its own + # config file when it's chrooted. Instead, use the --reconfigure option to + # dump the contents of the config file to a Unix domain socket on which it's + # listening for this purpose. + ERRMSG=`su -s /bin/sh -c "$DAEMON --reconfigure $RUNTIMEDIR < $CONFIGFILE" $USER 2>&1` + case "$?" in + 0) echo "$NAME." ;; + *) + echo "FAILED." + echo "$ERRMSG" >&2 + exit 1 + ;; + esac + ;; + restart) + if ! su -s /bin/sh -c "$DAEMON --verify-config $ARGS" $USER 2> /dev/null; then + echo "Restarting TorDNSEL ABORTED: TorDNSEL configuration invalid:" >&2 + su -s /bin/sh -c "$DAEMON --verify-config $ARGS" $USER + exit 1 + fi + + echo "Restarting $DESC: $NAME..." + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) echo "done." ;; + 1) echo "FAILED ($DAEMON is still running)." ;; + *) echo "FAILED." ;; # Failed to start + esac + ;; + *) + # Failed to stop + echo "FAILED ($DAEMON won't die)." + exit 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 + exit 3 + ;; +esac + +: