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