From b76be7513ab20e3dbb42a45ff8879691b2b9f85b Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Mon, 3 Jun 2024 10:39:11 -0400 Subject: [PATCH] daemon service files for distros * to this files to work you must set: * gameid in defaults , see multicraftserver.defaults file for set the paths of this file to work in scripts daemons * log file goes to /var/log/multicraft/multicraft.log * start config file to /etc/multicraft/multicraft.conf * user to start the daemon as "multicraft" * the game group must exist, the user must be into * the shitstemd custom daemon is special, you can use as "multicraftserverNAME" and will use the config file "/e/tc/multicraft/NAME.conf" and log as "/var/log/multicraft/NAME.log" with gameid as "NAME" * sysvinit script to new file: multicraftserver.init * openrc script to new file: multicraftserver.initd * shit-stemd script to new file: multicraftserver.service * shist-stemd custom config argument daemon as new file: multicraftserver@.service * log rotate for all services as multicraftserver.logrotate * defaults starting values for scripts as multicraftserver.defaults * closes https://codeberg.org/minenux/minetest-engine-multicraft2/issues/52 * closes https://github.com/MultiCraft/MultiCraft/issues/59 * packages at https://build.opensuse.org/project/show/home:venenux:minenux --- doc/multicraftserver.confd | 7 +++ doc/multicraftserver.defaults | 9 ++++ doc/multicraftserver.init | 87 ++++++++++++++++++++++++++++++++++ doc/multicraftserver.initd | 33 +++++++++++++ doc/multicraftserver.logrotate | 13 +++++ doc/multicraftserver.service | 16 +++++++ doc/multicraftserver@.service | 16 +++++++ 7 files changed, 181 insertions(+) create mode 100644 doc/multicraftserver.confd create mode 100644 doc/multicraftserver.defaults create mode 100644 doc/multicraftserver.init create mode 100644 doc/multicraftserver.initd create mode 100644 doc/multicraftserver.logrotate create mode 100644 doc/multicraftserver.service create mode 100644 doc/multicraftserver@.service diff --git a/doc/multicraftserver.confd b/doc/multicraftserver.confd new file mode 100644 index 000000000..22d81a2b2 --- /dev/null +++ b/doc/multicraftserver.confd @@ -0,0 +1,7 @@ +# alpine based server default distro config file +USER="multicraft" +GROUP="games" +LOG="/var/log/multicraft/multicraft.log" +CONFIG="/etc/multicraft/multicraft.conf" +ARGS="" +GAMEID="minenux" diff --git a/doc/multicraftserver.defaults b/doc/multicraftserver.defaults new file mode 100644 index 000000000..0c41d8688 --- /dev/null +++ b/doc/multicraftserver.defaults @@ -0,0 +1,9 @@ +# DEB/RPM based server default distro config file +# for deb place as /etc/defaults/multicraftserver +# for rpm place as /etc/sysconfig/multicraftserver +USER="multicraft" +GROUP="games" +LOG="/var/log/multicraft/multicraft.log" +CONFIG="/etc/multicraft/multicraft.conf" +ARGS="" +GAMEID="minenux" diff --git a/doc/multicraftserver.init b/doc/multicraftserver.init new file mode 100644 index 000000000..7f5a8f914 --- /dev/null +++ b/doc/multicraftserver.init @@ -0,0 +1,87 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: multicraftserver +# Required-Start: $remote_fs $network +# Required-Stop: $remote_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: multicraftserver daemon by MinenuX +# Description: MinenuX dedicated game server for multicraft +### END INIT INFO + +PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" +NAME="multicraftserver" +DAEMON="/usr/games/$NAME" +DESC="multicraft network game server" +PIDFILE="/var/run/$NAME.pid" +BINARY="/usr/games/$NAME" +USER="multicraft" + +test -x $DAEMON || exit 0 + +. /lib/lsb/init-functions + +# Include defaults if available +if [ -f /etc/default/$NAME ] ; then + . /etc/default/$NAME +fi + +DAEMON_OPTS = "--logfile $LOG --config $CONFIG --gameid $GAMEID" + +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 $? + ;; + reload) + log_begin_msg "Reloading $DESC: $NAME" + start-stop-daemon --signal HUP --exec "$BINARY" --pidfile "$PIDFILE" + 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|reload}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/doc/multicraftserver.initd b/doc/multicraftserver.initd new file mode 100644 index 000000000..e9216d3ca --- /dev/null +++ b/doc/multicraftserver.initd @@ -0,0 +1,33 @@ +#!/sbin/openrc-run + +description="multicraftserver daemon by MinenuX" + +pidfile="/var/run/$SVCNAME.pid" +command="/usr/bin/multicraftserver" + +start_stop_daemon_args="--user ${USER:-multicraft} --group ${GROUP:-games} --make-pidfile --pidfile $pidfile --background --quiet --wait 300" +command_args="$ARGS" + + +depend() { + need net + after firewall +} + +optional_command_arg() { + if [ -n "$2" ]; then + command_args="$command_args $1 $2" + fi +} + +start_pre() { + optional_command_arg --logfile $LOG + optional_command_arg --config $CONFIG + optional_command_arg --gameid $GAMEID +} + +reload() { + ebegin "Reloading $SVCNAME" + start-stop-daemon --signal HUP --exec "$EXEC" --pidfile "$pidfile" + eend $? +} diff --git a/doc/multicraftserver.logrotate b/doc/multicraftserver.logrotate new file mode 100644 index 000000000..a26d28683 --- /dev/null +++ b/doc/multicraftserver.logrotate @@ -0,0 +1,13 @@ +/var/log/multicraft/*.log { + daily + missingok + copytruncate + rotate 14 + compress + delaycompress + notifempty + copytruncate + postrotate + service multicraftserver reload + endscript +} diff --git a/doc/multicraftserver.service b/doc/multicraftserver.service new file mode 100644 index 000000000..5147ac8c9 --- /dev/null +++ b/doc/multicraftserver.service @@ -0,0 +1,16 @@ +[Unit] +Description=multicraftserver daemon for multicraft.conf by MinenuX +Documentation=man:multicraftserver(6) +After=network.target +RequiresMountsFor=/var/games/multicraft + +[Service] +Restart=on-failure +User=multicraft +Group=games +ExecStart=/usr/games/multicraftserver --config /etc/multicraft/multicraft.conf --logfile /var/log/multicraft/multicraft.log +StandardOutput=null + +[Install] +WantedBy=multi-user.target + diff --git a/doc/multicraftserver@.service b/doc/multicraftserver@.service new file mode 100644 index 000000000..593856fe0 --- /dev/null +++ b/doc/multicraftserver@.service @@ -0,0 +1,16 @@ +[Unit] +Description=multicraftserver daemon for %i.conf by MinenuX +Documentation=man:multicraftserver(6) +After=network.target +RequiresMountsFor=/var/games/multicraft + +[Service] +Restart=on-failure +User=multicraft +Group=games +ExecStart=/usr/games/multicraftserver --config /etc/multicraft/%i.conf --logfile /var/log/multicraft/%i.log --gameid %i +StandardOutput=null + +[Install] +WantedBy=multi-user.target +