]> WPIA git - gigi.git/blob - debian/cacert-gigi-testing.cacert-gigi.init
UPD: Fix the debian package
[gigi.git] / debian / cacert-gigi-testing.cacert-gigi.init
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          cacert-gigi
4 # Required-Start:    $local_fs $network $remote_fs $syslog mysql
5 # Required-Stop:     $local_fs $network $remote_fs $syslog mysql
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: <Enter a short description of the software>
9 # Description:       <Enter a long description of the software>
10 #                    <...>
11 #                    <...>
12 ### END INIT INFO
13
14 # Author: unknown <software@cacert.org>
15
16 # Do NOT "set -e"
17
18 # PATH should only include /usr/* if it runs after the mountnfs.sh script
19 PATH=/sbin:/usr/sbin:/bin:/usr/bin
20 DESC="cacert-gigi"
21 NAME=cacert-gigi
22 DAEMON=`which java`
23 DAEMON_ARGS="-cp /usr/share/java/mysql-connector-java.jar:/usr/share/java/gigi.jar org.cacert.gigi.Launcher"
24 PIDFILE=/var/run/$NAME.pid
25 SCRIPTNAME=/etc/init.d/$NAME
26 DIR=/var/lib/cacert-gigi
27
28 # Exit if the package is not installed
29 [ -x "$DAEMON" ] || exit 0
30
31 # Read configuration variable file if it is present
32 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
33
34 # Load the VERBOSE setting and other rcS variables
35 . /lib/init/vars.sh
36
37 # Define LSB log_* functions.
38 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
39 # and status_of_proc is working.
40 . /lib/lsb/init-functions
41
42 #
43 # Function that starts the daemon/service
44 #
45 do_start()
46 {
47         if [ ! -f /etc/cacert-gigi/conf.tar ]; then
48                 echo Missing gigi-configfile
49                 exit 2
50         fi
51         # Return
52         #   0 if daemon has been started
53         #   1 if daemon was already running
54         #   2 if daemon could not be started
55         start-stop-daemon -b --start --quiet --pidfile $PIDFILE -d $DIR --exec $DAEMON --test > /dev/null \
56                 || return 1
57         start-stop-daemon -b --start --quiet --pidfile $PIDFILE -d $DIR --exec /usr/bin/gigi -- start-daemon \
58                 || return 2
59         # The above code will not work for interpreted scripts, use the next
60         # six lines below instead (Ref: #643337, start-stop-daemon(8) )
61         # start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \
62         #       --name $NAME --test > /dev/null \
63         #       || return 1
64         # start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \
65         #       --name $NAME -- $DAEMON_ARGS \
66         #       || return 2
67
68         # Add code here, if necessary, that waits for the process to be ready
69         # to handle requests from services started subsequently which depend
70         # on this one.  As a last resort, sleep for some time.
71 }
72
73 #
74 # Function that stops the daemon/service
75 #
76 do_stop()
77 {
78         # Return
79         #   0 if daemon has been stopped
80         #   1 if daemon was already stopped
81         #   2 if daemon could not be stopped
82         #   other if a failure occurred
83         start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
84         RETVAL="$?"
85         [ "$RETVAL" = 2 ] && return 2
86         # Wait for children to finish too if this is a daemon that forks
87         # and if the daemon is only ever run from this initscript.
88         # If the above conditions are not satisfied then add some other code
89         # that waits for the process to drop all resources that could be
90         # needed by services started subsequently.  A last resort is to
91         # sleep for some time.
92         start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --pidfile $PIDFILE
93         [ "$?" = 2 ] && return 2
94         # Many daemons don't delete their pidfiles when they exit.
95         rm -f $PIDFILE
96         return "$RETVAL"
97 }
98
99 #
100 # Function that sends a SIGHUP to the daemon/service
101 #
102 do_reload() {
103         #
104         # If the daemon can reload its configuration without
105         # restarting (for example, when it is sent a SIGHUP),
106         # then implement that here.
107         #
108         start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
109         return 0
110 }
111
112 case "$1" in
113   start)
114         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
115         do_start
116         case "$?" in
117                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
118                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
119         esac
120         ;;
121   stop)
122         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
123         do_stop
124         case "$?" in
125                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
126                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
127         esac
128         ;;
129   status)
130         status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
131         ;;
132   #reload|force-reload)
133         #
134         # If do_reload() is not implemented then leave this commented out
135         # and leave 'force-reload' as an alias for 'restart'.
136         #
137         #log_daemon_msg "Reloading $DESC" "$NAME"
138         #do_reload
139         #log_end_msg $?
140         #;;
141   restart|force-reload)
142         #
143         # If the "reload" option is implemented then remove the
144         # 'force-reload' alias
145         #
146         log_daemon_msg "Restarting $DESC" "$NAME"
147         do_stop
148         case "$?" in
149           0|1)
150                 do_start
151                 case "$?" in
152                         0) log_end_msg 0 ;;
153                         1) log_end_msg 1 ;; # Old process is still running
154                         *) log_end_msg 1 ;; # Failed to start
155                 esac
156                 ;;
157           *)
158                 # Failed to stop
159                 log_end_msg 1
160                 ;;
161         esac
162         ;;
163   *)
164         #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
165         echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
166         exit 3
167         ;;
168 esac
169
170 :