[iortcw] 05/08: Redo init script and systemd services, based on quake/12

Simon McVittie smcv at debian.org
Fri Feb 6 11:13:33 UTC 2015


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch master
in repository iortcw.

commit 8b9d278accf012e6fd590689d73948f819161d3f
Author: Simon McVittie <smcv at debian.org>
Date:   Thu Feb 5 23:36:54 2015 +0000

    Redo init script and systemd services, based on quake/12
    
    Unfortunately, it turns out we do need DAEMON_OPTS for Q3-based games,
    since an exec'd config file is too late to set the net_port.
    
    Also rename the unit back to rtcw-server, I've changed my mind about the
    relative priorities of consistency with other games and consistency
    with how upstream name their executable.
---
 debian/rtcw-server.README.Debian   | 57 +++++++++++++----------------
 debian/rtcw-server.init            | 75 ++++++++++++++++++++++++++++++++++++++
 debian/rtcw-server.install         |  4 +-
 debian/rtcw-server.links           |  2 +-
 debian/rtcw-server.service         | 25 +++++++++++++
 debian/rtcw-server.wolfded.init    | 64 --------------------------------
 debian/rtcw-server.wolfded.service | 15 --------
 debian/rtcw-server at .service        | 22 +++++++++++
 debian/rules                       |  6 ---
 debian/{default.cfg => server.cfg} |  0
 debian/wolfded at .service            | 23 ------------
 11 files changed, 151 insertions(+), 142 deletions(-)

diff --git a/debian/rtcw-server.README.Debian b/debian/rtcw-server.README.Debian
index 94ca15c..d013ebe 100644
--- a/debian/rtcw-server.README.Debian
+++ b/debian/rtcw-server.README.Debian
@@ -5,18 +5,23 @@ Running the server
 ------------------
 
 Installing the rtcw-server package provides a dedicated server
-running as the user "rtcw-server", from an init script named wolfded.
+running as the user "rtcw-server", from an init script named rtcw-server.
 This is a simple setup suitable for running one server on a machine.
 
-By default, the server will use etc/rtcw-server/default.cfg,
-which is a symlink to /etc/rtcw-server/default.cfg. You can edit
+By default, the server will use etc/rtcw-server/server.cfg,
+which is a symlink to /etc/rtcw-server/server.cfg. You can edit
 this file to reconfigure the default instance.
 
+The equivalent of ~/.iortcw for the server is
+/var/games/rtcw-server/server.iortcw.
+
 The server can be managed in the usual way, e.g. via service(8) commands
 like
 
-    service wolfded stop
-    service wolfded start
+    service rtcw-server stop
+    service rtcw-server start
+    update-rc.d rtcw-server disable
+    update-rc.d rtcw-server enable
 
 which should work for all of systemd, sysvinit and upstart.
 
@@ -24,33 +29,23 @@ The whole /etc/rtcw-server directory is symlinked into the engine's
 search path as etc/rtcw-server, so you can place files there and
 execute them with commands like "exec etc/rtcw-server/checkpoint.cfg".
 
-Disabling the server
---------------------
-
-To disable the default instance, use the facilities provided by your
-init system. The recommended command is
-
-    update-rc.d wolfded disable
-
-which should work for all of systemd, sysvinit and upstart.
-
-Multiple instances under systemd
---------------------------------
+Running multiple server instances with systemd
+----------------------------------------------
 
-Under systemd, wolfded.service just depends on wolfded at default.service,
-which runs the actual server. You can create an additional instance
-"foo" like this:
+Under systemd, rtcw-server supports additional instances of the server,
+for instance for different game modes.
 
-- create /etc/rtcw-server/foo.cfg based on /etc/rtcw-server/default.cfg
-  (remember to change the net_port)
-- run "systemctl enable wolfded at foo.service"
+Each instance rtcw-server at INSTANCE.service has configuration and state in
+/var/games/rtcw-server/INSTANCE.iortcw, and will execute
+/etc/rtcw-server/INSTANCE.cfg on startup.
 
