Merge pull request #160 from klightspeed/1.4-dev#multiserver

1.4 Features
This commit is contained in:
Fez Vrasta 2015-09-14 11:23:52 +02:00
commit 22b021b41b
6 changed files with 98 additions and 21 deletions

View File

@ -303,6 +303,8 @@ doRun() {
arkserveropts="-MapModID=$serverMapModId" arkserveropts="-MapModID=$serverMapModId"
fi fi
arkextraopts=( )
# bring in ark_... options # bring in ark_... options
for varname in "${!ark_@}"; do for varname in "${!ark_@}"; do
name="${varname#ark_}" name="${varname#ark_}"
@ -320,12 +322,23 @@ doRun() {
fi fi
done done
# bring in arkflag_... flags
for varname in "${!arkflag_@}"; do
name="${varname#arkflag_}"
val="${!varname}"
if [ -n "$val" ]; then
arkextraopts=( "${arkextraopts[@]}" "-${name}" )
fi
done
arkserveropts="${arkserveropts}?listen" arkserveropts="${arkserveropts}?listen"
# run the server in background # run the server in background
echo "`timestamp`: start" echo "`timestamp`: start"
# set max open files limit before we start the server # set max open files limit before we start the server
ulimit -n $maxOpenFiles ulimit -n $maxOpenFiles
"$arkserverroot/$arkserverexec" "$arkserveropts" "$arkserverroot/$arkserverexec" "$arkserveropts" "${arkextraopts[@]}"
echo "`timestamp`: exited with status $?" echo "`timestamp`: exited with status $?"
} }
@ -346,6 +359,21 @@ doStart() {
fi fi
} }
#
# starts all servers specified by configfile_xxxxx in config file
#
doStartAll(){
doStart
for cfg in "${!configfile_@}"; do
if [ -f "${!cfg}" ]; then
(
source "${!cfg}"
doStart
)
fi
done
}
# #
# stop the ARK server # stop the ARK server
# #
@ -379,6 +407,21 @@ doStop() {
fi fi
} }
#
# stops all servers specified by configfile_xxxxx in config file
#
doStopAll(){
doStop
for cfg in "${!configfile_@}"; do
if [ -f "${!cfg}" ]; then
(
source "${!cfg}"
doStop
)
fi
done
}
# #
# install of ARK server # install of ARK server
# #
@ -609,6 +652,7 @@ doWarnUpdate(){
doBackup(){ doBackup(){
local datestamp=`date +"%Y-%m-%d_%H.%M.%S"` local datestamp=`date +"%Y-%m-%d_%H.%M.%S"`
local backupdir="${arkbackupdir}/${datestamp}" local backupdir="${arkbackupdir}/${datestamp}"
local savedir="SavedArks"
mkdir -p "$backupdir" mkdir -p "$backupdir"
# extract the map name from the active map mod # extract the map name from the active map mod
@ -625,17 +669,22 @@ doBackup(){
' <"${arkserverroot}/ShooterGame/Content/Mods/${serverMapModId}/mod.info")" ' <"${arkserverroot}/ShooterGame/Content/Mods/${serverMapModId}/mod.info")"
fi fi
# Get save directory name
if [ -n "${ark_AltSaveDirectoryName}" ]; then
savedir="${ark_AltSaveDirectoryName}"
fi
# ARK server uses Write-Unlink-Rename # ARK server uses Write-Unlink-Rename
echo -ne "${NORMAL} Copying ARK world file " echo -ne "${NORMAL} Copying ARK world file "
cp -p "${arkserverroot}/ShooterGame/Saved/SavedArks/${serverMap##*/}.ark" "${backupdir}/${serverMap##*/}.ark" cp -p "${arkserverroot}/ShooterGame/Saved/${savedir}/${serverMap##*/}.ark" "${backupdir}/${serverMap##*/}.ark"
if [ ! -f "${backupdir}/${serverMap##*/}.ark" ]; then if [ ! -f "${backupdir}/${serverMap##*/}.ark" ]; then
sleep 2 sleep 2
cp -p "${arkserverroot}/ShooterGame/Saved/SavedArks/${serverMap##*/}.ark" "${backupdir}/${serverMap##*/}.ark" cp -p "${arkserverroot}/ShooterGame/Saved/${savedir}/${serverMap##*/}.ark" "${backupdir}/${serverMap##*/}.ark"
fi fi
# If both attempts fail, server may have # If both attempts fail, server may have
# crashed between unlink and rename # crashed between unlink and rename
if [ ! -f "${backupdir}/${serverMap##*/}.ark" ]; then if [ ! -f "${backupdir}/${serverMap##*/}.ark" ]; then
cp -p "${arkserverroot}/ShooterGame/Saved/SavedArks/${serverMap##*/}.tmp" "${backupdir##*/}/${serverMap##*/}.ark" cp -p "${arkserverroot}/ShooterGame/Saved/${savedir}/${serverMap##*/}.tmp" "${backupdir##*/}/${serverMap##*/}.ark"
fi fi
if [ -f "${backupdir}/${serverMap##*/}.ark" ]; then if [ -f "${backupdir}/${serverMap##*/}.ark" ]; then
echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]"
@ -648,7 +697,7 @@ doBackup(){
# ARK server uses a non-blocking lock and will # ARK server uses a non-blocking lock and will
# fail to update the file if the lock fails. # fail to update the file if the lock fails.
echo -e "${NORMAL} Copying ARK profile files" echo -e "${NORMAL} Copying ARK profile files"
for f in "${arkserverroot}/ShooterGame/Saved/SavedArks/"*.arkprofile; do for f in "${arkserverroot}/ShooterGame/Saved/${savedir}/"*.arkprofile; do
echo -ne "${NORMAL} ${f##*/} " echo -ne "${NORMAL} ${f##*/} "
cp -p "${f}" "${backupdir}/${f##*/}" cp -p "${f}" "${backupdir}/${f##*/}"
if [ ! -s "${backupdir}/${f##*/}" ]; then if [ ! -s "${backupdir}/${f##*/}" ]; then
@ -669,7 +718,7 @@ doBackup(){
# ARK server uses Lock-Truncate-Write-Unlock # ARK server uses Lock-Truncate-Write-Unlock
echo -e "${NORMAL} Copying ARK tribe files " echo -e "${NORMAL} Copying ARK tribe files "
for f in "${arkserverroot}/ShooterGame/Saved/SavedArks/"*.arktribe; do for f in "${arkserverroot}/ShooterGame/Saved/${savedir}/"*.arktribe; do
echo -ne "${NORMAL} ${f##*/} " echo -ne "${NORMAL} ${f##*/} "
cp -p "${f}" "${backupdir}/${f##*/}" cp -p "${f}" "${backupdir}/${f##*/}"
if [ ! -s "${backupdir}/${f##*/}" ]; then if [ ! -s "${backupdir}/${f##*/}" ]; then
@ -784,16 +833,35 @@ checkConfig
while true; do while true; do
case "$1" in case "$1" in
start) start)
doStart if [ "$2" == "--all" ]; then
doStartAll
shift
else
doStart
fi
;; ;;
stop) stop)
doStop if [ "$2" == "--all" ]; then
doStopAll
shift
else
doStop
fi
;; ;;
restart) restart)
doStop if [ "$2" == "--all" ]; then
doStopAll
else
doStop
fi
echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog"
sleep 1 sleep 1
doStart if [ "$2" == "--all" ]; then
doStartAll
shift
else
doStart
fi
echo "`timestamp`: start" >> "$logdir/$arkmanagerLog" echo "`timestamp`: start" >> "$logdir/$arkmanagerLog"
echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog" echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog"
;; ;;
@ -855,8 +923,11 @@ while true; do
echo "checkupdate Check for a new ARK server version" echo "checkupdate Check for a new ARK server version"
echo "install Install the ARK server files from steamcmd" echo "install Install the ARK server files from steamcmd"
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 "start Starts the server" echo "start Starts the server"
echo "start --all Starts all servers specified in configfile_xxxxx"
echo "stop Stops the server" echo "stop Stops the server"
echo "stop --all Stops all servers specified in configfile_xxxxx"
echo "status Returns the status of the current ARK server instance" echo "status Returns the status of the current ARK server instance"
echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again" echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again"
echo "update --force Apply update without check the current version" echo "update --force Apply update without check the current version"

