Fix installation for silc-client and silc-toolkit packages
[silc.git] / debian-silc-server / init.d
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          silcd
4 # Required-Start:    $local_fs $remote_fs $network
5 # Required-Stop:     $local_fs $remote_fs $network
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: SILC server
9 # Description:       A server for the Secure Live Internet Conferencing (SILC)
10 #                    protocol.
11 ### END INIT INFO
12
13 # Author: Jérémy Bobbio <lunar@debian.org>
14
15 # PATH should only include /usr/* if it runs after the mountnfs.sh script
16 PATH=/sbin:/usr/sbin:/bin:/usr/bin
17 DESC="SILC server"
18 NAME=silcd
19 DAEMON=/usr/sbin/$NAME
20 PIDFILE=/var/run/$NAME.pid
21 SCRIPTNAME=/etc/init.d/$NAME
22 CONFIGFILE=/etc/$NAME/$NAME.conf
23
24 # Exit if the package is not installed
25 [ -x "$DAEMON" ] || exit 0
26
27 # Exit if configuration file is not readable
28 [ -r "$CONFIGFILE" ] || exit 0
29
30 read_config() {
31     PARAMETER="$1"
32     sed -n -e "s/^[^#]*$PARAMETER  *=  *\"\([^\"]*\)\".*$/\1/p" "$CONFIGFILE"
33 }
34
35 PRIVATE_KEY="$(read_config PrivateKey)"
36
37 # Exit if private key is not readable
38 [ -r "$PRIVATE_KEY" ] || exit 0
39
40 # Load the VERBOSE setting and other rcS variables
41 . /lib/init/vars.sh
42
43 # Define LSB log_* functions.
44 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
45 . /lib/lsb/init-functions
46
47 do_start()
48 {
49     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
50         --test > /dev/null || return 1
51     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
52         || return 2
53 }
54
55 do_stop()
56 {
57     start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
58         --pidfile $PIDFILE --name $NAME
59     RETVAL="$?"
60     [ "$RETVAL" = 2 ] && return 2
61     start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 \
62         --exec $DAEMON
63     [ "$?" = 2 ] && return 2
64     rm -f $PIDFILE
65     return "$RETVAL"
66 }
67
68 do_reload() {
69     start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE \
70         --name $NAME
71     return 0
72 }
73
74 case "$1" in
75     start)
76         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
77         do_start
78         case "$?" in
79             0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
80             2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
81         esac
82         ;;
83     stop)
84         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
85         do_stop
86         case "$?" in
87             0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
88             2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
89         esac
90         ;;
91     reload|force-reload)
92         log_daemon_msg "Reloading $DESC" "$NAME"
93         do_reload
94         log_end_msg $?
95         ;;
96     restart)
97         log_daemon_msg "Restarting $DESC" "$NAME"
98         do_stop
99         case "$?" in
100             0|1)
101                 do_start
102                 case "$?" in
103                     0) log_end_msg 0 ;;
104                     1) log_end_msg 1 ;; # Old process is still running
105                     *) log_end_msg 1 ;; # Failed to start
106                 esac
107                 ;;
108             *)
109                 # Failed to stop
110                 log_end_msg 1
111                 ;;
112         esac
113         ;;
114     *)
115         echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
116         exit 3
117         ;;
118 esac
119
120 :
121
122 #vim et sw=4