Merge pull request #225 from klightspeed/1.4-dev#upstart

Upstart and SystemD multi-server
This commit is contained in:
Fez Vrasta 2015-10-08 16:05:56 +02:00
commit 320dfe94fd
9 changed files with 48 additions and 103 deletions

View File

@ -1138,6 +1138,9 @@ printStatus(){
} }
useConfig() { useConfig() {
if [ "$1" == "main" ]; then
return
fi
for varname in "${!configfile_@}"; do for varname in "${!configfile_@}"; do
if [ "configfile_$1" == "$varname" ]; then if [ "configfile_$1" == "$varname" ]; then
source "${!varname}" source "${!varname}"
@ -1156,6 +1159,9 @@ checkConfig
while true; do while true; do
case "$1" in case "$1" in
run)
doRun
;;
start) start)
if [ "$2" == "--all" ]; then if [ "$2" == "--all" ]; then
doStartAll doStartAll
@ -1248,6 +1254,7 @@ while true; do
echo "installmod <modid> Installs a mod from the Steam workshop" echo "installmod <modid> Installs a mod from the Steam workshop"
echo "restart Stops the server and then starts it" echo "restart Stops the server and then starts it"
echo "restart --all Restarts all servers specified in configfile_xxxxx" echo "restart --all Restarts all servers specified in configfile_xxxxx"
echo "run Runs the server without daemonizing"
echo "start Starts the server" echo "start Starts the server"
echo "start --all Starts all servers specified in configfile_xxxxx" echo "start --all Starts all servers specified in configfile_xxxxx"
echo "stop Stops the server" echo "stop Stops the server"

View File

@ -251,11 +251,12 @@ else
fi fi
elif [ -f /etc/systemd/system.conf ]; then # used by systemd elif [ -f /etc/systemd/system.conf ]; then # used by systemd
mkdir -p "${INSTALL_ROOT}${LIBEXECDIR}" mkdir -p "${INSTALL_ROOT}${LIBEXECDIR}"
cp systemd/arkdaemon.init "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" cp systemd/arkmanager.init "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init"
chmod +x "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" chmod +x "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init"
cp systemd/arkdeamon.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" cp systemd/arkmanager.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service"
sed -i "s|=/usr/libexec/arkmanager/|=${LIBEXECDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" sed -i "s|=/usr/libexec/arkmanager/|=${LIBEXECDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service"
sed -i "s@^DAEMON=\"/usr/bin/@DAEMON=\"${BINDIR}/@" "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" cp systemd/arkmanager@.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service"
sed -i "s|=/usr/bin/|=${BINDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service"
if [ -z "${INSTALL_ROOT}" ]; then if [ -z "${INSTALL_ROOT}" ]; then
systemctl enable arkmanager.service systemctl enable arkmanager.service
echo "Ark server will now start on boot, if you want to remove this feature run the following line" echo "Ark server will now start on boot, if you want to remove this feature run the following line"

View File

@ -1,88 +0,0 @@
#!/bin/bash
#
# /usr/libexec/arkmanager/arkmanager.init
#
# ARK manager daemon
#
# chkconfig: 2345 80 20
# description: ARK manager daemon used to start the server and keep it updated
# processname: ShooterGameServer
# config: /etc/arkmanager/arkmanager.cfg
### BEGIN INIT INFO
# Provides: ARK manager deamon
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ARK manager deamon
# Description: ARK manager daemon used to start the server and keep it updated
#
### END INIT INFO
# Global variables
source /etc/arkmanager/arkmanager.cfg
NAME="ShooterGameServer"
LOGFILE="${logdir}/${NAME}.log"
DAEMON="/usr/bin/arkmanager"
GREEN="\\033[1;32m"
RED="\\033[1;31m"
NORMAL="\\033[0;39m"
set -e
# If the daemon is not there, then exit.
test -x $DAEMON || exit 5
case "$1" in
start)
echo -n "Starting $NAME: "
ulimit -n 100000
su -s /bin/sh -c "$DAEMON start" $steamcmd_user > /dev/null
sleep 5
PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'`
if [ -n "$PID" ]; then
echo "$PID" >/var/run/arkmanager.pid
echo "[" "$GREEN" " OK " "$NORMAL" "]"
exit 0
else
echo "[" "$RED" " FAILED " "$NORMAL" "]"
exit 1
fi
;;
stop)
echo -n "Stopping $NAME: "
su -s /bin/sh -c "$DAEMON stop" $steamcmd_user > /dev/null
sleep 5
PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'`
if [ -n "$PID" ]; then
echo "[" "$RED" " FAILED " "$NORMAL" "]"
exit 1
else
echo "[" "$GREEN" " OK " "$NORMAL" "]"
rm /var/run/arkmanager.pid
exit 0
fi
;;
restart)
echo -n "Restarting $NAME: "
ulimit -n 100000
su -s /bin/sh -c "$DAEMON restart" $steamcmd_user > /dev/null
echo "OK"
;;
status)
su -s /bin/sh -c "$DAEMON status" $steamcmd_user
exit 0
;;
*)
# For invalid arguments, print the usage message.
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

View File

@ -1,12 +0,0 @@
[Unit]
Description=Daemon to start ark server
After=network.target
[Service]
ExecStart=/usr/libexec/arkmanager/arkmanager.init start --all
ExecStop=/usr/libexec/arkmanager/arkmanager.init stop --all
Type=forking
PIDFile=/var/run/arkmanager.pid
[Install]
WantedBy=multi-user.target

5
tools/systemd/arkmanager.init Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
for service in main $(grep -o '^configfile_[^=]*' /etc/arkmanager/arkmanager.cfg); do
systemctl start arkmanager@${service#configfile_}
done

View File

@ -0,0 +1,11 @@
[Unit]
Description=Starts and stops all ark server instances
After=network.target
[Service]
ExecStart=/usr/libexec/arkmanager/arkmanager.init start
ExecStop=/usr/libexec/arkmanager/arkmanager.init stop
Type=oneshot
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,6 @@
[Unit]
Description=Daemon to start an ark server instance
[Service]
ExecStart=/usr/bin/arkmanager useconfig %i run
Type=simple

View File

@ -0,0 +1,7 @@
description "ARK Server Tools service"
instance $service
env DAEMON="/usr/bin/arkmanager"
exec "$DAEMON" useconfig $service run

View File

@ -0,0 +1,8 @@
start on runlevel [345]
stop on runlevel [!345]
script
for service in main $(grep -o '^configfile_[^=]*' /etc/arkmanager/arkmanager.cfg); do
start arkmanager-instance service=${service#configfile_}
done
end script