Debian Codegraph @

calypso-init

raw symbols SCIP
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides: calypso
4 # Required-Start: $network $remote_fs
5 # Required-Stop: $remote_fs
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: CalDAV/CardDAV server
9 # Description: Calendar and Contact server over WebDAV
10 # using the CalDAV and CardDAV protocols
11 ### END INIT INFO
12
13 # Author: Keith Packard <[email protected]>
14 # Author: Joe Nahmias <[email protected]>
15 # Author: Petter Reinholdtsen <[email protected]>
16
17 # PATH should only include /usr/* if it runs after the mountnfs.sh script
18 PATH=/sbin:/usr/sbin:/bin:/usr/bin
19 DESC="Calypso CalDAV Server"
20 NAME=calypso
21 USER=calypso
22 GROUP=calypso
23 BINDIP=127.0.0.1
24 DAEMON=/usr/bin/$NAME
25 PIDFILE=/var/run/calypso/$NAME.pid
26 CALYPSO_OPTS="--daemon"
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 if [ "$BINDIP" ] ; then
35 CALYPSO_OPTS="${CALYPSO_OPTS:+$CALYPSO_OPTS }--host=$BINDIP"
36 fi
37
38 if [ "$PIDFILE" ] ; then
39 CALYPSO_OPTS="${CALYPSO_OPTS:+$CALYPSO_OPTS }--pid-file=$PIDFILE"
40 fi
41
42 # Load the VERBOSE setting and other rcS variables
43 . /lib/init/vars.sh
44
45 # Define LSB log_* functions.
46 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
47 # and status_of_proc is working.
48 . /lib/lsb/init-functions
49
50 #
51 # Check whether daemon starting is enabled
52 #
53 check_start_daemon()
54 {
55 if [ "$DISABLE_CALPYSO" = "yes" ]; then
56 [ "$VERBOSE" != no ] && \
57 log_warning_msg "Not starting $NAME, disabled via /etc/default/$NAME"
58 return 1
59 else
60 return 0
61 fi
62 }
63
64 #
65 # Function that starts the daemon/service
66 #
67 do_start()
68 {
69 # Return
70 # 0 if daemon has been started
71 # 1 if daemon was already running
72 # 2 if daemon could not be started
73 mkdir -p $(dirname $PIDFILE)
74 chown $USER:$GROUP $(dirname $PIDFILE)
75 start-stop-daemon \
76 --quiet \
77 --start \
78 --chuid $USER \
79 --pidfile $PIDFILE \
80 --exec $DAEMON \
81 -- $CALYPSO_OPTS \
82 || return 2
83 # Add code here, if necessary, that waits for the process to be ready
84 # to handle requests from services started subsequently which depend
85 # on this one. As a last resort, sleep for some time.
86 }
87
88 #
89 # Function that stops the daemon/service
90 #
91 do_stop()
92 {
93 # Return
94 # 0 if daemon has been stopped
95 # 1 if daemon was already stopped
96 # 2 if daemon could not be stopped
97 # other if a failure occurred
98 start-stop-daemon \
99 --stop \
100 --quiet \
101 --retry=TERM/30/KILL/5 \
102 --pidfile $PIDFILE \
103 --name $NAME
104 RETVAL="$?"
105 [ "$RETVAL" = 2 ] && return 2
106 # Wait for children to finish too if this is a daemon that forks
107 # and if the daemon is only ever run from this initscript.
108 # If the above conditions are not satisfied then add some other code
109 # that waits for the process to drop all resources that could be
110 # needed by services started subsequently. A last resort is to
111 # sleep for some time.
112 start-stop-daemon \
113 --stop \
114 --quiet \
115 --oknodo \
116 --retry=0/30/KILL/5 \
117 --exec $DAEMON
118 [ "$?" = 2 ] && return 2
119 # Many daemons don't delete their pidfiles when they exit.
120 rm -f $PIDFILE
121 return "$RETVAL"
122 }
123
124 case "$1" in
125 start)
126 check_start_daemon || exit 0
127 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
128 do_start
129 case "$?" in
130 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
131 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
132 esac
133 ;;
134 stop)
135 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
136 do_stop
137 case "$?" in
138 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
139 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
140 esac
141 ;;
142 status)
143 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
144 ;;
145 restart|force-reload)
146 #
147 # If the "reload" option is implemented then remove the
148 # 'force-reload' alias
149 #
150 log_daemon_msg "Restarting $DESC" "$NAME"
151 do_stop
152 case "$?" in
153 0|1)
154 do_start
155 case "$?" in
156 0) log_end_msg 0 ;;
157 1) log_end_msg 1 ;; # Old process is still running
158 *) log_end_msg 1 ;; # Failed to start
159 esac
160 ;;
161 *)
162 # Failed to stop
163 log_end_msg 1
164 ;;
165 esac
166 ;;
167 *)
168 echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2
169 exit 3
170 ;;
171 esac
172
173 :