1#! /bin/sh
2
3# /etc/init.d/cvsd script for starting and stopping cvsd
4# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010 Arthur de Jong
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20### BEGIN INIT INFO
21# Provides:          cvsd
22# Required-Start:    $local_fs $remote_fs $syslog
23# Required-Stop:     $local_fs $remote_fs $syslog
24# Should-Start:      $network
25# Default-Start:     2 3 4 5
26# Default-Stop:      0 1 6
27# Short-Description: cvs pserver chroot wrapper
28# Description:       cvsd is a wrapper program for cvs in pserver mode.
29#                    It will run 'cvs pserver' under a special uid/gid in
30#                    a chroot jail.
31### END INIT INFO
32
33PATH=/bin:/usr/bin:/sbin:/usr/sbin
34CVSD_BIN=/usr/sbin/cvsd
35DESC="cvs pserver chroot wrapper"
36CVSD_CFG=/etc/cvsd/cvsd.conf
37
38[ -x "$CVSD_BIN" ] || exit 0
39[ -f "$CVSD_CFG" ] || exit 0
40
41. /lib/lsb/init-functions
42
43PIDFILE=`sed -n 's/^ *PidFile *\([^ ]*\) *$/\1/p' < $CVSD_CFG`
44[ -n "$PIDFILE" ] && PFO="--pidfile $PIDFILE"
45
46case "$1" in
47start)
48  log_daemon_msg "Starting $DESC" "cvsd"
49  start-stop-daemon --start --oknodo \
50                    $PFO \
51                    --startas $CVSD_BIN \
52                    -- -f $CVSD_CFG
53  log_end_msg $?
54  ;;
55stop)
56  log_daemon_msg "Stopping $DESC" "cvsd"
57  start-stop-daemon --stop --oknodo \
58                    $PFO \
59                    --name cvsd
60  log_end_msg $?
61  [ -n "$PIDFILE" ] && rm -f $PIDFILE
62  ;;
63restart|force-reload)
64  log_daemon_msg "Restarting $DESC" "cvsd"
65  start-stop-daemon --stop --quiet --retry 10 \
66                    $PFO \
67                    --name cvsd
68  [ -n "$PIDFILE" ] && rm -f $PIDFILE
69  start-stop-daemon --start \
70                    $PFO \
71                    --startas $CVSD_BIN \
72                    -- -f $CVSD_CFG
73  log_end_msg $?
74  ;;
75status)
76  if [ -n "$PIDFILE" ]
77  then
78    if [ -f "$PIDFILE" ]
79    then
80      if kill -s 0 `cat $PIDFILE` > /dev/null 2>&1
81      then
82        log_success_msg "cvsd running"
83        exit 0
84      else
85        log_success_msg "cvsd stopped"
86        exit 1
87      fi
88    else
89      log_success_msg "cvsd stopped"
90      exit 3
91    fi
92  else
93    if ps -ef | grep cvsd | grep -v grep > /dev/null 2>&1
94    then
95      log_warning_msg "cvsd probably running (no PidFile in cvsd.conf)"
96    else
97      log_warning_msg "cvsd probably not running (no PidFile in cvsd.conf)"
98      exit 3
99    fi
100  fi
101  ;;
102*)
103  log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}"
104  exit 1
105  ;;
106esac
107
108exit 0
109