[openarena] 11/15: Sync server support with quake/12

Simon McVittie smcv at debian.org
Sun Feb 8 23:40:17 UTC 2015


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

smcv pushed a commit to branch master
in repository openarena.

commit b3920531ee4fb43a3c0ba6205549c8381ff82081
Author: Simon McVittie <smcv at debian.org>
Date:   Wed Feb 4 23:07:02 2015 +0000

    Sync server support with quake/12
    
      - remove support for START_DAEMON
      - if the server was previously disabled via START_DAEMON,
        do a one-time migration to "update-rc.d $SERVICE disable"
      - put default for DAEMON_OPTS in /etc/init.d/openarena-server so it can
        operate without /etc/default/openarena-server
      - "+exec etc/openarena-server/server.cfg" is no longer part of DAEMON_OPTS
      - add native systemd units
      - add optional instanced systemd units for multiple servers
        per machine; stop documenting how to do this with @reboot cron jobs
---
 debian/changelog                          | 10 ++++
 debian/openarena-server.NEWS              | 23 ++++++++
 debian/openarena-server.README.Debian     | 98 +++++++++++++++----------------
 debian/openarena-server.default           | 23 ++++----
 debian/openarena-server.init              | 13 +---
 debian/openarena-server.install           |  2 +
 debian/openarena-server.lintian-overrides |  2 +
 debian/openarena-server.postinst          |  5 ++
 debian/openarena-server.preinst           | 93 +++++++++++++++++++++++++----
 debian/openarena-server.service           | 25 ++++++++
 debian/openarena-server at .service          | 22 +++++++
 11 files changed, 233 insertions(+), 83 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 0919efa..75233a0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -8,6 +8,16 @@ openarena (0.8.8-10) UNRELEASED; urgency=low
   * Recommend update-rc.d unconditionally: it "does the right thing"
     for each of sysvinit, systemd and upstart
   * Mention service(8) in README.Debian for completeness
+  * Sync server support with quake/11:
+    - remove support for START_DAEMON
+    - if the server was previously disabled via START_DAEMON,
+      do a one-time migration to "update-rc.d $SERVICE disable"
+    - put default for DAEMON_OPTS in /etc/init.d/openarena-server so it can
+      operate without /etc/default/openarena-server
+    - "+exec etc/openarena-server/server.cfg" is no longer part of DAEMON_OPTS
+    - add native systemd units
+    - add optional instanced systemd units for multiple servers
+      per machine; stop documenting how to do this with @reboot cron jobs
   * Use LDFLAGS on non-Linux too
   * Canonicalize Vcs-Git, Vcs-Browser and switch Vcs-Browser to cgit
   * Symlink all of /etc/openarena-server into the OpenArena search path
diff --git a/debian/openarena-server.NEWS b/debian/openarena-server.NEWS
index 9696e75..0c4272d 100644
--- a/debian/openarena-server.NEWS
+++ b/debian/openarena-server.NEWS
@@ -1,3 +1,26 @@
+openarena-server (0.8.8-10) experimental; urgency=low
+
+  openarena-server configuration has changed in this version for
+  better systemd support.
+
+  The DAEMON_OPTS variable in /etc/default/openarena-server no longer
+  contains a configurable "+exec" command. /etc/openarena-server/server.cfg
+  will always be executed in addition to whatever is specified in
+  DAEMON_OPTS, and the default DAEMON_OPTS is now empty.
+
+  The START_DAEMON variable in /etc/default/openarena-server is no longer
+  supported. If openarena-server was previously disabled via START_DAEMON,
+  upgrading to this version will run "update-rc.d openarena-server disable"
+  to disable it in the correct way.
+
+  systemd users can now enable additional instances of the server,
+  openarena-server at INSTANCE.service, which use
+  /etc/default/openarena-server at INSTANCE
+  and /etc/openarena-server/INSTANCE.cfg instead.
+  See /usr/share/doc/openarena-server/README.Debian for details.
+
+ -- Simon McVittie <smcv at debian.org>  Wed, 04 Feb 2015 22:56:40 +0000
+
 openarena-server (0.8.8-1) experimental; urgency=low
 
   In the Debian packaging for OpenArena 0.8.1 and 0.8.5, the openarena
diff --git a/debian/openarena-server.README.Debian b/debian/openarena-server.README.Debian
index b771d5f..37834b1 100644
--- a/debian/openarena-server.README.Debian
+++ b/debian/openarena-server.README.Debian
@@ -1,70 +1,70 @@
 OpenArena dedicated server for Debian
 =====================================
 
-Running the server via the init script
---------------------------------------
+Running one server instance
+---------------------------
 
 The openarena-server init script runs a dedicated server as the user
 "Debian-openarena". This is a simple setup suitable for running one server
 on a machine; by default it will run a deathmatch server.
 
 The Debian-openarena user's home directory is /var/games/openarena-server,