-You can control individual instances with commands like
-"systemctl start wolfded at foo.service".
-You can also use commands like "systemctl start wolfded.service"
-to start the default instance and all enabled instances.
+To set a parameter that can only be given on the command line, such as
+fs_game or net_port, you can create /etc/default/rtcw-server at INSTANCE
+or a systemd "drop-in" file, and set DAEMON_OPTS there. Setting a
+unique net_port for each server is recommended: if you do not, each
+server will try ports above its configured net_port until it finds one
+that is not in use, so the mapping between servers and ports will be arbitrary.
 
-Non-default instances can be enabled and disabled with systemctl, but
-to disable the default instance, you must either mask the
-default instance ("systemctl mask wolfded at default.service")
-or disable wolfded.service ("systemctl disable wolfded.service").
+The instance name "server" cannot be used without disabling and stopping
+rtcw-server.service, since it shares its configuration with that
+service.
diff --git a/debian/rtcw-server.init b/debian/rtcw-server.init
new file mode 100755
index 0000000..dd3eef8
--- /dev/null
+++ b/debian/rtcw-server.init
@@ -0,0 +1,75 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          rtcw-server
+# Required-Start:    $remote_fs $network
+# Required-Stop:     $remote_fs $network
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Return to Castle Wolfenstein game server
+# Description:       Dedicated server for Return to Castle Wolfenstein,
+#                    a 3D first-person shooter game
+### END INIT INFO
+
+PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
+NAME="rtcw-server"
+DAEMON="/usr/games/wolfded"
+DESC="Return to Castle Wolfenstein dedicated server"
+PIDFILE="/var/run/$NAME.pid"
+BINARY="/usr/lib/rtcw/iowolfded"
+USER="$NAME"
+DAEMON_OPTS=""
+
+test -x $DAEMON || exit 0
+
+. /lib/lsb/init-functions
+
+# Include defaults if available
+if [ -f /etc/default/$NAME ] ; then
+    . /etc/default/$NAME
+fi
+
+q3_start() {
+    start-stop-daemon --start --quiet --pidfile $PIDFILE --oknodo \
+        --background --exec $BINARY --startas $DAEMON \
+        --make-pidfile --chuid $USER \
+        -- \
+        +set com_homepath server.iortcw \
+        $DAEMON_OPTS \
+        +exec etc/rtcw-server/server.cfg \
+        > /dev/null 2>&1 || return 1
+    return 0
+}
+
+q3_stop() {
+    start-stop-daemon --stop --quiet --pidfile $PIDFILE \
+        --oknodo --exec $BINARY || return 1
+    rm -f $PIDFILE
+    return 0
+}
+
+case "$1" in
+    start)
+        log_begin_msg "Starting $DESC: $NAME"
+        q3_start
+        log_end_msg $?
+        ;;
+    stop)
+        log_begin_msg "Stopping $DESC: $NAME"
+        q3_stop
+        log_end_msg $?
+        ;;
+    restart|force-reload)
+        log_begin_msg "Restarting $DESC: $NAME"
+        q3_stop && sleep 1 && q3_start
+        log_end_msg $?
+        ;;
+    status)
+        status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
+        exit 1
+        ;;
+esac
+
+exit 0
diff --git a/debian/rtcw-server.install b/debian/rtcw-server.install
index 38ca730..42c5062 100644
--- a/debian/rtcw-server.install
+++ b/debian/rtcw-server.install
@@ -1,5 +1,5 @@
 debian/build/mp/iowolfded              usr/lib/rtcw
 debian/build/mp/iowolfded.*            usr/lib/rtcw
 debian/scripts/wolfded                 usr/games
