#!/bin/sh # # svnserve init script # Latest change: Mi Apr 11 18:09:23 CEST 2007 # ### BEGIN INIT INFO # Provides: svnserve # Required-Start: $network $local_fs $remote_fs $syslog # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: init-Script for system wide svnserve daemon ### END INIT INFO # # A svnserverc file containg hosts and passwords for all local users should be # placed in /etc/conf.d/svnserve. Remember to make the /etc/conf.d/svnserve mode 600 # to avoid disclosing the users' passwords. # # This script will NOT start or stop svnserve if the /etc/svnserverc file # does not exist or if START_DAEMON in /etc/default/svnserve is set to no. set -e # Defaults PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/bin/svnserve USER=svn OPTIONS="" CONFFILE="/etc/conf.d/svnserve" PIDFILE="/var/run/svnserve/svnserve.pid" UIDL="/var/lib/svnserve/.svnserve-UIDL-cache" START_DAEMON="no" . /lib/lsb/init-functions if [ -r /etc/default/svnserve ]; then . /etc/default/svnserve fi OPTIONS="$OPTIONS -d --pid-file $PIDFILE" if [ ! "x$START_DAEMON" = "xyes" -a ! "$1" = "stop" ]; then echo "Edit /etc/default/svnserve to start svnserve" exit 0 fi if [ ! -e $CONFFILE ]; then log_failure_msg "$CONFFILE not found." log_failure_msg "can not start svnserve daemon... consider disabling the script" exit 0 fi test -f $DAEMON || exit 0 if [ "$1" = "start" ]; then if [ ! -r $CONFFILE ] ; then log_failure_msg "$CONFFILE found but not readable." exit 0 fi fi # support for ephemeral /var/run if [ "${PIDFILE%/*}" = "/var/run/svnserve" ] && [ ! -d ${PIDFILE%/*} ]; then mkdir /var/run/svnserve chown -h $USER:nogroup /var/run/svnserve chmod 700 /var/run/svnserve fi # Makes sure certain files/directories have the proper owner if [ "`stat -c '%U %a' $CONFFILE 2>/dev/null`" != "$USER 600" ]; then chown -h $USER $CONFFILE chmod -f 0600 $CONFFILE fi case "$1" in start) if test -e $PIDFILE ; then pid=`cat $PIDFILE | sed -e 's/\s.*//'|head -n1` PIDDIR=/proc/$pid if [ -d ${PIDDIR} -a "$(readlink -f ${PIDDIR}/exe)" = "${DAEMON}" ]; then log_failure_msg "svnserve already started; not starting." exit 0 fi fi log_begin_msg "Starting svnserve" if start-stop-daemon -S -o -q -p $PIDFILE -x $DAEMON -u $USER -c $USER -- $OPTIONS; then logger -t "svn[`cat $PIDFILE`]" "Starting svnserve" log_end_msg 0 else log_end_msg 1 exit 1 fi ;; stop) if ! test -e $PIDFILE ; then log_failure_msg "Pidfile not found! Is svnserve running?" exit 0 fi log_begin_msg "Stopping svnserve" logger -t "svn[`cat $PIDFILE`]" "Stopping svnserve" if start-stop-daemon -K -o -q -p $PIDFILE -x $DAEMON -u $USER; then log_end_msg 0 rm -f $PIDFILE else log_end_msg 1 exit 1 fi ;; force-reload|restart) log_begin_msg "Restarting svnserve" if ! start-stop-daemon -K -o -q -p $PIDFILE -x $DAEMON -u $USER; then log_end_msg 1 exit 1 fi sleep 1 if start-stop-daemon -S -q -p $PIDFILE -x $DAEMON -u $USER -c $USER -- $OPTIONS; then logger -t "svn[`cat $PIDFILE`]" "Restarting svnserve" log_end_msg 0 else log_end_msg 1 exit 1 fi ;; try-restart) if test -e $PIDFILE ; then pid=`cat $PIDFILE | sed -e 's/\s.*//'|head -n1` PIDDIR=/proc/$pid if [ -d ${PIDDIR} -a "$(readlink -f ${PIDDIR}/exe)" = "${DAEMON}" ]; then $0 restart exit 0 fi fi test -f /etc/rc`/sbin/runlevel | cut -d' ' -f2`.d/S*svnserve* && $0 start ;; awaken) log_begin_msg "Awakening svnserve" if [ -s $PIDFILE ]; then start-stop-daemon -K -s 10 -q -p $PIDFILE -x $DAEMON log_end_msg 0 exit 0 else log_end_msg 1 exit 1 fi ;; debug-run) echo "$0: Initiating debug run of system-wide svnserve service..." 1>&2 echo "$0: script will be run in debug mode, all output to forced to" 1>&2 echo "$0: stdout. This is not enough to debug failures that only" 1>&2 echo "$0: happen in daemon mode." 1>&2 echo "$0: You might want to direct output to a file, and tail -f it." 1>&2 if [ "$2" = "strace" ]; then echo "$0: (running debug mode under strace. See strace(1) for options)" 1>&2 echo "$0: WARNING: strace output may contain security-sensitive info, such as" 1>&2 echo "$0: passwords; please clobber them before sending the strace file to a" 1>&2 echo "$0: public bug tracking system, such as Debian's." 1>&2 fi echo "$0: Stopping the service..." 1>&2 "$0" stop echo "$0: exit status of service stop was: $?" echo "$0: RUNUSER is $USER" echo "$0: OPTIONS would be $OPTIONS" echo "$0: Starting service in nodetach mode, hit ^C (SIGINT/intr) to finish run..." 1>&2 if [ "$2" = "strace" ] ; then shift shift [ $# -ne 0 ] && echo "$0: (strace options are: -tt $@)" 1>&2 su -s /bin/sh -c "/usr/bin/strace -tt $* $DAEMON $OPTIONS " $USER <&- 2>&1 else su -s /bin/sh -c "$DAEMON $OPTIONS " $USER <&- 2>&1 fi echo "$0: End of service run. Exit status was: $?" exit 0 ;; *) log_warning_msg "Usage: /etc/init.d/svnserve {start|stop|restart|force-reload|awaken|debug-run}" log_warning_msg " start - starts system-wide svnserve service" log_warning_msg " stop - stops system-wide svnserve service" log_warning_msg " restart, force-reload - starts a new system-wide svnserve service" log_warning_msg " awaken - tell system-wide svnserve to start a poll cycle immediately" log_warning_msg " debug-run [strace [strace options...]] - start a debug run of the" log_warning_msg " system-wide svnserve service, optionally running it under strace" exit 1 ;; esac exit 0