View File

@ -22,6 +22,7 @@ msgWarnUpdateSeconds="This ARK server will shutdown for an update in %d seconds"
# inside your GameUserSettings.ini file # inside your GameUserSettings.ini file
serverMap="TheIsland" # server map (default TheIsland) serverMap="TheIsland" # server map (default TheIsland)
#serverMapModId="469987622" # Uncomment this to specify the Map Mod Id (<fileid> in http://steamcommunity.com/sharedfiles/filedetails/?id=<fileid>) #serverMapModId="469987622" # Uncomment this to specify the Map Mod Id (<fileid> in http://steamcommunity.com/sharedfiles/filedetails/?id=<fileid>)
#ark_TotalConversionMod="496735411" # Uncomment this to specify a total-conversion mod
ark_RCONEnabled="True" # Enable RCON Protocol ark_RCONEnabled="True" # Enable RCON Protocol
ark_RCONPort="32330" # RCON Port ark_RCONPort="32330" # RCON Port
ark_SessionName="ARK Server Tools" # if your session name needs special characters please use the .ini instead ark_SessionName="ARK Server Tools" # if your session name needs special characters please use the .ini instead
@ -31,6 +32,11 @@ ark_ServerPassword="" # ARK server
ark_ServerAdminPassword="keyboardcat" # ARK server admin password, KEEP IT SAFE! ark_ServerAdminPassword="keyboardcat" # ARK server admin password, KEEP IT SAFE!
ark_MaxPlayers="70" ark_MaxPlayers="70"
#ark_GameModIds="487516323,487516324,487516325" # Uncomment to specify additional mods by Mod Id separated by commas #ark_GameModIds="487516323,487516324,487516325" # Uncomment to specify additional mods by Mod Id separated by commas
#ark_AltSaveDirectoryName="SotF" # Uncomment to specify a different save directory name
# ARK server flags - use arkflag_<optionname>=true
#arkflag_OnlyAdminRejoinAsSpectator=true # Uncomment to only allow admins to rejoin as spectator
#arkflag_DisableDeathSpectator=true # Uncomment to disable players from becoming spectators when they die
# config Service # config Service
servicename="arkserv" # Name of the service (don't change if you don't know what are you doing) servicename="arkserv" # Name of the service (don't change if you don't know what are you doing)
@ -42,4 +48,4 @@ mod_appid=346110 # App ID for
# alternate configs # alternate configs
# example for config name "ark1": # example for config name "ark1":
#config_ark1="/path/to/config/file" #configfile_ark1="/path/to/config/file"