-debian/wolfded at .service                lib/systemd/system
-debian/default.cfg                     etc/rtcw-server
+debian/rtcw-server at .service            lib/systemd/system
+debian/server.cfg                      etc/rtcw-server
diff --git a/debian/rtcw-server.links b/debian/rtcw-server.links
index b2d5078..1f82d91 100644
--- a/debian/rtcw-server.links
+++ b/debian/rtcw-server.links
@@ -1,2 +1,2 @@
-# so you can do "exec etc/rtcw-server/default.cfg"
+# so you can do "exec etc/rtcw-server/server.cfg"
 etc/rtcw-server                        usr/lib/rtcw/main/etc/rtcw-server
diff --git a/debian/rtcw-server.service b/debian/rtcw-server.service
new file mode 100644
index 0000000..683077e
--- /dev/null
+++ b/debian/rtcw-server.service
@@ -0,0 +1,25 @@
+[Unit]
+Description=Return to Castle Wolfenstein game server
+After=network.target
+# This server and the @server instance would try to use the same
+# configuration, and fight over their home directory
+Conflicts=rtcw-server at server.service
+
+[Service]
+Type=simple
+User=rtcw-server
+Environment=DAEMON_OPTS=
+EnvironmentFile=-/etc/default/rtcw-server
+ExecStart=/usr/games/wolfded +set com_homepath server.iortcw $DAEMON_OPTS +exec etc/rtcw-server/server.cfg
+Restart=on-failure
+RestartPreventExitStatus=72
+# hardening
+CapabilityBoundingSet=
+NoNewPrivileges=true
+PrivateDevices=true
+PrivateTmp=true
+ProtectHome=true
+ProtectSystem=full
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/rtcw-server.wolfded.init b/debian/rtcw-server.wolfded.init
deleted file mode 100755
index bf120b2..0000000
--- a/debian/rtcw-server.wolfded.init
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/bin/sh
-# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
-if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
-    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
-fi
-### BEGIN INIT INFO
-# Provides:          wolfded rtcw-server
-# Required-Start:    $remote_fs $syslog
-# Required-Stop:     $remote_fs $syslog
-# Default-Start:     2 3 4 5
-# Default-Stop:
-# Short-Description: Return to Castle Wolfenstein game server
-# Description:       Return to Castle Wolfenstein multiplayer dedicated
-#                    server using the iortcw engine.
-### END INIT INFO
-
-PACKAGE="rtcw-server"
-NAME="wolfded"
-DESC="Return to Castle Wolfenstein game server"
-DAEMON="/usr/games/$NAME"
-BINARY="/usr/lib/rtcw/io$NAME"
-START_ARGS="--background --make-pidfile --chuid ${PACKAGE}"
-DAEMON_ARGS="+exec etc/${PACKAGE}/default.cfg"
-
-# The init script corresponds to the "default" systemd instance
-HOME="/var/games/$PACKAGE/default.home"
-XDG_DATA_HOME="$HOME"
-XDG_CACHE_HOME="$HOME/cache"
-XDG_CONFIG_HOME="$HOME/config"
-export HOME XDG_DATA_HOME XDG_CACHE_HOME XDG_CONFIG_HOME
-
-# Return
-#   0 if daemon has been started
-#   1 if daemon was already running
-#   2 if daemon could not be started
-do_start_cmd() {
-    start-stop-daemon --start --quiet ${PIDFILE:+--pidfile ${PIDFILE}} \
-        $START_ARGS \
-        --startas $DAEMON --name $NAME --exec $BINARY --test > /dev/null \
-        || return 1
-    start-stop-daemon --start --quiet ${PIDFILE:+--pidfile ${PIDFILE}} \
-        $START_ARGS \
-        --startas $DAEMON --name $NAME --exec $BINARY -- $DAEMON_ARGS \
-        || return 2
-}
-
-# Return
-#   0 if daemon has been stopped
-#   1 if daemon was already stopped
-#   2 if daemon could not be stopped
-#   other if a failure occurred
-do_stop_cmd() {
-    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
-        $STOP_ARGS \
-        ${PIDFILE:+--pidfile ${PIDFILE}} --name $NAME --exec $BINARY
-    RETVAL="$?"
-    [ "$RETVAL" = 2 ] && return 2
-    rm -f $PIDFILE
-    return $RETVAL
-}
-
-do_status() {
-    status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && return 0 || return $?
-}
diff --git a/debian/rtcw-server.wolfded.service b/debian/rtcw-server.wolfded.service
deleted file mode 100644
index 9c4af56..0000000
--- a/debian/rtcw-server.wolfded.service
+++ /dev/null
@@ -1,15 +0,0 @@
-# This service is actually more like a systemd target,
-# but we are using a service so it will mask the init script.
-[Unit]
-Description=Return to Castle Wolfenstein game server(s)
-After=network.target
-Wants=wolfded at default.service
-
-[Service]
-Type=oneshot
-RemainAfterExit=yes
-ExecStart=/bin/true
-
-[Install]
-WantedBy=multi-user.target
-Alias=rtcw-server.service
diff --git a/debian/rtcw-server at .service b/debian/rtcw-server at .service
new file mode 100644
index 0000000..37c8ac0
--- /dev/null
+++ b/debian/rtcw-server at .service
@@ -0,0 +1,22 @@
+[Unit]
+Description=Return to Castle Wolfenstein game server (instance: "%i")
+After=network.target
+
+[Service]
+Type=simple
+User=rtcw-server
+Environment=DAEMON_OPTS=
+EnvironmentFile=-/etc/default/rtcw-server@%i
+ExecStart=/usr/games/rtcw-server +set com_homepath %i.iortcw $DAEMON_OPTS +exec etc/rtcw-server/%i.cfg
+Restart=on-failure
+RestartPreventExitStatus=72
+# hardening
+CapabilityBoundingSet=
+NoNewPrivileges=true
+PrivateDevices=true
+PrivateTmp=true
+ProtectHome=true
+ProtectSystem=full
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/rules b/debian/rules
index fdaa3ad..452b86b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -79,12 +79,6 @@ override_dh_auto_build:
 	convert debian/32/wolfsp.png debian/wolfsp.xpm
 	convert debian/32/wolfmp.png debian/wolfmp.xpm
 
