| 1 |
#! /bin/sh |
| 2 |
# |
| 3 |
### BEGIN INIT INFO |
| 4 |
# Provides: crossfire.real-time.com |
| 5 |
# Required-Start: $local_fs $network $remote_fs |
| 6 |
# Required-Stop: $local_fs $network $remote_fs |
| 7 |
# Default-Start: 2 3 4 5 |
| 8 |
# Default-Stop: 0 1 6 |
| 9 |
# Short-Description: multiplayer RPG |
| 10 |
# Description: Networked graphical RPG/adventure game |
| 11 |
### END INIT INFO |
| 12 |
|
| 13 |
PATH=/bin:/usr/bin:/sbin:/usr/sbin |
| 14 |
DESC="Crossfire" |
| 15 |
NAME=crossfire-server |
| 16 |
DAEMON=/usr/sbin/crossfire-server |
| 17 |
DAEMON_OPTS="-detach -log /var/log/crossfire/logfile" |
| 18 |
|
| 19 |
test -f $DAEMON || exit 0 |
| 20 |
|
| 21 |
# Include crossfire defaults if available |
| 22 |
if [ -f /etc/default/crossfire ] ; then |
| 23 |
. /etc/default/crossfire |
| 24 |
fi |
| 25 |
|
| 26 |
# Load the VERBOSE setting and other rcS variables |
| 27 |
. /lib/init/vars.sh |
| 28 |
|
| 29 |
# Define LSB log_* functions. |
| 30 |
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present |
| 31 |
# and status_of_proc is working. |
| 32 |
. /lib/lsb/init-functions |
| 33 |
|
| 34 |
umask 002 |
| 35 |
|
| 36 |
do_start() |
| 37 |
{ |
| 38 |
# Return |
| 39 |
# 0 if daemon has been started |
| 40 |
# 1 if daemon was already running |
| 41 |
# 2 if daemon could not be started |
| 42 |
start-stop-daemon --start --quiet --user games --exec $DAEMON --test > /dev/null \ |
| 43 |
|| return 1 |
| 44 |
start-stop-daemon --start --quiet --chuid games: --pidfile $PIDFILE --exec $DAEMON -- \ |
| 45 |
$DAEMON_ARGS \ |
| 46 |
|| return 2 |
| 47 |
} |
| 48 |
|
| 49 |
do_stop() |
| 50 |
{ |
| 51 |
# Return |
| 52 |
# 0 if daemon has been stopped |
| 53 |
# 1 if daemon was already stopped |
| 54 |
# 2 if daemon could not be stopped |
| 55 |
# other if a failure occurred |
| 56 |
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user games --name $NAME |
| 57 |
RETVAL="$?" |
| 58 |
[ "$RETVAL" = 2 ] && return 2 |
| 59 |
# Wait for children to finish too if this is a daemon that forks |
| 60 |
# and if the daemon is only ever run from this initscript. |
| 61 |
# If the above conditions are not satisfied then add some other code |
| 62 |
# that waits for the process to drop all resources that could be |
| 63 |
# needed by services started subsequently. A last resort is to |
| 64 |
# sleep for some time. |
| 65 |
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --user games --exec $DAEMON |
| 66 |
[ "$?" = 2 ] && return 2 |
| 67 |
return "$RETVAL" |
| 68 |
} |
| 69 |
|
| 70 |
case "$1" in |
| 71 |
start) |
| 72 |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
| 73 |
do_start |
| 74 |
case "$?" in |
| 75 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 76 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 77 |
esac |
| 78 |
;; |
| 79 |
stop) |
| 80 |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
| 81 |
do_stop |
| 82 |
case "$?" in |
| 83 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 84 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 85 |
esac |
| 86 |
;; |
| 87 |
status) |
| 88 |
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? |
| 89 |
;; |
| 90 |
restart|force-reload) |
| 91 |
log_daemon_msg "Restarting $DESC" "$NAME" |
| 92 |
do_stop |
| 93 |
case "$?" in |
| 94 |
0|1) |
| 95 |
do_start |
| 96 |
case "$?" in |
| 97 |
0) log_end_msg 0 ;; |
| 98 |
1) log_end_msg 1 ;; # Old process is still running |
| 99 |
*) log_end_msg 1 ;; # Failed to start |
| 100 |
esac |
| 101 |
;; |
| 102 |
*) |
| 103 |
# Failed to stop |
| 104 |
log_end_msg 1 |
| 105 |
;; |
| 106 |
esac |
| 107 |
;; |
| 108 |
*) |
| 109 |
echo "Usage: /etc/init.d/crossfire-server {start|stop|restart|force-reload}" |
| 110 |
exit 3 |
| 111 |
;; |
| 112 |
esac |
| 113 |
|
| 114 |
: |