View File

@ -29,7 +29,7 @@ case "$1" in
start) start)
log_daemon_msg "Starting" "$NAME" log_daemon_msg "Starting" "$NAME"
ulimit -n 100000 ulimit -n 100000
su -s /bin/sh -c "$DAEMON start" $steamcmd_user su -s /bin/sh -c "$DAEMON start --all" $steamcmd_user
sleep 5 sleep 5
PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'`
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
@ -42,7 +42,7 @@ case "$1" in
stop) stop)
log_daemon_msg "Stopping" "$NAME" log_daemon_msg "Stopping" "$NAME"
su -s /bin/sh -c "$DAEMON stop" $steamcmd_user su -s /bin/sh -c "$DAEMON stop --all" $steamcmd_user
sleep 5 sleep 5
PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'`
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
@ -55,7 +55,7 @@ case "$1" in
restart) restart)
ulimit -n 100000 ulimit -n 100000
su -s /bin/sh -c "$DAEMON restart" $steamcmd_user su -s /bin/sh -c "$DAEMON restart --all" $steamcmd_user
;; ;;
status) status)

View File

@ -15,7 +15,7 @@ depend(){
start(){ start(){
ebegin "Starting ARK manager daemon" ebegin "Starting ARK manager daemon"
ulimit -n 100000 ulimit -n 100000
su -s /bin/sh -c "$DAEMON start" $steamcmd_user su -s /bin/sh -c "$DAEMON start --all" $steamcmd_user
sleep 5 sleep 5
PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'`
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
@ -27,7 +27,7 @@ start(){
stop(){ stop(){
ebegin "Stopping ARK manager daemon" ebegin "Stopping ARK manager daemon"
su -s /bin/sh -c "$DAEMON start" $steamcmd_user su -s /bin/sh -c "$DAEMON stop --all" $steamcmd_user
sleep 5 sleep 5
PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'`
if [ -n "$PID" ]; then if [ -n "$PID" ]; then

View File

@ -43,7 +43,7 @@ case "$1" in
start) start)
echo -n "Starting $NAME: " echo -n "Starting $NAME: "
ulimit -n 100000 ulimit -n 100000
su -s /bin/sh -c "$DAEMON start" $steamcmd_user > /dev/null su -s /bin/sh -c "$DAEMON start --all" $steamcmd_user > /dev/null
sleep 5 sleep 5
PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'`
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
@ -59,7 +59,7 @@ case "$1" in
stop) stop)
echo -n "Stopping $NAME: " echo -n "Stopping $NAME: "
su -s /bin/sh -c "$DAEMON stop" $steamcmd_user > /dev/null su -s /bin/sh -c "$DAEMON stop --all" $steamcmd_user > /dev/null
sleep 5 sleep 5
PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'`
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
@ -76,7 +76,7 @@ case "$1" in
restart) restart)
echo -n "Restarting $NAME: " echo -n "Restarting $NAME: "
ulimit -n 100000 ulimit -n 100000
su -s /bin/sh -c "$DAEMON restart" $steamcmd_user > /dev/null su -s /bin/sh -c "$DAEMON restart --all" $steamcmd_user > /dev/null
echo "OK" echo "OK"
;; ;;

View File

@ -3,8 +3,8 @@ Description=Daemon to start ark server
After=network.target After=network.target
[Service] [Service]
ExecStart=/usr/libexec/arkmanager/arkmanager.init start ExecStart=/usr/libexec/arkmanager/arkmanager.init start --all
ExecStop=/usr/libexec/arkmanager/arkmanager.init stop ExecStop=/usr/libexec/arkmanager/arkmanager.init stop --all
Type=forking Type=forking
PIDFile=/var/run/arkmanager.pid PIDFile=/var/run/arkmanager.pid