-override_dh_systemd_enable:
-	dh_systemd_enable -prtcw-server --name=wolfded
-
-override_dh_installinit:
-	dh_installinit -prtcw-server --name=wolfded
-
 override_dh_strip:
 	dh_strip --dbg-package=rtcw-dbg
 
diff --git a/debian/default.cfg b/debian/server.cfg
similarity index 100%
rename from debian/default.cfg
rename to debian/server.cfg
diff --git a/debian/wolfded at .service b/debian/wolfded at .service
deleted file mode 100644
index 5370187..0000000
--- a/debian/wolfded at .service
+++ /dev/null
@@ -1,23 +0,0 @@
-[Unit]
-Description=Return to Castle Wolfenstein game server - %i configuration
-PartOf=wolfded.service
-Before=wolfded.service
-After=network.target
-ConditionPathExists=/etc/rtcw-server/%i.cfg
-
-[Service]
-User=rtcw-server
-Environment=HOME=/var/games/rtcw-server/%i.home
-Environment=XDG_DATA_HOME=/var/games/rtcw-server/%i.home
-Environment=XDG_CACHE_HOME=/var/games/rtcw-server/%i.home/cache
-Environment=XDG_CONFIG_HOME=/var/games/rtcw-server/%i.home/config
-ExecStart=/usr/games/wolfded +exec etc/rtcw-server/%i.cfg
-Restart=on-failure
-RestartPreventExitStatus=72
-
-[Install]
-WantedBy=multi-user.target
-# We deliberately do not set DefaultInstance so that
-# "update-rc.d wolfded disable" -> "systemctl disable wolfded.service"
-# results in wolfded at default.service not being started unless explicitly
-# requested.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/iortcw.git



More information about the Pkg-games-commits mailing list