Rev 17 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | magnus | 1 | #!/bin/sh |
| 2 | ### BEGIN INIT INFO |
||
| 9 | magnus | 3 | # Provides: pyscrabble-server |
| 2 | magnus | 4 | # Required-Start: $local_fs $remote_fs |
| 5 | # Required-Stop: $local_fs $remote_fs |
||
| 6 | # Default-Start: 2 3 4 5 |
||
| 9 | magnus | 7 | # Default-Stop: 0 1 6 |
| 2 | magnus | 8 | # Short-Description: PyScrabble server |
| 9 | # Description: Controls the PyScrabble server |
||
| 10 | ### END INIT INFO |
||
| 11 | |||
| 12 | set -e |
||
| 13 | |||
| 14 | PATH=/sbin:/bin:/usr/bin |
||
| 15 | DESC="PyScrabble server" |
||
| 16 | NAME=python |
||
| 17 | NAME2=pyscrabble-server |
||
| 18 | DAEMON=/usr/games/pyscrabble-server |
||
| 19 | PIDFILE=/var/run/$NAME2.pid |
||
| 20 | SCRIPTNAME=/etc/init.d/$NAME2 |
||
| 21 | |||
| 22 | # Gracefully exit if the package has been removed. |
||
| 23 | test -x $DAEMON || exit 0 |
||
| 24 | |||
| 3 | magnus | 25 | . /lib/lsb/init-functions |
| 26 | |||
| 2 | magnus | 27 | USER="pyscrabble" |
| 28 | |||
| 29 | # Read config file if it is present. |
||
| 3 | magnus | 30 | if [ -r /etc/default/$NAME2 ]; then |
| 2 | magnus | 31 | . /etc/default/$NAME2 |
| 32 | fi |
||
| 33 | |||
| 3 | magnus | 34 | d_running() { |
| 35 | start-stop-daemon --stop --quiet --pidfile $PIDFILE \ |
||
| 36 | --name $NAME --test > /dev/null |
||
| 37 | } |
||
| 38 | |||
| 2 | magnus | 39 | # |
| 40 | # Function that starts the daemon/service. |
||
| 41 | # |
||
| 42 | d_start() { |
||
| 3 | magnus | 43 | start-stop-daemon --start --oknodo --quiet --pidfile $PIDFILE --name $NAME \ |
| 44 | --background --make-pidfile --chuid "$USER" --startas $DAEMON |
||
| 2 | magnus | 45 | } |
| 46 | |||
| 47 | # |
||
| 48 | # Function that stops the daemon/service. |
||
| 49 | # |
||
| 50 | d_stop() { |
||
| 3 | magnus | 51 | start-stop-daemon --stop --oknodo --quiet --pidfile $PIDFILE --name $NAME |
| 2 | magnus | 52 | rm -f $PIDFILE |
| 53 | } |
||
| 54 | |||
| 55 | case "$1" in |
||
| 56 | start) |
||
| 3 | magnus | 57 | log_daemon_msg "Starting $DESC" "$NAME2" |
| 58 | if d_running; then |
||
| 59 | log_progress_msg "already running" |
||
| 60 | else |
||
| 61 | d_start; |
||
| 62 | fi |
||
| 63 | log_end_msg 0 |
||
| 2 | magnus | 64 | ;; |
| 65 | stop) |
||
| 3 | magnus | 66 | log_daemon_msg "Stopping $DESC" "$NAME2" |
| 67 | if ! d_running; then |
||
| 68 | log_progress_msg "not running" |
||
| 69 | else |
||
| 70 | d_stop |
||
| 71 | fi |
||
| 72 | log_end_msg 0 |
||
| 2 | magnus | 73 | ;; |
| 74 | #reload) |
||
| 75 | # |
||
| 76 | # If the daemon can reload its configuration without |
||
| 77 | # restarting (for example, when it is sent a SIGHUP), |
||
| 78 | # then implement that here. |
||
| 79 | # |
||
| 80 | # If the daemon responds to changes in its config file |
||
| 81 | # directly anyway, make this an "exit 0". |
||
| 82 | # |
||
| 83 | # echo -n "Reloading $DESC configuration..." |
||
| 84 | # d_reload |
||
| 85 | # echo "done." |
||
| 86 | #;; |
||
| 87 | restart|force-reload) |
||
| 88 | # |
||
| 89 | # If the "reload" option is implemented, move the "force-reload" |
||
| 90 | # option to the "reload" entry above. If not, "force-reload" is |
||
| 91 | # just the same as "restart". |
||
| 92 | # |
||
| 3 | magnus | 93 | log_daemon_msg "Restarting $DESC" "$NAME2" |
| 2 | magnus | 94 | d_stop |
| 95 | # One second might not be time enough for a daemon to stop, |
||
| 96 | # if this happens, d_start will fail (and dpkg will break if |
||
| 97 | # the package is being upgraded). Change the timeout if needed |
||
| 98 | # be, or change d_stop to have start-stop-daemon use --retry. |
||
| 99 | # Notice that using --retry slows down the shutdown process somewhat. |
||
| 100 | sleep 1 |
||
| 101 | d_start |
||
| 3 | magnus | 102 | log_end_msg 0 |
| 2 | magnus | 103 | ;; |
| 3 | magnus | 104 | status) |
| 105 | d_running || status="not " |
||
| 106 | log_action_msg "Status of $DESC:" "${status}running" |
||
| 107 | ;; |
||
| 2 | magnus | 108 | *) |
| 109 | # echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 |
||
| 110 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
||
| 111 | exit 1 |
||
| 112 | ;; |
||
| 113 | esac |
||
| 114 | |||
| 115 | exit 0 |