source: subversion/applications/utils/tirex/debian/tirex-syncd.init @ 29268

Last change on this file since 29268 was 21122, checked in by jochen, 9 years ago

great cleanup and reorganisation of debian packages

File size: 3.5 KB
Line 
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides:          tirex-syncd
4# Required-Start:   
5# Required-Stop:     
6# Default-Start:     2 3 4 5
7# Default-Stop:      0 1 6
8# Short-Description: Tirex sync server
9# Description:       Tirex sync server
10### END INIT INFO
11
12# Do NOT "set -e"
13
14# PATH should only include /usr/* if it runs after the mountnfs.sh script
15PATH=/sbin:/usr/sbin:/bin:/usr/bin
16DESC="Tirex sync server"
17NAME=tirex-syncd
18DAEMON=/usr/bin/$NAME
19DAEMON_ARGS=""
20PIDFILE=/var/run/tirex/$NAME.pid
21SCRIPTNAME=/etc/init.d/$NAME
22
23# Exit if the package is not installed
24[ -x "$DAEMON" ] || exit 0
25
26# Read configuration variable file if it is present
27[ -r /etc/default/$NAME ] && . /etc/default/$NAME
28
29# Load the VERBOSE setting and other rcS variables
30. /lib/init/vars.sh
31
32# Define LSB log_* functions.
33# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
34. /lib/lsb/init-functions
35
36#
37# Function that starts the daemon/service
38#
39do_start()
40{
41    [ -d `dirname $PIDFILE` ] || (mkdir -p `dirname $PIDFILE` ; chown tirex:tirex `dirname $PIDFILE`)
42
43        # Return
44        #   0 if daemon has been started
45        #   1 if daemon was already running
46        #   2 if daemon could not be started
47        start-stop-daemon --start --quiet --chuid tirex --exec $DAEMON --test > /dev/null \
48                || return 1
49        start-stop-daemon --start --quiet --chuid tirex --exec $DAEMON -- \
50                $DAEMON_ARGS \
51                || return 2
52        # Add code here, if necessary, that waits for the process to be ready
53        # to handle requests from services started subsequently which depend
54        # on this one.  As a last resort, sleep for some time.
55}
56
57#
58# Function that stops the daemon/service
59#
60do_stop()
61{
62        # Return
63        #   0 if daemon has been stopped
64        #   1 if daemon was already stopped
65        #   2 if daemon could not be stopped
66        #   other if a failure occurred
67        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
68        RETVAL="$?"
69        [ "$RETVAL" = 2 ] && return 2
70        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
71        [ "$?" = 2 ] && return 2
72        # Many daemons don't delete their pidfiles when they exit.
73        rm -f $PIDFILE
74        return "$RETVAL"
75}
76
77#
78# Function that sends a SIGHUP to the daemon/service
79#
80do_reload() {
81        #
82        # If the daemon can reload its configuration without
83        # restarting (for example, when it is sent a SIGHUP),
84        # then implement that here.
85        #
86        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
87        return 0
88}
89
90case "$1" in
91  start)
92        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
93        do_start
94        case "$?" in
95                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
96                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
97        esac
98        ;;
99  stop)
100        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
101        do_stop
102        case "$?" in
103                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
104                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
105        esac
106        ;;
107  #reload|force-reload)
108        #
109        # If do_reload() is not implemented then leave this commented out
110        # and leave 'force-reload' as an alias for 'restart'.
111        #
112        #log_daemon_msg "Reloading $DESC" "$NAME"
113        #do_reload
114        #log_end_msg $?
115        #;;
116  restart|force-reload)
117        #
118        # If the "reload" option is implemented then remove the
119        # 'force-reload' alias
120        #
121        log_daemon_msg "Restarting $DESC" "$NAME"
122        do_stop
123        case "$?" in
124          0|1)
125                do_start
126                case "$?" in
127                        0) log_end_msg 0 ;;
128                        1) log_end_msg 1 ;; # Old process is still running
129                        *) log_end_msg 1 ;; # Failed to start
130                esac
131                ;;
132          *)
133                # Failed to stop
134                log_end_msg 1
135                ;;
136        esac
137        ;;
138  *)
139        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
140        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
141        exit 3
142        ;;
143esac
144
145:
Note: See TracBrowser for help on using the repository browser.