[openjk] 14/15: Add init script and instanced systemd unit
Simon McVittie
smcv at debian.org
Tue Dec 30 22:11:47 UTC 2014
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch master
in repository openjk.
commit 63012951bfbf6a55504b627652ac601f420b10c0
Author: Simon McVittie <smcv at debian.org>
Date: Tue Dec 30 20:35:41 2014 +0000
Add init script and instanced systemd unit
---
debian/control | 2 +
debian/default.cfg | 52 ++++++++++++++++++++
debian/openjk-academy-server.README.Debian | 57 ++++++++++++++++++++++
debian/openjk-academy-server.install | 2 +
debian/openjk-academy-server.links | 3 ++
debian/openjk-academy-server.openjkded.init | 67 ++++++++++++++++++++++++++
debian/openjk-academy-server.openjkded.service | 15 ++++++
debian/openjk-academy-server.postinst | 30 ++++++++++++
debian/openjk-academy-server.postrm | 16 ++++++
debian/openjkded at .service | 22 +++++++++
debian/rules | 12 ++++-
11 files changed, 277 insertions(+), 1 deletion(-)
diff --git a/debian/control b/debian/control
index cef695b..374596b 100644
--- a/debian/control
+++ b/debian/control
@@ -6,6 +6,7 @@ Uploaders: Simon McVittie <smcv at debian.org>
Build-Depends:
cmake,
debhelper (>= 9),
+ dh-systemd,
dpkg-dev (>= 1.16.1),
icnsutils,
imagemagick,
@@ -43,6 +44,7 @@ Architecture: i386 amd64
Depends:
${misc:Depends},
${shlibs:Depends},
+ adduser,
jedi-academy-data | game-data-packager (>= 38),
openjk-common,
Description: Jedi Academy multiplayer game server
diff --git a/debian/default.cfg b/debian/default.cfg
new file mode 100644
index 0000000..f7292e5
--- /dev/null
+++ b/debian/default.cfg
@@ -0,0 +1,52 @@
+// Sample server configuration for OpenJK in Debian
+//
+// See e.g. http://www.chopshopservers.com/education/homeserver.htm for more
+// commands and variables.
+
+seta sv_hostname "An unconfigured Debian server"
+// sorry, couldn't resist -smcv
+seta g_motd "may the source be with you"
+
+// The port must be different for each server instance. The default is 29070.
+seta net_port 29070
+
+// Game type. If you change this, change the map below too.
+//
+// In OpenJK, these are a mixture of the ones from Jedi Outcast and
+// Jedi Academy:
+//
+// 0: free-for-all (deathmatch)
+// 1: holocron
+// 2: Jedi Master
+// 3: duel (1:1 tournament)
+// 4: power duel (2:1 tournament)
+// 5: single player free-for-all
+// 6: team free-for-all
+// 7: siege
+// 8: capture the flag
+// 9: capture the ysalamiri
+seta g_gametype "0"
+
+// starting map (required)
+//
+// mp/ffa1: Vjun Sentinel
+// mp/ffa2: Korriban
+// mp/ffa3: Tatooine
+// mp/ffa4: Rift Sanctuary
+// mp/ffa5: Taspir
+// mp/ctf1: Imperial Drop Zone
+// mp/ctf2: Hoth Wasteland
+// mp/ctf3: Yavin Hilltops
+// mp/ctf4: Coruscant Streets
+// mp/ctf5: Factory
+// mp/duel1: Bespin Courtyard
+// mp/duel2: Generator Room
+// mp/duel3: Imperial Shaft
+// mp/duel4: Imperial Control Room
+// mp/duel5: Taspir Landing
+// mp/duel6: Yavin Training Grounds
+// mp/duel7: Rancor Pit
+// mp/duel8: Abandoned City
+// mp/duel9: Hoth
+// mp/duel10: Vjun Fuel Processing
+map mp/ffa1
diff --git a/debian/openjk-academy-server.README.Debian b/debian/openjk-academy-server.README.Debian
new file mode 100644
index 0000000..d54baf6
--- /dev/null
+++ b/debian/openjk-academy-server.README.Debian
@@ -0,0 +1,57 @@
+Jedi Academy dedicated server for Debian
+========================================
+
+Running the server
+------------------
+
+Installing the openjk-academy-server package provides a dedicated server
+running as the user "openjk-academy-server", from an init script named
+openjkded. This is a simple setup suitable for running one server on
+a machine.
+
+By default, the server will use etc/openjk-academy-server/default.cfg,
+which is a symlink to /etc/openjk-academy-server/default.cfg. You can edit
+this file to reconfigure the default instance.
+
+The server can be managed in the usual way, e.g. via service(8) commands
+like
+
+ service openjkded stop
+ service openjkded start
+
+which should work for all of systemd, sysvinit and upstart.
+
+The whole /etc/openjk-academy-server directory is symlinked into the engine's
+search path as etc/openjk-academy-server, so you can place files there and
+execute them with commands like "exec etc/openjk-academy-server/ctf.cfg".
+
+Disabling the server
+--------------------
+
+To disable the default instance, use the facilities provided by your
+init system. The recommended command is
+
+ update-rc.d openjkded disable
+
+which should work for all of systemd, sysvinit and upstart.
+
+Multiple instances under systemd
+--------------------------------
+
+Under systemd, openjkded.service just depends on openjkded at default.service,
+which runs the actual server. You can create an additional instance
+"foo" like this:
+
+- create /etc/rtcw-server/foo.cfg based on /etc/rtcw-server/default.cfg
+ (remember to change the net_port)
+- run "systemctl enable openjkded at foo.service"
+
+You can control individual instances with commands like
+"systemctl start openjkded at foo.service".
+You can also use commands like "systemctl start openjkded.service"
+to start the default instance and all enabled instances.
+
+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 openjkded at default.service")
+or disable openjkded.service ("systemctl disable openjkded.service").
diff --git a/debian/openjk-academy-server.install b/debian/openjk-academy-server.install
index edfac8b..b543a33 100644
--- a/debian/openjk-academy-server.install
+++ b/debian/openjk-academy-server.install
@@ -3,3 +3,5 @@
debian/scripts/openjkded usr/games
usr/lib/openjk/openjkded usr/lib/openjk-academy
usr/lib/openjk/openjkded.* usr/lib/openjk-academy
+debian/openjkded at .service lib/systemd/system
+debian/default.cfg etc/openjk-academy-server
diff --git a/debian/openjk-academy-server.links b/debian/openjk-academy-server.links
new file mode 100644
index 0000000..7aba54a
--- /dev/null
+++ b/debian/openjk-academy-server.links
@@ -0,0 +1,3 @@
+# so you can do "exec etc/openjk-academy-server/default.cfg"
+etc/openjk-academy-server usr/lib/openjk-academy/base/etc/openjk-academy-server
+etc/openjk-academy-server usr/lib/openjk-academy/OpenJK/etc/openjk-academy-server
diff --git a/debian/openjk-academy-server.openjkded.init b/debian/openjk-academy-server.openjkded.init
new file mode 100644
index 0000000..735d80f
--- /dev/null
+++ b/debian/openjk-academy-server.openjkded.init
@@ -0,0 +1,67 @@
+#!/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: openjkded openjk-academy-server
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop:
+# Short-Description: Jedi Academy game server
+# Description: Jedi Academy multiplayer dedicated server using the
+# OpenJK engine.
+### END INIT INFO
+
+PACKAGE="openjk-academy-server"
+NAME="openjkded"
+DESC="Jedi Academy game server"
+DAEMON="/usr/games/$NAME"
+BINARY="/usr/lib/openjk-academy/$NAME"
+START_ARGS="--background --make-pidfile --chuid ${PACKAGE}"
+DAEMON_ARGS="+exec etc/${PACKAGE}/default.cfg"
+
+# The actual daemon is in openjk-common, this package just has init scripts.
+[ -e "/usr/lib/openjk-academy/${PACKAGE}-installed" ] || exit 0
+
+# The init script corresponds to the "default" systemd instance
+HOME=/var/games/openjk-academy-server/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/openjk-academy-server.openjkded.service b/debian/openjk-academy-server.openjkded.service
new file mode 100644
index 0000000..d247dfe
--- /dev/null
+++ b/debian/openjk-academy-server.openjkded.service
@@ -0,0 +1,15 @@
+# This service is actually more like a systemd target,
+# but we are using a service so it will mask the init script.
+[Unit]
+Description=Jedi Academy game server
+After=network.target
+Wants=openjkded at default.service
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/bin/true
+
+[Install]
+WantedBy=multi-user.target
+Alias=openjk-academy-server.service
diff --git a/debian/openjk-academy-server.postinst b/debian/openjk-academy-server.postinst
new file mode 100644
index 0000000..b1c63ca
--- /dev/null
+++ b/debian/openjk-academy-server.postinst
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+set -e
+
+case "$1" in
+ configure)
+ if ! getent passwd openjk-academy-server >/dev/null; then
+ adduser --disabled-password --quiet --system \
+ --home /var/games/openjk-academy-server --no-create-home \
+ --gecos "Jedi Academy dedicated server" \
+ --ingroup games openjk-academy-server
+ fi
+ # Unlock account, if it was locked by our postrm
+ if [ -f /etc/shadow ]; then
+ usermod -U -e '' openjk-academy-server
+ else
+ usermod -U openjk-academy-server
+ fi
+ install -d /var/games
+ install -d -o openjk-academy-server -g games /var/games/openjk-academy-server
+ ;;
+ abort-upgrade|abort-remove|abort-deconfigure)
+ ;;
+ *)
+ echo "postinst called with unknown argument \`$1'" >&2
+ exit 1
+ ;;
+esac
+
+#DEBHELPER#
diff --git a/debian/openjk-academy-server.postrm b/debian/openjk-academy-server.postrm
new file mode 100644
index 0000000..4a5ce98
--- /dev/null
+++ b/debian/openjk-academy-server.postrm
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+set -e
+
+#DEBHELPER#
+
+if [ "$1" = "purge" ] ; then
+ # Lock account on purge
+ if [ -f /etc/shadow ]; then
+ usermod -L -e 1 openjk-academy-server
+ else
+ usermod -L openjk-academy-server
+ fi
+ rm -r /var/games/openjk-academy-server
+ rmdir --ignore-fail-on-non-empty /var/games
+fi
diff --git a/debian/openjkded at .service b/debian/openjkded at .service
new file mode 100644
index 0000000..9739082
--- /dev/null
+++ b/debian/openjkded at .service
@@ -0,0 +1,22 @@
+[Unit]
+Description=Jedi Academy game server - %i configuration
+PartOf=openjkded.service
+Before=openjkded.service
+After=network.target
+
+[Service]
+ConditionPathExists=/etc/openjk-academy-server/%i.cfg
+Environment=HOME=/var/games/openjk-academy-server/%i.home
+Environment=XDG_DATA_HOME=/var/games/openjk-academy-server/%i.home
+Environment=XDG_CACHE_HOME=/var/games/openjk-academy-server/%i.home/cache
+Environment=XDG_CONFIG_HOME=/var/games/openjk-academy-server/%i.home/config
+ExecStart=/usr/games/openjkded +exec etc/openjk-academy-server/%i.cfg
+Restart=on-failure
+RestartPreventExitStatus=72
+
+[Install]
+WantedBy=multi-user.target
+# We deliberately do not set DefaultInstance so that
+# "update-rc.d openjkded disable" -> "systemctl disable openjkded.service"
+# results in openjkded at default.service not being started unless explicitly
+# requested.
diff --git a/debian/rules b/debian/rules
index 9f7b871..11640f2 100755
--- a/debian/rules
+++ b/debian/rules
@@ -30,7 +30,7 @@ include /usr/share/dpkg/default.mk
# for convenience, use a builddir that is excluded by upstream's .gitignore
%:
- dh $@ --builddir=obj --parallel
+ dh $@ --builddir=obj --with=systemd --parallel
override_dh_auto_configure:
dh_auto_configure -- \
@@ -93,6 +93,16 @@ override_dh_auto_install: debian/icons
< debian/scripts/jedi.in > debian/scripts/openjkded
chmod 0755 debian/scripts/openj*
+override_dh_install:
+ dh_install
+ touch debian/openjk-academy-server/usr/lib/openjk-academy/openjk-academy-server-installed
+
+override_dh_systemd_enable:
+ dh_systemd_enable -popenjk-academy-server --name=openjkded
+
+override_dh_installinit:
+ dh_installinit -popenjk-academy-server --name=openjkded
+
debian/icons: debian/rules
install -d debian/icons/512 debian/icons/128 \
debian/icons/32 debian/icons/16
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git
More information about the Pkg-games-commits
mailing list