Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 2 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 3
Line 6... Line 6...
6
# Default-Start:     2 3 4 5
6
# Default-Start:     2 3 4 5
7
# Default-Stop:      S 0 1 6
7
# Default-Stop:      S 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
#
-
 
12
# Author:	Will Gray <graywh@gmail.com>
-
 
13
# Version:	1
-
 
14
#
-
 
15
11
16
set -e
12
set -e
17
13
18
PATH=/sbin:/bin:/usr/bin
14
PATH=/sbin:/bin:/usr/bin
19
DESC="PyScrabble server"
15
DESC="PyScrabble server"
Line 24... Line 20...
24
SCRIPTNAME=/etc/init.d/$NAME2
20
SCRIPTNAME=/etc/init.d/$NAME2
25
21
26
# Gracefully exit if the package has been removed.
22
# Gracefully exit if the package has been removed.
27
test -x $DAEMON || exit 0
23
test -x $DAEMON || exit 0
28
24
-
 
25
. /lib/lsb/init-functions
-
 
26
29
USER="pyscrabble"
27
USER="pyscrabble"
30
28
31
# Read config file if it is present.
29
# Read config file if it is present.
32
if [ -r /etc/default/$NAME2 ]
30
if [ -r /etc/default/$NAME2 ]; then
33
then
-
 
34
	. /etc/default/$NAME2
31
	. /etc/default/$NAME2
35
fi
32
fi
36
33
-
 
34
d_running() {
-
 
35
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \
-
 
36
		--name $NAME --test > /dev/null
-
 
37
}
-
 
38
37
#
39
#
38
#	Function that starts the daemon/service.
40
#	Function that starts the daemon/service.
39
#
41
#
40
d_start() {
42
d_start() {
41
	start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE \
43
	start-stop-daemon --start --oknodo --quiet --pidfile $PIDFILE --name $NAME \
42
		--chuid "$USER" --exec $DAEMON \
44
	    --background --make-pidfile --chuid "$USER" --startas $DAEMON
43
		|| echo -n " already running"
-
 
44
}
45
}
45
46
46
#
47
#
47
#	Function that stops the daemon/service.
48
#	Function that stops the daemon/service.
48
#
49
#
49
d_stop() {
50
d_stop() {
50
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \
51
	start-stop-daemon --stop --oknodo --quiet --pidfile $PIDFILE --name $NAME
51
		--name $NAME \
-
 
52
		|| echo -n " not running"
-
 
53
        rm -f $PIDFILE
52
        rm -f $PIDFILE
54
}
53
}
55
54
56
case "$1" in
55
case "$1" in
57
  start)
56
  start)
58
	echo -n "Starting $DESC: $NAME2"
57
        log_daemon_msg "Starting $DESC" "$NAME2"
-
 
58
        if d_running; then 
-
 
59
            log_progress_msg "already running"
-
 
60
        else 
59
	d_start
61
            d_start;
60
	echo "."
62
        fi
-
 
63
	log_end_msg 0
61
	;;
64
	;;
62
  stop)
65
  stop)
63
	echo -n "Stopping $DESC: $NAME2"
66
	log_daemon_msg "Stopping $DESC" "$NAME2"
-
 
67
        if ! d_running; then
-
 
68
	    log_progress_msg "not running"
-
 
69
        else
64
	d_stop
70
	    d_stop
65
	echo "."
71
        fi
-
 
72
	log_end_msg 0
66
	;;
73
	;;
67
  #reload)
74
  #reload)
68
	#
75
	#
69
	#	If the daemon can reload its configuration without
76
	#	If the daemon can reload its configuration without
70
	#	restarting (for example, when it is sent a SIGHUP),
77
	#	restarting (for example, when it is sent a SIGHUP),
Line 81... Line 88...
81
	#
88
	#
82
	#	If the "reload" option is implemented, move the "force-reload"
89
	#	If the "reload" option is implemented, move the "force-reload"
83
	#	option to the "reload" entry above. If not, "force-reload" is
90
	#	option to the "reload" entry above. If not, "force-reload" is
84
	#	just the same as "restart".
91
	#	just the same as "restart".
85
	#
92
	#
86
	echo -n "Restarting $DESC: $NAME2"
93
	log_daemon_msg "Restarting $DESC" "$NAME2"
87
	d_stop
94
	d_stop
88
	# 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, 
89
	# 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 
90
	# the package is being upgraded). Change the timeout if needed
97
	# the package is being upgraded). Change the timeout if needed
91
	# 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. 
92
	# Notice that using --retry slows down the shutdown process somewhat.
99
	# Notice that using --retry slows down the shutdown process somewhat.
93
	sleep 1
100
	sleep 1
94
	d_start
101
	d_start
95
	echo "."
102
	log_end_msg 0
96
	;;
103
	;;
-
 
104
  status)
-
 
105
        d_running || status="not "
-
 
106
        log_action_msg "Status of $DESC:" "${status}running"
-
 
107
        ;;
97
  *)
108
  *)
98
	# echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
109
	# echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
99
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
110
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
100
	exit 1
111
	exit 1
101
	;;
112
	;;