diff --git a/CMakeLists.txt b/CMakeLists.txt index bd38f5409..b497b428f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,6 +196,9 @@ if(UNIX AND NOT APPLE) install(FILES "misc/multicraft-xorg-icon-128.png" DESTINATION "${ICONDIR}/hicolor/128x128/apps" RENAME "multicraft.png") + install(FILES "misc/multicraftserver*service" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/systemd/system/") + install(FILES "misc/multicraftserver*init" DESTINATION "${CMAKE_INSTALL_PREFIX}/../etc/init.d/" RENAME "multicraftserver") + install(FILES "misc/multicraft.logrotate" DESTINATION "${CMAKE_INSTALL_PREFIX}/../etc/logrotate.d/" RENAME "multicraftserver") endif() if(APPLE) diff --git a/misc/multicraft.logrotate b/misc/multicraft.logrotate index 50d79a059..fd6c70382 100644 --- a/misc/multicraft.logrotate +++ b/misc/multicraft.logrotate @@ -1,4 +1,4 @@ -/var/log/minetest*.log { +/var/log/multicraft*.log { copytruncate notifempty missingok diff --git a/misc/multicraftserver b/misc/multicraftserver deleted file mode 100755 index 641dd111c..000000000 --- a/misc/multicraftserver +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -set -e - -exec @INSTALLPLACE@/multicraftserver \ - "$@" diff --git a/misc/multicraftserver.init b/misc/multicraftserver.init new file mode 100644 index 000000000..40b242983 --- /dev/null +++ b/misc/multicraftserver.init @@ -0,0 +1,85 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: minetest4-server +# Required-Start: $remote_fs $network +# Required-Stop: $remote_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start multicraft network game server +# Description: dedicated game server for multicraft +### END INIT INFO + +PATHBIN="@INSTALLPLACE@" +PATHLOG="/var/log/multicraft" +PATHETC="/etc/multicraft/muticraft.conf" + +PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" +NAME="multicraftserver" +DAEMON="$NAME" +DESC="$NAME server" +PIDFILE="/var/run/$NAME.pid" +BINARY="$PATHBIN/multicraftserver" +USER="multicraft" +DAEMON_OPTS="--config $PATHETC --logfile $PATHLOG" + +test -x $DAEMON || exit 0 + +. /lib/lsb/init-functions + +# Include defaults if available +if [ -f /etc/default/$NAME ] ; then + . /etc/default/$NAME +fi + +multicraft_start() { + 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 + return 0 +} + +multicraft_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" + multicraft_start + log_end_msg $? + ;; + stop) + log_begin_msg "Stopping $DESC: $NAME" + multicraft_stop + log_end_msg $? + ;; + restart|force-reload) + log_begin_msg "Restarting $DESC: $NAME" + multicraft_stop && sleep 1 && multicraft_start + log_end_msg $? + ;; + status) + status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + *) + # echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/misc/multicraftserver.service b/misc/multicraftserver.service index 1d1f0db54..f498617a0 100644 --- a/misc/multicraftserver.service +++ b/misc/multicraftserver.service @@ -2,13 +2,13 @@ Description=Multicraft multiplayer server multicraft.conf server config Documentation=man:multicraftserver(6) After=network.target -RequiresMountsFor=/var/games/multicraftserver +RequiresMountsFor=/var/games/multicraft [Service] Restart=on-failure User=multicraft Group=games -ExecStart=/usr/lib/multicraft/multicraftserver --config /etc/multicraft/multicraft.conf --logfile /var/log/multicraft/multicraft.log +ExecStart=@INSTALLPLACE@/multicraftserver --config /etc/multicraft/multicraft.conf --logfile /var/log/multicraft/multicraft.log StandardOutput=null [Install] diff --git a/misc/multicraftserver@.service b/misc/multicraftserver@.service index 804eed01a..a4c24a73f 100644 --- a/misc/multicraftserver@.service +++ b/misc/multicraftserver@.service @@ -2,13 +2,13 @@ Description=Multicraft multiplayer server %i.conf server config Documentation=man:multicraftserver(6) After=network.target -RequiresMountsFor=/var/games/multicraft-server +RequiresMountsFor=/var/games/multicraft [Service] Restart=on-failure User=multicraft Group=games -ExecStart=/usr/lib/multicraft/multicraftserver --config /etc/multicraft/%i.conf --logfile /var/log/multicraft/%i.log +ExecStart=@INSTALLPLACE@/multicraftserver --config /etc/multicraft/%i.conf --logfile /var/log/multicraft/%i.log StandardOutput=null [Install]