-so you can find OA files in the /var/games/openarena-server/.openarena
-directory.
+and the equivalent of ~/.openarena for the default server is
+/var/games/openarena-server/server.oa.
 
 By default, the init script will use etc/openarena-server/server.cfg,
 which is a symlink to /etc/openarena-server/server.cfg. You can edit
 this file, or put an alternative configuration in
-/var/games/openarena-server/.openarena/baseoa and change
+/var/games/openarena-server/server.oa/baseoa and change
 /etc/default/openarena-server to exec that.
 
-The server can be managed in the usual way, e.g. via the recommended
-service(8) command:
-
-    service openarena-server stop
-    service openarena-server start
-
 The whole /etc/openarena-server directory is symlinked into the engine's
 search path as etc/openarena-server, so you can place files there and
 exec them with commands like "/exec etc/openarena-server/ctf.cfg".
 
-Disabling the init script
--------------------------
-
-To disable the init script (for instance if you want to run the server
-via screen(1), as below, or manually), use the facilities provided by your
-init system. The recommended command is
+The server can be managed in the usual way, e.g. via service(8)
+and update-rc.d(8) commands like
 
+    service openarena-server stop
+    service openarena-server start
     update-rc.d openarena-server disable
-
-which works for all of systemd, sysvinit and upstart.
-
-Changing the value of the START_DAEMON variable in
-/etc/default/openarena-server is deprecated. Please leave it set to
-"unless-disabled-by-upgrade".
-
-Running the server with cron and screen
----------------------------------------
-
-One alternative way to run the server is to run it in a screen(1) session
-from a cron @reboot action. This can be used to run multiple instances
-of the server; you'll need to set a different net_port on each server after
-the first, and it's safest to give each server a unique fs_homepath so they
-don't overwrite each other's configuration files.
-
-To do this, you could put something like this in the Debian-openarena user's
-crontab (don't break the long lines!):
-
-    @reboot screen -d -m -S ffa /usr/games/openarena-server +set fs_homepath /var/games/openarena-server/ffa +exec etc/openarena-server/ffa.cfg
-    @reboot screen -d -m -S ctf /usr/games/openarena-server +set fs_homepath /var/games/openarena-server/ctf +set net_port 54321 +exec etc/openarena-server/ctf.cfg
-
-or in /etc/crontab or a file in /etc/cron.d:
-
-    @reboot Debian-openarena screen -d -m -S ffa /usr/games/openarena-server +set fs_homepath /var/games/openarena-server/ffa +exec etc/openarena-server/ffa.cfg
-    @reboot Debian-openarena screen -d -m -S ctf /usr/games/openarena-server +set fs_homepath /var/games/openarena-server/ctf +set net_port 54321 +exec etc/openarena-server/ctf.cfg
-
-If you do that, you can access the servers' consoles by attaching a screen
-session to them:
-
-    sudo -u Debian-openarena screen -r ffa
-    sudo -u Debian-openarena screen -r ctf
+    update-rc.d openarena-server enable
+
+which should work for all of Debian's supported init systems.
+
+Running multiple server instances with systemd
+----------------------------------------------
+
+Under systemd, openarena-server supports additional instances of the server,
+so you can run a deathmatch server and a Capture the Flag server, or
+a vanilla OpenArena server and an Excessive Plus server.
+
+Each instance openarena-server at INSTANCE.service has configuration and state in
+/var/games/openarena-server/INSTANCE.oa, and will execute
+/etc/openarena-server/INSTANCE.cfg on startup.
+
+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/openarena-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.
+
+The instance name "server" cannot be used without disabling and stopping
+openarena-server.service, since it shares its configuration with that
+service.
+
+For instance, these shell commands (as root) would set up a Capture the
+Flag server on port 27970:
+
+    cat > /etc/default/openarena-server at ctf
+    DAEMON_OPTS="+set net_port 27970"
+    EOF
+    cat > /etc/openarena-server/ctf.cfg <<EOF
+    sv_hostname "My Capture the Flag Server"
+    g_gametype 4
+    map islandctf
+    EOF
+    systemctl daemon-reload
+    systemctl enable openarena-server at ctf.service
+    systemctl start openarena-server at ctf.service
diff --git a/debian/openarena-server.default b/debian/openarena-server.default
index 6ebf7b1..a3a36b8 100644
--- a/debian/openarena-server.default
+++ b/debian/openarena-server.default
@@ -1,16 +1,17 @@
 # Defaults for OpenArena init script
 # sourced by /etc/init.d/openarena-server
+# used as an EnvironmentFile by /lib/systemd/system/openarena-server.service
 # installed at /etc/default/openarena-server by the maintainer scripts
 
-# To disable the server, please use the normal mechanisms provided by init:
-# see /usr/share/doc/openarena-server/README.Debian.gz. Changing the value
-# of this variable is deprecated.
-START_DAEMON=unless-disabled-by-upgrade
-
-# Additional options that are passed to the daemon.
-# Add "+set dedicated 2" here, or "set dedicated 2" in server.cfg, if you want
-# your server advertised on the public server list.
+# Options that are passed to the daemon.
 #
-# server.cfg is a symlink to /etc/openarena-server/server.cfg, so you
-# can use that file for system-wide configuration.
-DAEMON_OPTS="+exec etc/openarena-server/server.cfg"
+# In addition to these options, the server will execute commands from
+# /etc/openarena-server/server.cfg using
+# "+exec etc/openarena-server/server.cfg".
+# For most options it's better to edit server.cfg instead, but certain
+# options such as fs_game and net_port can only be set here.
+DAEMON_OPTS=""
+
+# To disable the server, please use the normal mechanisms provided by init:
+# "update-rc.d openarena-server disable". The START_DAEMON variable is no
+# longer supported.
diff --git a/debian/openarena-server.init b/debian/openarena-server.init
index 3ffa3bd..a72fdd0 100644
--- a/debian/openarena-server.init
+++ b/debian/openarena-server.init
@@ -28,19 +28,12 @@ if [ -f /etc/default/$NAME ] ; then
 fi
 
 q3_start() {
-    if [ "$START_DAEMON" = "unless-disabled-by-upgrade" ]; then
-        if [ -e /var/games/openarena-server/init-script-disabled-by-upgrade ]; then
-            echo -n " (disabled during upgrade, not starting - see /usr/share/doc/openarena-server/NEWS.Debian.gz)"
-	    return 0
-        fi
-    elif [ "$START_DAEMON" != 1 ]; then
-        echo -n " (disabled in /etc/default/openarena-server - deprecated, see /usr/share/doc/openarena-server/README.Debian.gz)"
-        return 0
-    fi
     start-stop-daemon --start --quiet --pidfile $PIDFILE --oknodo \
 	--background --exec $BINARY --startas $DAEMON \
 	--make-pidfile --chuid $USER \
-	-- $DAEMON_OPTS > /dev/null 2>&1 || return 1
+        --\
+        +set com_homepath server.oa $DAEMON_OPTS\
+        +exec etc/openarena-server/server.cfg > /dev/null 2>&1 || return 1
     return 0
 }
 
diff --git a/debian/openarena-server.install b/debian/openarena-server.install
index 457c601..ce7b597 100644
--- a/debian/openarena-server.install
+++ b/debian/openarena-server.install
@@ -1,4 +1,6 @@
 debian/server.cfg etc/openarena-server
 debian/scripts/openarena-server usr/games
+debian/openarena-server at .service lib/systemd/system
+
 debian/tmp/usr/lib/openarena-server/*/*.so
 debian/tmp/usr/lib/openarena-server/*/*/*.so
diff --git a/debian/openarena-server.lintian-overrides b/debian/openarena-server.lintian-overrides
new file mode 100644
index 0000000..3f9120f
--- /dev/null
+++ b/debian/openarena-server.lintian-overrides
@@ -0,0 +1,2 @@
+# it's "update-rc.d disable" not "update-rc.d defaults"
+openarena-server binary: preinst-calls-updaterc.d openarena-server
diff --git a/debian/openarena-server.postinst b/debian/openarena-server.postinst
index 5a466d7..0a7ed55 100644
--- a/debian/openarena-server.postinst
+++ b/debian/openarena-server.postinst
@@ -13,6 +13,11 @@ case "$1" in
     install -d /var/games
     install -d /var/games/openarena-server
     chown Debian-openarena:games /var/games/openarena-server
+    if [ -d /var/games/openarena-server/.openarena ] && ! [ -e /var/games/openarena-server/server.oa ]; then
+        # we use com_homepath to redirect server stuff to a non-hidden
+        # directory and be ready for multi-instance; migrate old configuration
+        ln -s .openarena /var/games/quake3-server/server.oa
+    fi
   ;;
   abort-upgrade|abort-remove|abort-deconfigure)
   ;;
diff --git a/debian/openarena-server.preinst b/debian/openarena-server.preinst
index dff5e29..2ed645f 100644
--- a/debian/openarena-server.preinst
+++ b/debian/openarena-server.preinst
@@ -1,22 +1,89 @@
 #!/bin/sh
+# vim:set sw=2 sts=2 et:
 
 set -e
 
+quake_atomic_write () {
+  ## quake_atomic_write DIR FILE CONTENTS
+  ## Create DIR/FILE with contents (CONTENTS + '\n').
+  install -d "$1"
+  echo "$3" > "$1/$2.$$.tmp"
+  chmod 0644 "$1/$2.$$.tmp"
+  mv "$1/$2.$$.tmp" "$1/$2"
+}
+
+quake_disable () {
+  update-rc.d openarena-server disable
+
+  # Make deb-systemd-helper think the systemd unit was already installed
+  # and disabled, so that the disabledness sticks. Strictly speaking this
+  # is internal state, but it replicates what init-system-helpers/1.22
+  # would have done, so it should work as long as upgrades from jessie
+  # are supported.
+  quake_atomic_write /var/lib/systemd/deb-systemd-helper-enabled \
+    openarena-server.service.dsh-also \
+    /etc/systemd/system/multi-user.target.wants/openarena-server.service
+  if [ -L /etc/systemd/system/multi-user.target.wants/openarena-server.service ]; then
+    rm /etc/systemd/system/multi-user.target.wants/openarena-server.service
+  fi
+}
+
+quake_migrate_disabledness () {
+  echo "openarena-server.preinst: migrating from START_DAEMON to init script enable/disable status..." >&2
+
+  e=0
+  # Do this in a subshell just in case /etc/default/openarena-server has been
+  # patched by the sysadmin to exit the init script.
+  (
+    set +e
+    START_DAEMON=1
+    [ -r /etc/default/openarena-server ] && . /etc/default/openarena-server
+
+    case "$START_DAEMON" in
+      (1)
+        echo "Preserving current status of openarena-server init script (START_DAEMON=1 in /etc/default/openarena-server)" >&2
+        exit 104
+        ;;
+      (unless-disabled-by-upgrade)
+        if [ -e /var/games/openarena-server/init-script-disabled-by-upgrade ]; then
+          echo "Disabling openarena-server init script to preserve default from openarena-server (<< 0.8.8)" >&2
+          exit 101
+        else
+          echo "Preserving current status of openarena-server init script" >&2
+          exit 104
+        fi
+        ;;
+      (*)
+        # 0 or unknown
+        echo "Disabling openarena-server init script (previously disabled by START_DAEMON=$START_DAEMON in /etc/default/openarena-server)" >&2
+        exit 101
+        ;;
+    esac
+  ) || e="$?"
+
+  case "$e" in
+    (101)
+      # we already printed a message
+      quake_disable
+      ;;
+    (104)
+      # nothing to do and we already printed a message
+      ;;
+    (*)
+      # maybe the sysadmin stubbed it out with "exit 0" or "exit 1"?
+      echo "Sourcing /etc/default/openarena-server returned unexpected code, disabling init script" >&2
+      quake_disable
+      ;;
+  esac
+
+  # we have done the migration, so remove this to avoid confusion
+  rm -f /var/games/openarena-server/init-script-disabled-by-upgrade
+}
+
 case "$1" in
   (upgrade)
-    if dpkg --compare-versions "$2" lt 0.8.8; then
-      def=/etc/default/openarena-server
-      home=/var/games/openarena-server
-      inhibit=$home/init-script-disabled-by-upgrade
-
-      if test -e $def && grep '^START_DAEMON=1$' $def; then
-        echo "Not disabling openarena-server init script (previously enabled in $def)" >&2
-      else
-        echo "Disabling openarena-server init script (previously disabled in $def)" >&2
-        echo "Remove $inhibit to restore normal behaviour."
-	install -d $home
-	touch $inhibit
-      fi
+    if dpkg --compare-versions "$2" lt 0.8.8-10~; then
+      quake_migrate_disabledness "$@"
     fi
   ;;
   (install|abort-upgrade)
diff --git a/debian/openarena-server.service b/debian/openarena-server.service
new file mode 100644
index 0000000..44fb519
--- /dev/null
+++ b/debian/openarena-server.service
@@ -0,0 +1,25 @@
+[Unit]
+Description=OpenArena 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=openarena-server at server.service
+
+[Service]
+Type=simple
+User=Debian-openarena
+Environment=DAEMON_OPTS=
+EnvironmentFile=-/etc/default/openarena-server
+ExecStart=/usr/games/openarena-server +set com_homepath server.oa $DAEMON_OPTS +exec etc/openarena-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/openarena-server at .service b/debian/openarena-server at .service
new file mode 100644
index 0000000..a87183d
--- /dev/null
+++ b/debian/openarena-server at .service
@@ -0,0 +1,22 @@
+[Unit]
+Description=OpenArena game server (instance: "%i")
+After=network.target
+
+[Service]
+Type=simple
+User=Debian-openarena
+Environment=DAEMON_OPTS=
+EnvironmentFile=-/etc/default/openarena-server@%i
+ExecStart=/usr/games/openarena-server +set com_homepath %i.oa $DAEMON_OPTS +exec etc/openarena-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

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



More information about the Pkg-games-commits mailing list