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