]> git.stg.codes - stg.git/blob - stargazer/inst/linux/etc/init.d/stargazer.ubuntu.7.10
Port to CMake, get rid of os_int.h.
[stg.git] / stargazer / inst / linux / etc / init.d / stargazer.ubuntu.7.10
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          stargazer
4 # Required-Start:    $local_fs $remote_fs
5 # Required-Stop:     $local_fs $remote_fs
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      S 0 1 6
8 # Short-Description: Stargazer initscript
9 # Description:       This file should be used to start and stop stargazer daemon
10 ### END INIT INFO
11
12 # Author: Boris Mikhailenko <stg34@stg.dp.ua>
13
14 # Do NOT "set -e"
15
16 # PATH should only include /usr/* if it runs after the mountnfs.sh script
17 PATH=/usr/sbin:/usr/bin:/sbin:/bin
18 DESC="Billing system"
19 NAME=stargazer
20 DAEMON=/usr/sbin/$NAME
21 DAEMON_ARGS=""
22 PIDFILE=/var/run/$NAME.pid
23 SCRIPTNAME=/etc/init.d/$NAME
24
25 # Exit if the package is not installed
26 [ -x "$DAEMON" ] || exit 0
27
28 # Read configuration variable file if it is present
29 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
30
31 # Load the VERBOSE setting and other rcS variables
32 [ -f /etc/default/rcS ] && . /etc/default/rcS
33
34 # Define LSB log_* functions.
35 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
36 . /lib/lsb/init-functions
37
38 #
39 # Function that starts the daemon/service
40 #
41 do_start()
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 --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
48                 || return 1
49                 
50         # ps x | grep $DAEMON | grep -v grep | cut -f1 -d" " > $PIDFILE
51                 
52         start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
53                 $DAEMON_ARGS \
54                 || return 2
55         
56         # ps x | grep $DAEMON | grep -v grep | cut -f1 -d" " > $PIDFILE
57         # Add code here, if necessary, that waits for the process to be ready
58         # to handle requests from services started subsequently which depend
59         # on this one.  As a last resort, sleep for some time.
60 }
61
62 #
63 # Function that stops the daemon/service
64 #
65 do_stop()
66 {
67         # Return
68         #   0 if daemon has been stopped
69         #   1 if daemon was already stopped
70         #   2 if daemon could not be stopped
71         #   other if a failure occurred
72         start-stop-daemon --stop --quiet --retry=INT/60/KILL/5 --pidfile $PIDFILE --name $NAME
73         RETVAL="$?"
74         [ "$RETVAL" = 2 ] && return 2
75         # Wait for children to finish too if this is a daemon that forks
76         # and if the daemon is only ever run from this initscript.
77         # If the above conditions are not satisfied then add some other code
78         # that waits for the process to drop all resources that could be
79         # needed by services started subsequently.  A last resort is to
80         # sleep for some time.
81         start-stop-daemon --stop --quiet --oknodo --retry=0/60/KILL/5 --exec $DAEMON
82         [ "$?" = 2 ] && return 2
83         # Many daemons don't delete their pidfiles when they exit.
84         rm -f $PIDFILE
85         return "$RETVAL"
86 }
87
88 #
89 # Function that sends a SIGHUP to the daemon/service
90 #
91 do_reload() {
92         # If the daemon can reload its configuration without
93         # restarting (for example, when it is sent a SIGHUP),
94         # then implement that here.
95         start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
96         return 0
97 }
98
99 case "$1" in
100   start)
101         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
102         do_start
103         case "$?" in
104                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
105                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
106         esac
107         ;;
108   stop)
109         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
110         do_stop
111         case "$?" in
112                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
113                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
114         esac
115         ;;
116   reload)
117         # If do_reload() is not implemented then leave this commented out
118         # and leave 'force-reload' as an alias for 'restart'.
119         log_daemon_msg "Reloading $DESC" "$NAME"
120         do_reload
121         log_end_msg $?
122         ;;
123   restart)
124         #
125         # If the "reload" option is implemented then remove the
126         # 'force-reload' alias
127         #
128         log_daemon_msg "Restarting $DESC" "$NAME"
129         do_stop
130         case "$?" in
131           0|1)
132                 do_start
133                 case "$?" in
134                         0) log_end_msg 0 ;;
135                         1) log_end_msg 1 ;; # Old process is still running
136                         *) log_end_msg 1 ;; # Failed to start
137                 esac
138                 ;;
139           *)
140                 # Failed to stop
141                 log_end_msg 1
142                 ;;
143         esac
144         ;;
145   *)
146         #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
147         echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
148         exit 3
149         ;;
150 esac
151
152 :