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