From 6f18d9adaefcea95f0afe9a90ee8e29c60c9653f Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Wed, 24 Jun 2015 17:51:03 +0200 Subject: [PATCH 01/50] log output of ShooterGameServer and moved arkmanager logs to arkmanager.log --- tools/arkmanager | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 463c74c..ebb5469 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -34,6 +34,9 @@ GREEN="\\033[1;32m" RED="\\033[1;31m" NORMAL="\\033[0;39m" +arkmanagerLog="arkmanager.log" # here are logged the actions performed by arkmanager +arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer + #--------------------- # functions #--------------------- @@ -155,8 +158,9 @@ doStart() { arkserveropts="${arkserveropts}?listen" # run the server in background - nohup "$arkserverroot/$arkserverexec" "$arkserveropts" /dev/null 2>&1 & - echo "$timestamp: start" >> "$logdir/arkserver.log" + echo "$timestamp: start" >> "$logdir/$arkserverLog" + nohup "$arkserverroot/$arkserverexec" "$arkserveropts" "$logdir/$arkserverLog" 2>&1 & # output of this command is logged + echo "$timestamp: start" >> "$logdir/$arkmanagerLog" tput rc; tput ed; echo "The server is now up" fi @@ -175,7 +179,7 @@ doStop() { tput rc; tput ed; echo "The server has been stopped" - echo "$timestamp: stop" >> "$logdir/arkserver.log" + echo "$timestamp: stop" >> "$logdir/$arkmanagerLog" else echo "The server is already stopped" fi @@ -255,11 +259,11 @@ case "$1" in ;; restart) doStop - echo "$timestamp: stop" >> "$logdir/arkserver.log" + echo "$timestamp: stop" >> "$logdir/$arkmanagerLog" sleep 10 doStart - echo "$timestamp: start" >> "$logdir/arkserver.log" - echo "$timestamp: restart" >> "$logdir/arkserver.log" + echo "$timestamp: start" >> "$logdir/$arkmanagerLog" + echo "$timestamp: restart" >> "$logdir/$arkmanagerLog" ;; install) doInstall From 9c633d045a97b8c0339a4bb56626789e343b2a5c Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Wed, 24 Jun 2015 18:08:59 +0200 Subject: [PATCH 02/50] added Contributors line instead of putting them together with maintainers --- tools/arkmanager | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index ebb5469..c350fe7 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -3,7 +3,8 @@ # ARK: survival evolved manager # # Original author: LeXaT -# Maintainer: FezVrasta, Sispheor +# Maintainer: FezVrasta +# Contributors: Sispheor, Atriusftw, lexat, puseidr # Check the user is not currently running this script as root if [ "$(id -u)" == "0" ]; then From 446147982f2a24e5f1a0a59c4aa495ef9dda1b98 Mon Sep 17 00:00:00 2001 From: Sispheor Date: Wed, 24 Jun 2015 20:28:38 +0200 Subject: [PATCH 03/50] add systemd unit file and update install to use it --- tools/install.sh | 25 ++++++++++++++++++------- tools/systemd/arkdeamon.service | 11 +++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) mode change 100644 => 100755 tools/install.sh create mode 100644 tools/systemd/arkdeamon.service diff --git a/tools/install.sh b/tools/install.sh old mode 100644 new mode 100755 index ec1f5ea..102f804 --- a/tools/install.sh +++ b/tools/install.sh @@ -9,14 +9,22 @@ if [ ! -z "$1" ]; then # Copy arkdaemon to /etc/init.d ,set permissions and add it to boot if [ -f /lib/lsb/init-functions ]; then - cp lsb/arkdaemon "${INSTALL_ROOT}/etc/init.d/arkmanager" - chmod +x "${INSTALL_ROOT}/etc/init.d/arkmanager" - sed -i "s|^DAEMON=\"/usr|DAEMON=\"${EXECPREFIX}|" "${INSTALL_ROOT}/etc/init.d/arkmanager" - # add to startup if the system use sysinit - if [ -x /usr/sbin/update-rc.d -a -z "${INSTALL_ROOT}" ]; then - update-rc.d arkmanager defaults + # on debian 8, sysvinit and systemd are present. If systemd is available we use it instead of sysvinit + if [[ -f /etc/systemd/system.conf ]]; then # used by systemd + cp systemd/arkdeamon.service /etc/systemd/system/arkdaemon.service + systemctl enable arkdeamon.service echo "Ark server will now start on boot, if you want to remove this feature run the following line" - echo "update-rc.d -f arkmanager remove" + echo "systemctl disable unit" + else # systemd not present, so use sysvinit + cp lsb/arkdaemon "${INSTALL_ROOT}/etc/init.d/arkmanager" + chmod +x "${INSTALL_ROOT}/etc/init.d/arkmanager" + sed -i "s|^DAEMON=\"/usr|DAEMON=\"${EXECPREFIX}|" "${INSTALL_ROOT}/etc/init.d/arkmanager" + # add to startup if the system use sysinit + if [ -x /usr/sbin/update-rc.d -a -z "${INSTALL_ROOT}" ]; then + update-rc.d arkmanager defaults + echo "Ark server will now start on boot, if you want to remove this feature run the following line" + echo "update-rc.d -f arkmanager remove" + fi fi elif [ -f /etc/rc.d/init.d/functions ]; then cp redhat/arkdaemon "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" @@ -36,6 +44,9 @@ if [ ! -z "$1" ]; then echo "Ark server will now start on boot, if you want to remove this feature run the following line" echo "rc-update del arkmanager default" fi + elif [[ /etc/systemd/system.conf ]]; then # used by systemd + cp systemd/arkdeamon.service /etc/systemd/system/arkdaemon.service + systemctl enable arkdeamon.service fi # Create a folder in /var/log to let Ark tools write its own log files diff --git a/tools/systemd/arkdeamon.service b/tools/systemd/arkdeamon.service new file mode 100644 index 0000000..3d93a01 --- /dev/null +++ b/tools/systemd/arkdeamon.service @@ -0,0 +1,11 @@ +[Unit] +Description=Daemon to start ark server +After=network.target + +[Service] +ExecStart=/etc/init.d/arkdaemon start +ExecStop=/etc/init.d/arkdaemon stop +Type=forking + +[Install] +WantedBy=multi-user.target From e26a49a8259398eaef33e5702210be002e1cf078 Mon Sep 17 00:00:00 2001 From: Sispheor Date: Wed, 24 Jun 2015 21:33:13 +0200 Subject: [PATCH 04/50] fix issue #31 and add forceupdate function --- README.md | 5 +++- tools/arkmanager | 65 ++++++++++++++++++++++++++++-------------------- tools/install.sh | 1 + 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 7b64a76..7bb845e 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,10 @@ stops ARK server restarts ARK server #### arkmanager update -manually updates ARK server +manually updates ARK server if a new version is available + +#### arkmanager forceupdate +Apply update without check the current version #### arkmanager status Get the status of the server. Show if the process is running, if the server is up and the current version number diff --git a/tools/arkmanager b/tools/arkmanager index c350fe7..b3548c5 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -41,12 +41,6 @@ arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer #--------------------- # functions #--------------------- -function testfunction(){ - if [ -z $servermail ]; then - echo "mail ok" - fi - -} # # Check if a new version is available but not apply it @@ -94,7 +88,9 @@ function isUpdateNeeded(){ # function getCurrentVersion(){ cd "$arkserverroot" - touch arkversion # If the file doesn't exist + if ! [ -f arkversion ];then + touch arkversion + fi instver=`cat "arkversion"` return $instver @@ -121,13 +117,20 @@ function isTheServerRunning(){ # # Check if the server is down and not visible in steam server list # -function isTheServerDown(){ - lsof -i |grep $ark_Port > /dev/null +# +function isTheServerUp(){ + lsof -i :"$ark_Port" > /dev/null result=$? - return $result + # In this case, the result is: + # 1 if the command fail. The port is not listenning + # 0 if the command succeed. The port is listenning + if [ $result -eq 0 ];then + return 1 + else + return 0 + fi } - # # start function # @@ -207,27 +210,31 @@ doUpdate() { cd "$arkserverroot" if isUpdateNeeded; then - # check if the server was alive before the update so we can launch it back after the update - serverWasAlive=0 - if isTheServerRunning ;then - serverWasAlive=1 - fi - doStop - cd "$steamcmdroot" - ./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid +quit - echo "$bnumber" > "$arkserverroot/arkversion" - echo "$timestamp: update to $bnumber complete" >> "$logdir/update.log" - - # we restart the server only if it was started before the update - if [ $serverWasAlive -eq 1 ]; then - doStart - fi + forceUpdate else echo "Your server is already up to date! The most recent version is ${bnumber}." echo "$timestamp: No update needed." >> "$logdir/update.log" fi; } +forceUpdate(){ + # check if the server was alive before the update so we can launch it back after the update + serverWasAlive=0 + if isTheServerRunning ;then + serverWasAlive=1 + fi + doStop + cd "$steamcmdroot" + ./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid +quit + echo "$bnumber" > "$arkserverroot/arkversion" + echo "$timestamp: update to $bnumber complete" >> "$logdir/update.log" + + # we restart the server only if it was started before the update + if [ $serverWasAlive -eq 1 ]; then + doStart + fi +} + # # Print the status of the server (running? online? version?) # @@ -238,7 +245,7 @@ printStatus(){ echo -e "$NORMAL" "Server running: " "$RED" "No" "$NORMAL" fi - if isTheServerDown ;then + if isTheServerUp ;then echo -e "$NORMAL" "Server online: " "$RED" "No" "$NORMAL" else echo -e "$NORMAL" "Server online: " "$GREEN" "Yes" "$NORMAL" @@ -273,6 +280,9 @@ case "$1" in doUpdate #testfunction ;; + forceupdate) + forceUpdate + ;; checkupdate) tput sc echo "Querying Steam database for latest version..." @@ -292,6 +302,7 @@ case "$1" in echo "restart Stops the server and then starts it" echo "install Install the ARK server files from steamcmd" echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again" + echo "forceupdate Apply update without check the current version" echo "checkupdate Check for a new ARK server version" echo "boradcast PLACEHOLDER, not supported yet" echo "status Returns the status of the current ARK server instance" diff --git a/tools/install.sh b/tools/install.sh index 102f804..d4f008f 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -12,6 +12,7 @@ if [ ! -z "$1" ]; then # on debian 8, sysvinit and systemd are present. If systemd is available we use it instead of sysvinit if [[ -f /etc/systemd/system.conf ]]; then # used by systemd cp systemd/arkdeamon.service /etc/systemd/system/arkdaemon.service + systemctl daemon-reload systemctl enable arkdeamon.service echo "Ark server will now start on boot, if you want to remove this feature run the following line" echo "systemctl disable unit" From ec83d37a560404ca30056479c962791548544b1f Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Wed, 24 Jun 2015 18:36:05 +1000 Subject: [PATCH 05/50] Parse steamcmd output and extract buildid buildid for public branch is under depots.branches.public.buildid The output from app_info_print is a line-oriented json-like structure which is easily parsed by bash. --- tools/arkmanager | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index b3548c5..4fe34f8 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -96,11 +96,35 @@ function getCurrentVersion(){ } +# +# Parse the buildid from steamcmd +# +function parseSteamAppVer(){ + local sname + while read name val; do + name="${name#\"}" + name="${name%\"}" + val="${val#\"}" + val="${val%\"}" + if [ "$name" = "}" ]; then + break + elif [ "$name" == "{" ]; then + parseSteamAppVer "${1}.${sname}" + else + if [ "$1" == ".depots.branches.public" -a "$name" == "buildid" ]; then + echo "$val" + break + fi + sname="${name}" + fi + done +} + # # Get the current available server version on steamdb # function getAvailableVersion(){ - bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_print "$appid" +quit | grep -EA 5 "^\s+\"public\"$" | grep -E "^\s+\"buildid\"\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -f3 | sed 's/^ //' | cut -c9-14` + bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamAppVer; break; fi; done` return $bnumber } From 80fd03809443cd2905834afcd3f67997712ffcb7 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Wed, 24 Jun 2015 13:20:39 +0000 Subject: [PATCH 06/50] Fix typo in init script modification --- tools/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index d4f008f..b5d97a6 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -30,7 +30,7 @@ if [ ! -z "$1" ]; then elif [ -f /etc/rc.d/init.d/functions ]; then cp redhat/arkdaemon "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" chmod +x "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" - sed -i "s@^DAEMON=\"/usr/bin@DAEMON=\"${EXECPREFIX}@" "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" + sed -i "s@^DAEMON=\"/usr@DAEMON=\"${EXECPREFIX}@" "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" if [ -x /sbin/chkconfig -a -z "${INSTALL_ROOT}" ]; then chkconfig --add arkmanager echo "Ark server will now start on boot, if you want to remove this feature run the following line" @@ -39,7 +39,7 @@ if [ ! -z "$1" ]; then elif [ -f /sbin/runscript ]; then cp openrc/arkdaemon "${INSTALL_ROOT}/etc/init.d/arkmanager" chmod +x "${INSTALL_ROOT}/etc/init.d/arkmanager" - sed -i "s@^DAEMON=\"/usr/bin@DAEMON=\"${EXECPREFIX}@" "${INSTALL_ROOT}/etc/init.d/arkmanager" + sed -i "s@^DAEMON=\"/usr@DAEMON=\"${EXECPREFIX}@" "${INSTALL_ROOT}/etc/init.d/arkmanager" if [ -x /sbin/rc-update -a -z "${INSTALL_ROOT}" ]; then rc-update add arkmanager default echo "Ark server will now start on boot, if you want to remove this feature run the following line" From f25c6af27ff1190dd6febfc633b5101f19119450 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Wed, 24 Jun 2015 13:24:46 +0000 Subject: [PATCH 07/50] Modify config user to match install user --- tools/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/install.sh b/tools/install.sh index b5d97a6..a30ec63 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -62,6 +62,7 @@ if [ ! -z "$1" ]; then else cp -n arkmanager.cfg "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" chown "$1" "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" + sed -i "s|^steamcmd_user=\"steam\"|steamcmd_user=\"$1\"|;s|\"/home/steam|\"/home/$1|" "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" fi else From 2652f5f7520172ea9148713c5691b4592e4d76f0 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Thu, 25 Jun 2015 11:58:53 +0200 Subject: [PATCH 08/50] improved output of rhel daemon --- tools/redhat/arkdaemon | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/redhat/arkdaemon b/tools/redhat/arkdaemon index be4be54..7b3c683 100755 --- a/tools/redhat/arkdaemon +++ b/tools/redhat/arkdaemon @@ -30,6 +30,10 @@ 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. @@ -38,37 +42,38 @@ test -x $DAEMON || exit 5 case "$1" in start) echo -n "Starting $NAME: " - su -s /bin/sh -c "$DAEMON start" $steamcmd_user + 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 touch /var/lock/subsys/arkdaemon - echo "OK" + echo "[" "$GREEN" " OK " "$NORMAL" "]" exit 0 else - echo "Failed" + echo "[" "$RED" " FAILED " "$NORMAL" "]" exit 1 fi ;; stop) echo -n "Stopping $NAME: " - su -s /bin/sh -c "$DAEMON stop" $steamcmd_user + 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 "Failed" + echo "[" "$RED" " FAILED " "$NORMAL" "]" exit 1 else - echo "OK" + echo "[" "$GREEN" " OK " "$NORMAL" "]" rm -f /var/lock/subsys/arkdaemon exit 0 fi ;; restart) - su -s /bin/sh -c "$DAEMON restart" $steamcmd_user - exit 0 + echo -n "Restarting $NAME: " + su -s /bin/sh -c "$DAEMON restart" $steamcmd_user > /dev/null + echo "OK" ;; status) From 201c8879d6fbf8e777767bfee806a4fa5bb636a5 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Thu, 25 Jun 2015 12:56:07 +0200 Subject: [PATCH 09/50] added upgrade command, added support for release channels --- .version | 1 + netinstall.sh | 12 +++++++----- tools/arkmanager | 20 ++++++++++++++++++-- tools/arkmanager.cfg | 3 +++ 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 .version diff --git a/.version b/.version new file mode 100644 index 0000000..ea710ab --- /dev/null +++ b/.version @@ -0,0 +1 @@ +1.2 \ No newline at end of file diff --git a/netinstall.sh b/netinstall.sh index b0907c3..e373191 100644 --- a/netinstall.sh +++ b/netinstall.sh @@ -4,21 +4,23 @@ # Net Installer, used with curl # +channel=${2:-master} # if defined by 2nd argument install the defined version, otherwise install master + # Download and untar installation files cd /tmp -wget https://github.com/FezVrasta/ark-server-tools/archive/master.tar.gz -tar -zxvf master.tar.gz +wget https://github.com/FezVrasta/ark-server-tools/archive/${channel}.tar.gz +tar -zxvf ${channel}.tar.gz # Install ARK Server Tools -cd ark-server-tools-master/tools +cd ark-server-tools-${channel}/tools chmod +x install.sh sh install.sh $1 > /dev/null status=$? # Remove the installation files -rm -f master.tar.gz -rm -rf /tmp/ark-server-tools-master +rm -f ${channel}.tar.gz +rm -rf /tmp/ark-server-tools-${channel} # Print messages case "$status" in diff --git a/tools/arkmanager b/tools/arkmanager index 4fe34f8..9bbfd2c 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -318,8 +318,23 @@ case "$1" in status) printStatus ;; + upgrade) + echo "arkmanager v${arkstVersion}: Checking for updates... + arkstLatestVersion=`curl -s https://raw.githubusercontent.com/FezVrasta/ark-server-tools/${arkstChannel}/.version` + if [ $arkstLatestVersion -gt $arkstVersion ]; then + read -p "A new version was found! Do you want to upgrade ARK Server Tools to v${$arkstLatestVersion}?" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + curl -s https://raw.githubusercontent.com/FezVrasta/ark-server-tools/${arkstChannel}/netinstall.sh | sudo bash -s ${steamcmd_user} ${arkstChannel} + else + exit 0 + fi + else + echo "Your ARK server tools are already up to date" + fi + ;; -h|--help) - echo -e "Usage: arkmanager [OPTION]\n" + echo -e "Usage: arkmanager[OPTION]\n" echo "Option Description" echo "start Starts the server" echo "stop Stops the server" @@ -330,9 +345,10 @@ case "$1" in echo "checkupdate Check for a new ARK server version" echo "boradcast PLACEHOLDER, not supported yet" echo "status Returns the status of the current ARK server instance" + echo "upgrade Check for a new ARK Server Tools version and upgrades it if needed" ;; *) - echo "arkmanager: no command specified" + echo "arkmanager v${arkstVersion}: no command specified" echo "Try 'arkmanager -h' or 'arkmanager --help' for more information." ;; esac diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index b0571d1..3e7ce29 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -1,3 +1,6 @@ +arkstVersion="1.2" # used to print the version when needed and to check for updates +arkstChannel="master" # change it to a different branch to get non-stable versions + # config SteamCMD steamcmdroot="/home/steam/steamcmd" # path of your steamcmd instance steamcmdexec="steamcmd.sh" # name of steamcmd executable From 9f2ecc847b6f6e6e24ad9f3a2c76eafd0e3d9bd0 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Thu, 25 Jun 2015 13:04:13 +0200 Subject: [PATCH 10/50] added to readme new upgrade command --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7bb845e..62f66ea 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,9 @@ Get the status of the server. Show if the process is running, if the server is u #### arkmanager checkupdate Check if a new version of the server is available but not apply it +#### arkmanager upgrade +Check for a new ARK Server Tools version and upgrades it if needed + ## Credits Original author of arkmanager: LeXaT From 0066063c2d4c770a256f9762558249f751849664 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Thu, 25 Jun 2015 13:19:26 +0200 Subject: [PATCH 11/50] fixed doUpgrade --- tools/arkmanager | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 9bbfd2c..089c753 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -279,6 +279,22 @@ printStatus(){ } +doUpgrade() { + echo "arkmanager v${arkstVersion}: Checking for updates..." + arkstLatestVersion=`curl -s https://raw.githubusercontent.com/FezVrasta/ark-server-tools/${arkstChannel}/.version` + if [[ $arkstLatestVersion > $arkstVersion ]]; then + read -p "A new version was found! Do you want to upgrade ARK Server Tools to v${$arkstLatestVersion}?" -n 1 -r + echo -en "/n" + if [[ $REPLY =~ ^[Yy]$ ]]; then + curl -s https://raw.githubusercontent.com/FezVrasta/ark-server-tools/${arkstChannel}/netinstall.sh | sudo bash -s ${steamcmd_user} ${arkstChannel} + else + exit 0 + fi + else + echo "Your ARK server tools are already up to date" + fi +} + #--------------------- # Main program #--------------------- @@ -319,19 +335,7 @@ case "$1" in printStatus ;; upgrade) - echo "arkmanager v${arkstVersion}: Checking for updates... - arkstLatestVersion=`curl -s https://raw.githubusercontent.com/FezVrasta/ark-server-tools/${arkstChannel}/.version` - if [ $arkstLatestVersion -gt $arkstVersion ]; then - read -p "A new version was found! Do you want to upgrade ARK Server Tools to v${$arkstLatestVersion}?" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - curl -s https://raw.githubusercontent.com/FezVrasta/ark-server-tools/${arkstChannel}/netinstall.sh | sudo bash -s ${steamcmd_user} ${arkstChannel} - else - exit 0 - fi - else - echo "Your ARK server tools are already up to date" - fi + doUpgrade ;; -h|--help) echo -e "Usage: arkmanager[OPTION]\n" From 10a6b213123c70549c322e89ef4bec4d99020ed9 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Thu, 25 Jun 2015 15:37:36 +0200 Subject: [PATCH 12/50] use ulimit -n instead of change the limits globally --- README.md | 20 +------------------- tools/arkmanager | 3 +++ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 62f66ea..218a89b 100644 --- a/README.md +++ b/README.md @@ -10,25 +10,7 @@ We assume you have created the `steam` user to store steamcmd and your ARK serve ## Requirements -### Increase max open files - -Edit /etc/sysctl.conf and set: -``` -fs.file-max=100000 -``` -Edit /etc/security/limits.conf and set these limits: -``` -* soft nofile 100000 -* hard nofile 100000 -``` -Add the following line to `/etc/pam.d/common-session` (Debian/Ubuntu) or `/etc/pam.d/system-auth` (RHEL/CentOS/Fedora): -``` -session required pam_limits.so -``` - -After these edits, you'll need to restart your bash session or reconnect to your SSH shell to make the changes effective. - -### Open firewall ports +To allow your ARK server to communicate with the outside you have to open some ports in your firewall: ```sh iptables -I INPUT -p udp --dport 27016 -j ACCEPT diff --git a/tools/arkmanager b/tools/arkmanager index 089c753..99e737d 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -34,6 +34,7 @@ timestamp=$( date +%T ) GREEN="\\033[1;32m" RED="\\033[1;31m" NORMAL="\\033[0;39m" +maxOpenFiles=100000 arkmanagerLog="arkmanager.log" # here are logged the actions performed by arkmanager arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer @@ -187,6 +188,8 @@ doStart() { arkserveropts="${arkserveropts}?listen" # run the server in background echo "$timestamp: start" >> "$logdir/$arkserverLog" + # set max open files limit before we start the server + ulimit -n $maxOpenFiles nohup "$arkserverroot/$arkserverexec" "$arkserveropts" "$logdir/$arkserverLog" 2>&1 & # output of this command is logged echo "$timestamp: start" >> "$logdir/$arkmanagerLog" tput rc; tput ed; From ae5de315e99cf57f71630ba297b8b19f2e0fcdb5 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 25 Jun 2015 20:29:00 +1000 Subject: [PATCH 13/50] Copy Debian init script to /usr/libexec/arkmanager --- tools/install.sh | 7 +++++-- tools/systemd/arkdeamon.service | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index a30ec63..d2d8933 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -11,11 +11,14 @@ if [ ! -z "$1" ]; then if [ -f /lib/lsb/init-functions ]; then # on debian 8, sysvinit and systemd are present. If systemd is available we use it instead of sysvinit if [[ -f /etc/systemd/system.conf ]]; then # used by systemd + mkdir -p "/usr/libexec/arkmanager" + cp lsb/arkdaemon "/usr/libexec/arkmanager/arkmanager.init" + chmod +x "/usr/libexec/arkmanager/arkmanager.init" cp systemd/arkdeamon.service /etc/systemd/system/arkdaemon.service systemctl daemon-reload - systemctl enable arkdeamon.service + systemctl enable arkdaemon.service echo "Ark server will now start on boot, if you want to remove this feature run the following line" - echo "systemctl disable unit" + echo "systemctl disable arkmanager.service" else # systemd not present, so use sysvinit cp lsb/arkdaemon "${INSTALL_ROOT}/etc/init.d/arkmanager" chmod +x "${INSTALL_ROOT}/etc/init.d/arkmanager" diff --git a/tools/systemd/arkdeamon.service b/tools/systemd/arkdeamon.service index 3d93a01..fd67b61 100644 --- a/tools/systemd/arkdeamon.service +++ b/tools/systemd/arkdeamon.service @@ -3,8 +3,8 @@ Description=Daemon to start ark server After=network.target [Service] -ExecStart=/etc/init.d/arkdaemon start -ExecStop=/etc/init.d/arkdaemon stop +ExecStart=/usr/libexec/arkmanager/arkmanager.init start +ExecStop=/usr/libexec/arkmanager/arkmanager.init stop Type=forking [Install] From 180c51569eb9c302304cd379ac3c1e08825eea4b Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 25 Jun 2015 20:45:52 +1000 Subject: [PATCH 14/50] Rename arkdaemon.service to arkmanager.service --- tools/install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index d2d8933..836436f 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -14,9 +14,9 @@ if [ ! -z "$1" ]; then mkdir -p "/usr/libexec/arkmanager" cp lsb/arkdaemon "/usr/libexec/arkmanager/arkmanager.init" chmod +x "/usr/libexec/arkmanager/arkmanager.init" - cp systemd/arkdeamon.service /etc/systemd/system/arkdaemon.service + cp systemd/arkdeamon.service /etc/systemd/system/arkmanager.service systemctl daemon-reload - systemctl enable arkdaemon.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 "systemctl disable arkmanager.service" else # systemd not present, so use sysvinit @@ -49,8 +49,8 @@ if [ ! -z "$1" ]; then echo "rc-update del arkmanager default" fi elif [[ /etc/systemd/system.conf ]]; then # used by systemd - cp systemd/arkdeamon.service /etc/systemd/system/arkdaemon.service - systemctl enable arkdeamon.service + cp systemd/arkdeamon.service /etc/systemd/system/arkmanager.service + systemctl enable arkmanager.service fi # Create a folder in /var/log to let Ark tools write its own log files From d73078115cbe62296fe7224c85b4b9af306f474a Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 25 Jun 2015 21:02:22 +1000 Subject: [PATCH 15/50] Add RedHat systemd unit --- tools/install.sh | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 836436f..87dcf23 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -31,13 +31,25 @@ if [ ! -z "$1" ]; then fi fi elif [ -f /etc/rc.d/init.d/functions ]; then - cp redhat/arkdaemon "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" - chmod +x "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" - sed -i "s@^DAEMON=\"/usr@DAEMON=\"${EXECPREFIX}@" "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" - if [ -x /sbin/chkconfig -a -z "${INSTALL_ROOT}" ]; then - chkconfig --add arkmanager + # on RHEL 7, sysvinit and systemd are present. If systemd is available we use it instead of sysvinit + if [[ -f /etc/systemd/system.conf ]]; then # used by systemd + mkdir -p "/usr/libexec/arkmanager" + cp redhat/arkdaemon "/usr/libexec/arkmanager/arkmanager.init" + chmod +x "/usr/libexec/arkmanager/arkmanager.init" + cp systemd/arkdeamon.service /etc/systemd/system/arkmanager.service + systemctl daemon-reload + systemctl enable arkmanager.service echo "Ark server will now start on boot, if you want to remove this feature run the following line" - echo "chkconfig arkmanager off" + echo "systemctl disable arkmanager.service" + else # systemd not preset, so use sysvinit + cp redhat/arkdaemon "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" + chmod +x "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" + sed -i "s@^DAEMON=\"/usr@DAEMON=\"${EXECPREFIX}@" "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" + if [ -x /sbin/chkconfig -a -z "${INSTALL_ROOT}" ]; then + chkconfig --add arkmanager + echo "Ark server will now start on boot, if you want to remove this feature run the following line" + echo "chkconfig arkmanager off" + fi fi elif [ -f /sbin/runscript ]; then cp openrc/arkdaemon "${INSTALL_ROOT}/etc/init.d/arkmanager" From 651568163896a584cc0f26b5801f36d9a5e8a553 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 25 Jun 2015 21:07:58 +1000 Subject: [PATCH 16/50] Add distro-agnostic systemd init script --- tools/install.sh | 5 +++ tools/systemd/arkdaemon.init | 86 ++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100755 tools/systemd/arkdaemon.init diff --git a/tools/install.sh b/tools/install.sh index 87dcf23..2cb6be6 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -61,8 +61,13 @@ if [ ! -z "$1" ]; then echo "rc-update del arkmanager default" fi elif [[ /etc/systemd/system.conf ]]; then # used by systemd + mkdir -p /usr/libexec/arkmanager + cp systemd/arkdaemon.init "/usr/libexec/arkmanager/arkmanager.init" + chmod +x "/usr/libexec/arkmanager/arkmanager.init" cp systemd/arkdeamon.service /etc/systemd/system/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 "systemctl disable arkmanager.service" fi # Create a folder in /var/log to let Ark tools write its own log files diff --git a/tools/systemd/arkdaemon.init b/tools/systemd/arkdaemon.init new file mode 100755 index 0000000..6faa93e --- /dev/null +++ b/tools/systemd/arkdaemon.init @@ -0,0 +1,86 @@ +#!/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: " + 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: " + 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 From 70ab07a07120b9f8d33e935c1b598bb92e9dba6a Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 25 Jun 2015 21:22:46 +1000 Subject: [PATCH 17/50] Use INSTALL_ROOT and EXECPREFIX for systemd --- tools/install.sh | 61 +++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 2cb6be6..0797ec2 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -10,15 +10,18 @@ if [ ! -z "$1" ]; then # Copy arkdaemon to /etc/init.d ,set permissions and add it to boot if [ -f /lib/lsb/init-functions ]; then # on debian 8, sysvinit and systemd are present. If systemd is available we use it instead of sysvinit - if [[ -f /etc/systemd/system.conf ]]; then # used by systemd - mkdir -p "/usr/libexec/arkmanager" - cp lsb/arkdaemon "/usr/libexec/arkmanager/arkmanager.init" - chmod +x "/usr/libexec/arkmanager/arkmanager.init" - cp systemd/arkdeamon.service /etc/systemd/system/arkmanager.service - systemctl daemon-reload - systemctl enable arkmanager.service - echo "Ark server will now start on boot, if you want to remove this feature run the following line" - echo "systemctl disable arkmanager.service" + if [ -f /etc/systemd/system.conf ]; then # used by systemd + mkdir -p "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager" + cp lsb/arkdaemon "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" + chmod +x "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" + cp systemd/arkdeamon.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" + sed -i "s|=\"/usr/|=\"${EXECPREFIX}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" + if [ -z "${INSTALL_ROOT}" ]; then + systemctl daemon-reload + systemctl enable arkmanager.service + echo "Ark server will now start on boot, if you want to remove this feature run the following line" + echo "systemctl disable arkmanager.service" + fi else # systemd not present, so use sysvinit cp lsb/arkdaemon "${INSTALL_ROOT}/etc/init.d/arkmanager" chmod +x "${INSTALL_ROOT}/etc/init.d/arkmanager" @@ -32,15 +35,18 @@ if [ ! -z "$1" ]; then fi elif [ -f /etc/rc.d/init.d/functions ]; then # on RHEL 7, sysvinit and systemd are present. If systemd is available we use it instead of sysvinit - if [[ -f /etc/systemd/system.conf ]]; then # used by systemd - mkdir -p "/usr/libexec/arkmanager" - cp redhat/arkdaemon "/usr/libexec/arkmanager/arkmanager.init" - chmod +x "/usr/libexec/arkmanager/arkmanager.init" - cp systemd/arkdeamon.service /etc/systemd/system/arkmanager.service - systemctl daemon-reload - systemctl enable arkmanager.service - echo "Ark server will now start on boot, if you want to remove this feature run the following line" - echo "systemctl disable arkmanager.service" + if [ -f /etc/systemd/system.conf ]; then # used by systemd + mkdir -p "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager" + cp redhat/arkdaemon "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" + chmod +x "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" + cp systemd/arkdeamon.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" + sed -i "s|=\"/usr/|=\"${EXECPREFIX}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" + if [ -z "${INSTALL_ROOT}" ]; then + systemctl daemon-reload + systemctl enable arkmanager.service + echo "Ark server will now start on boot, if you want to remove this feature run the following line" + echo "systemctl disable arkmanager.service" + fi else # systemd not preset, so use sysvinit cp redhat/arkdaemon "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" chmod +x "${INSTALL_ROOT}/etc/rc.d/init.d/arkmanager" @@ -60,14 +66,17 @@ if [ ! -z "$1" ]; then echo "Ark server will now start on boot, if you want to remove this feature run the following line" echo "rc-update del arkmanager default" fi - elif [[ /etc/systemd/system.conf ]]; then # used by systemd - mkdir -p /usr/libexec/arkmanager - cp systemd/arkdaemon.init "/usr/libexec/arkmanager/arkmanager.init" - chmod +x "/usr/libexec/arkmanager/arkmanager.init" - cp systemd/arkdeamon.service /etc/systemd/system/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 "systemctl disable arkmanager.service" + elif [ -f /etc/systemd/system.conf ]; then # used by systemd + mkdir -p "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager" + cp systemd/arkdaemon.init "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" + chmod +x "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" + cp systemd/arkdeamon.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" + sed -i "s|=\"/usr/|=\"${EXECPREFIX}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" + if [ -z "${INSTALL_ROOT}" ]; then + systemctl enable arkmanager.service + echo "Ark server will now start on boot, if you want to remove this feature run the following line" + echo "systemctl disable arkmanager.service" + fi fi # Create a folder in /var/log to let Ark tools write its own log files From a460fdffcee52b8b5061c8900ae2c9facaa24a27 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 25 Jun 2015 21:35:42 +1000 Subject: [PATCH 18/50] Add pidfile support --- tools/lsb/arkdaemon | 2 ++ tools/redhat/arkdaemon | 8 +++++--- tools/systemd/arkdeamon.service | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/lsb/arkdaemon b/tools/lsb/arkdaemon index a4fae1f..ad802c3 100755 --- a/tools/lsb/arkdaemon +++ b/tools/lsb/arkdaemon @@ -32,6 +32,7 @@ case "$1" in sleep 5 PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` if [ -n "$PID" ]; then + echo "$PID" >/var/run/arkmanager.pid log_end_msg 0 else log_end_msg 1 @@ -46,6 +47,7 @@ case "$1" in if [ -n "$PID" ]; then log_end_msg 1 else + rm /var/run/arkmanager.pid log_end_msg 0 fi ;; diff --git a/tools/redhat/arkdaemon b/tools/redhat/arkdaemon index 7b3c683..e51925c 100755 --- a/tools/redhat/arkdaemon +++ b/tools/redhat/arkdaemon @@ -1,6 +1,6 @@ #!/bin/bash # -# /etc/rc.d/init.d/arkdaemon +# /etc/rc.d/init.d/arkmanager # # ARK manager daemon # @@ -46,7 +46,8 @@ case "$1" in sleep 5 PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` if [ -n "$PID" ]; then - touch /var/lock/subsys/arkdaemon + echo "${PID}" >/var/run/arkmanager.pid + touch /var/lock/subsys/arkmanager echo "[" "$GREEN" " OK " "$NORMAL" "]" exit 0 else @@ -65,7 +66,8 @@ case "$1" in exit 1 else echo "[" "$GREEN" " OK " "$NORMAL" "]" - rm -f /var/lock/subsys/arkdaemon + rm -f /var/lock/subsys/arkmanager + rm -f /var/run/arkmanager.pid exit 0 fi ;; diff --git a/tools/systemd/arkdeamon.service b/tools/systemd/arkdeamon.service index fd67b61..d1fb5da 100644 --- a/tools/systemd/arkdeamon.service +++ b/tools/systemd/arkdeamon.service @@ -6,6 +6,7 @@ After=network.target ExecStart=/usr/libexec/arkmanager/arkmanager.init start ExecStop=/usr/libexec/arkmanager/arkmanager.init stop Type=forking +PIDFile=/var/run/arkmanager.pid [Install] WantedBy=multi-user.target From abd1e3ab31475a78e809f833a70010c78f62ff6b Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 25 Jun 2015 21:37:27 +1000 Subject: [PATCH 19/50] Fix EXECPREFIX modification in systemd install --- tools/install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 0797ec2..420aba1 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -15,7 +15,7 @@ if [ ! -z "$1" ]; then cp lsb/arkdaemon "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" chmod +x "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" cp systemd/arkdeamon.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" - sed -i "s|=\"/usr/|=\"${EXECPREFIX}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" + sed -i "s|=/usr/|=${EXECPREFIX}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" if [ -z "${INSTALL_ROOT}" ]; then systemctl daemon-reload systemctl enable arkmanager.service @@ -40,7 +40,7 @@ if [ ! -z "$1" ]; then cp redhat/arkdaemon "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" chmod +x "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" cp systemd/arkdeamon.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" - sed -i "s|=\"/usr/|=\"${EXECPREFIX}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" + sed -i "s|=/usr/|=${EXECPREFIX}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" if [ -z "${INSTALL_ROOT}" ]; then systemctl daemon-reload systemctl enable arkmanager.service @@ -71,7 +71,7 @@ if [ ! -z "$1" ]; then cp systemd/arkdaemon.init "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" chmod +x "${INSTALL_ROOT}${EXECPREFIX}/libexec/arkmanager/arkmanager.init" cp systemd/arkdeamon.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" - sed -i "s|=\"/usr/|=\"${EXECPREFIX}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" + sed -i "s|=/usr/|=${EXECPREFIX}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" if [ -z "${INSTALL_ROOT}" ]; then systemctl enable arkmanager.service echo "Ark server will now start on boot, if you want to remove this feature run the following line" From ad9a1a45875fed14e9a196d49cd664dfbdad44f4 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Thu, 25 Jun 2015 17:29:44 +0200 Subject: [PATCH 20/50] fixed forceUpdate function --- tools/arkmanager | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 99e737d..d3e270e 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -253,8 +253,10 @@ forceUpdate(){ doStop cd "$steamcmdroot" ./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid +quit - echo "$bnumber" > "$arkserverroot/arkversion" - echo "$timestamp: update to $bnumber complete" >> "$logdir/update.log" + # the current version should be the last version. We set our version + getAvailableVersion + setCurrentVersion + echo "$timestamp: update to $instver complete" >> "$logdir/update.log" # we restart the server only if it was started before the update if [ $serverWasAlive -eq 1 ]; then From 95510e0fa0e82b96837966c65b76b48595cc27f4 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 26 Jun 2015 12:54:12 +1000 Subject: [PATCH 21/50] Get current version from appmanifest_${appid}.acf forceUpdate had a window of time between initiating the update and getting the current version where it could miss an update. Close that window by getting the installed version from the appmanifest file. --- tools/arkmanager | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index d3e270e..ebc788e 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -85,22 +85,12 @@ function isUpdateNeeded(){ } # -# Return the current version number +# Parse an ACF structure +# $1 is the desired path +# $2 is the desired property +# $3 is the current path # -function getCurrentVersion(){ - cd "$arkserverroot" - if ! [ -f arkversion ];then - touch arkversion - fi - instver=`cat "arkversion"` - return $instver - -} - -# -# Parse the buildid from steamcmd -# -function parseSteamAppVer(){ +function parseSteamACF(){ local sname while read name val; do name="${name#\"}" @@ -110,9 +100,9 @@ function parseSteamAppVer(){ if [ "$name" = "}" ]; then break elif [ "$name" == "{" ]; then - parseSteamAppVer "${1}.${sname}" + parseSteamACF "$1" "$2" "${3}.${sname}" else - if [ "$1" == ".depots.branches.public" -a "$name" == "buildid" ]; then + if [ "$3" == "$1" -a "$name" == "$2" ]; then echo "$val" break fi @@ -121,11 +111,23 @@ function parseSteamAppVer(){ done } +# +# Return the current version number +# +function getCurrentVersion(){ + if [ -f "${arkserverroot}/steamapps/appmanifest_${appid}.acf" ]; then + instver=`while read name val; do if [ "${name}" == "{" ]; then parseSteamACF "" "buildid"; break; fi; done <"${arkserverroot}/steamapps/appmanifest_${appid}.acf"` + else + instver="" + fi + return $instver +} + # # Get the current available server version on steamdb # function getAvailableVersion(){ - bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamAppVer; break; fi; done` + bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamACF ".depots.branches.public" "buildid"; break; fi; done` return $bnumber } From 1bc75d61d17b02ad8ba6fbffcef2d8581da26a7e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 26 Jun 2015 16:34:30 +1000 Subject: [PATCH 22/50] Add app_info_update --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index ebc788e..b1a9540 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -127,7 +127,7 @@ function getCurrentVersion(){ # Get the current available server version on steamdb # function getAvailableVersion(){ - bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamACF ".depots.branches.public" "buildid"; break; fi; done` + bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamACF ".depots.branches.public" "buildid"; break; fi; done` return $bnumber } From 2134f022ebc9245864295ee9b709f0ddf63fd96c Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 15:20:34 +0200 Subject: [PATCH 23/50] clear cache before fetching the available version --- tools/arkmanager | 3 ++- tools/arkmanager.cfg | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index b1a9540..1e5b978 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -127,7 +127,8 @@ function getCurrentVersion(){ # Get the current available server version on steamdb # function getAvailableVersion(){ - bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamACF ".depots.branches.public" "buildid"; break; fi; done` + rm -f $steamcmd_appinfocache + bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamAppVer; break; fi; done` return $bnumber } diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 3e7ce29..93d00a1 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -5,6 +5,7 @@ arkstChannel="master" # change it steamcmdroot="/home/steam/steamcmd" # path of your steamcmd instance steamcmdexec="steamcmd.sh" # name of steamcmd executable steamcmd_user="steam" # name of the system user who own steamcmd folder +steamcmd_appinfocache="/home/steam/Steam/appinfo.vdf" # cache of the appinfo command # config environment arkserverroot="/home/steam/ARK" # path of your ARK server files (default ~/ARK) From 4983bc329c3f3c53d0cea160c86a5979b05d1d80 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 15:22:40 +0200 Subject: [PATCH 24/50] typo --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 1e5b978..a189d5e 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -127,7 +127,7 @@ function getCurrentVersion(){ # Get the current available server version on steamdb # function getAvailableVersion(){ - rm -f $steamcmd_appinfocache + rm -f "$steamcmd_appinfocache" bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamAppVer; break; fi; done` return $bnumber } From d192bd32d7ed571a5a9efb275734d37896590a26 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 15:37:22 +0200 Subject: [PATCH 25/50] added @klightspeed as contributor --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index a189d5e..1fd8249 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -4,7 +4,7 @@ # # Original author: LeXaT # Maintainer: FezVrasta -# Contributors: Sispheor, Atriusftw, lexat, puseidr +# Contributors: Sispheor, Atriusftw, klightspeed, lexat, puseidr # Check the user is not currently running this script as root if [ "$(id -u)" == "0" ]; then From 2e65a9820419d4e385f6a76978a181f22a52aa61 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 15:38:53 +0200 Subject: [PATCH 26/50] fixed comment --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 1fd8249..a4a7157 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -143,7 +143,7 @@ function isTheServerRunning(){ } # -# Check if the server is down and not visible in steam server list +# Check if the server is up and visible in steam server list # # function isTheServerUp(){ From 2e8e7d99c740ddc7d080db13fc36f0e15e25b736 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 15:39:50 +0200 Subject: [PATCH 27/50] moved message to function --- tools/arkmanager | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index a4a7157..fb6571b 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -47,6 +47,9 @@ arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer # Check if a new version is available but not apply it # function checkForUpdate(){ + tput sc + echo "Querying Steam database for latest version..." + if isUpdateNeeded; then tput rc; tput ed; echo -e "Current version:" "$RED" $instver "$NORMAL" @@ -332,8 +335,6 @@ case "$1" in forceUpdate ;; checkupdate) - tput sc - echo "Querying Steam database for latest version..." checkForUpdate ;; broadcast) From 3f1a879de7be6f2382ba8c79499db4434a38e55f Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 15:53:58 +0200 Subject: [PATCH 28/50] fixed install command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 218a89b..76e1cb9 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ NB: Change the ports according to the ones set in your `arkmanager.cfg` file. To install ARK Server Tools run this command: ```sh -curl -s http://git.io/vtf5N | sudo bash -s steam +curl -sL http://git.io/vtf5N | sudo bash -s steam ``` NB: You may want to change the `bash -s` parameter to fit your steam user if different from `steam`. From 0c1da812b55df60810319b56cadff1b05a95706c Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 15:58:45 +0200 Subject: [PATCH 29/50] ignore cache --- netinstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netinstall.sh b/netinstall.sh index e373191..8a4989a 100644 --- a/netinstall.sh +++ b/netinstall.sh @@ -8,7 +8,7 @@ channel=${2:-master} # if defined by 2nd argument install the defined version, o # Download and untar installation files cd /tmp -wget https://github.com/FezVrasta/ark-server-tools/archive/${channel}.tar.gz +wget --no-cache https://github.com/FezVrasta/ark-server-tools/archive/${channel}.tar.gz tar -zxvf ${channel}.tar.gz # Install ARK Server Tools From bc9e9f6d1fe42b568bb0183cd3fbb66fd2ce6655 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 16:02:06 +0200 Subject: [PATCH 30/50] replaced wget with curl (and overwrite existing file if needed) --- netinstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netinstall.sh b/netinstall.sh index 8a4989a..1872701 100644 --- a/netinstall.sh +++ b/netinstall.sh @@ -8,7 +8,7 @@ channel=${2:-master} # if defined by 2nd argument install the defined version, o # Download and untar installation files cd /tmp -wget --no-cache https://github.com/FezVrasta/ark-server-tools/archive/${channel}.tar.gz +curl -s https://github.com/FezVrasta/ark-server-tools/archive/${channel}.tar.gz > ${channel}.tar.gz tar -zxvf ${channel}.tar.gz # Install ARK Server Tools From a345a84efd545bbed81376c7e6b7cba34682d7b5 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 16:08:13 +0200 Subject: [PATCH 31/50] fixed netinstaller --- netinstall.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/netinstall.sh b/netinstall.sh index 1872701..3f49478 100644 --- a/netinstall.sh +++ b/netinstall.sh @@ -8,8 +8,7 @@ channel=${2:-master} # if defined by 2nd argument install the defined version, o # Download and untar installation files cd /tmp -curl -s https://github.com/FezVrasta/ark-server-tools/archive/${channel}.tar.gz > ${channel}.tar.gz -tar -zxvf ${channel}.tar.gz +curl -L -k -s https://github.com/FezVrasta/ark-server-tools/archive/${channel}.tar.gz | tar xz # Install ARK Server Tools cd ark-server-tools-${channel}/tools @@ -19,7 +18,6 @@ sh install.sh $1 > /dev/null status=$? # Remove the installation files -rm -f ${channel}.tar.gz rm -rf /tmp/ark-server-tools-${channel} # Print messages From 74023f208a88de6ec4643ad5160a97dd87bb1399 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 16:17:38 +0200 Subject: [PATCH 32/50] fixed wrong merge --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index fb6571b..a58b920 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -131,7 +131,7 @@ function getCurrentVersion(){ # function getAvailableVersion(){ rm -f "$steamcmd_appinfocache" - bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamAppVer; break; fi; done` + bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamACF ".depots.branches.public" "buildid"; break; fi; done` return $bnumber } From a34ab5ca3c6f2a3afb8aba69b7848b3c2efbb003 Mon Sep 17 00:00:00 2001 From: Marius Linge Date: Fri, 26 Jun 2015 16:47:14 +0200 Subject: [PATCH 33/50] Corrects path to appinfo --- tools/arkmanager.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 93d00a1..07325ea 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -5,7 +5,7 @@ arkstChannel="master" # change it steamcmdroot="/home/steam/steamcmd" # path of your steamcmd instance steamcmdexec="steamcmd.sh" # name of steamcmd executable steamcmd_user="steam" # name of the system user who own steamcmd folder -steamcmd_appinfocache="/home/steam/Steam/appinfo.vdf" # cache of the appinfo command +steamcmd_appinfocache="/home/steam/Steam/appcache/appinfo.vdf" # cache of the appinfo command # config environment arkserverroot="/home/steam/ARK" # path of your ARK server files (default ~/ARK) From 296d3c361fa4ea24722d0437ed7970eb941eeb1f Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 16:08:13 +0200 Subject: [PATCH 34/50] fixed netinstaller --- netinstall.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/netinstall.sh b/netinstall.sh index 3f49478..8814143 100644 --- a/netinstall.sh +++ b/netinstall.sh @@ -17,7 +17,6 @@ sh install.sh $1 > /dev/null status=$? -# Remove the installation files rm -rf /tmp/ark-server-tools-${channel} # Print messages From 23378625bbe72b9a6016feb1376f363c56696ada Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 26 Jun 2015 19:27:59 +0200 Subject: [PATCH 35/50] added check config function --- tools/arkmanager | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index a58b920..e7b05e5 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -33,6 +33,7 @@ bnumber="" timestamp=$( date +%T ) GREEN="\\033[1;32m" RED="\\033[1;31m" +YELLOW="\\e[0;33m" NORMAL="\\033[0;39m" maxOpenFiles=100000 @@ -43,6 +44,41 @@ arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer # functions #--------------------- +# +# check configuration and report errors +# +checkConfig() { + # SteamCMD configuration + # steamcmdroot + if [ ! -d "$steamcmdroot" ] ; then + echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tYour SteamCMD root seems not valid." + fi + # steamcmdexec + if [ ! -f "$steamcmdroot/$steamcmdexec" ] ; then + echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tYour SteamCMD exec could not be found." + fi + # steamcmd_user + if [ ! getent passwd $steamcmd_user > /dev/null 2>&1 ] ; then + echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tYour SteamCMD user is not valid." + fi + + # Environment configuration + # arkserverroot + if [ ! -w `echo "$arkserverroot" | sed 's:/[^/]*$::'` ] ; then + echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tYou have not rights to write in the defined ARK server root directory" + fi + # arkserverexec + if [ ! -f "$arkserverroot/$arkserverexec" ] ; then + echo -e "[" "$YELLOW" "WARN" "$NORMAL" "]" "\tYour SteamCMD exec could not be found." + fi + + # Service configuration + # logdir + if [ ! -w "$logdir" ] ; then + echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tYou have not rights to write in the log directory." + fi +} + # # Check if a new version is available but not apply it # @@ -309,6 +345,10 @@ doUpgrade() { #--------------------- # Main program #--------------------- + +# check the configuration and throw errors or warnings if needed +checkConfig + case "$1" in start) doStart From dcbea1dfd64c485aa4e016b97e31c3bb94c7b900 Mon Sep 17 00:00:00 2001 From: Fez Vrasta Date: Sat, 27 Jun 2015 20:26:15 +0200 Subject: [PATCH 36/50] fixed statement --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 2497345..196c962 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -58,7 +58,7 @@ checkConfig() { echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tYour SteamCMD exec could not be found." fi # steamcmd_user - if [ ! getent passwd $steamcmd_user > /dev/null 2>&1 ] ; then + if ! getent passwd $steamcmd_user > /dev/null 2>&1 ; then echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tYour SteamCMD user is not valid." fi From e348278cac910d34e0415fbe9208b802ceecc887 Mon Sep 17 00:00:00 2001 From: Rodzyn Date: Sun, 28 Jun 2015 13:34:59 +0200 Subject: [PATCH 37/50] Fixed missing terminating quotation mark. --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index afdc3d2..e02ee11 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -354,7 +354,7 @@ case "$1" in echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again" echo "forceupdate Apply update without check the current version" echo "checkupdate Check for a new ARK server version" - echo "safeupdate Wait for server to perform world save and update. + echo "safeupdate Wait for server to perform world save and update." echo "boradcast PLACEHOLDER, not supported yet" echo "status Returns the status of the current ARK server instance" ;; From a6b0afda6550e2bfce6a460bf92075d2f970b66c Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 28 Jun 2015 23:32:48 +1000 Subject: [PATCH 38/50] Revert "Revert "Waiting for world save before update."" This reverts commit d7004922dd1e813de136a9086cccc4b0c9139d66. --- README.md | 3 +++ tools/arkmanager | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index fb45856..54823ac 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,9 @@ manually updates ARK server if a new version is available #### arkmanager forceupdate Apply update without check the current version +#### arkmanager safeupdate +Waits for server to perform world save and then updates. + #### arkmanager status Get the status of the server. Show if the process is running, if the server is up and the current version number diff --git a/tools/arkmanager b/tools/arkmanager index d3cea38..8a57114 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -258,6 +258,26 @@ forceUpdate(){ fi } +# +# Waits for server to perform save before update (until save file is newer than 1 minute) +# +safeUpdate(){ + cd "$arkserverroot" + + if isUpdateNeeded; then + while [ ! `find $arkserverroot/ShooterGame/Saved/SavedArks -mmin -1 -name $serverMap.ark` ]; do + echo "$timestamp: Save file older than 1 minute. Delaying update." >> "$logdir/update.log" + sleep 30s + done + echo "$timestamp: Save file newer than 1 minute. Performing an update." >> "$logdir/update.log" + forceUpdate + else + echo "Your server is already up to date! The most recent version is ${bnumber}." + echo "$timestamp: No update needed." >> "$logdir/update.log" + fi +} + + # # Print the status of the server (running? online? version?) # @@ -325,6 +345,7 @@ case "$1" in echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again" echo "forceupdate Apply update without check the current version" echo "checkupdate Check for a new ARK server version" + echo "safeupdate Wait for server to perform world save and update. echo "boradcast PLACEHOLDER, not supported yet" echo "status Returns the status of the current ARK server instance" ;; From 4b74bf3e6972a949ecd4a62e161293053ebb57b4 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 28 Jun 2015 14:20:30 +1000 Subject: [PATCH 39/50] Increase open file limits before start and restart --- tools/lsb/arkdaemon | 2 ++ tools/openrc/arkdaemon | 1 + tools/redhat/arkdaemon | 2 ++ tools/systemd/arkdaemon.init | 2 ++ 4 files changed, 7 insertions(+) diff --git a/tools/lsb/arkdaemon b/tools/lsb/arkdaemon index ad802c3..f728ede 100755 --- a/tools/lsb/arkdaemon +++ b/tools/lsb/arkdaemon @@ -28,6 +28,7 @@ test -x $DAEMON || exit 5 case "$1" in start) log_daemon_msg "Starting" "$NAME" + ulimit -n 100000 su -s /bin/sh -c "$DAEMON start" $steamcmd_user sleep 5 PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` @@ -53,6 +54,7 @@ case "$1" in ;; restart) + ulimit -n 100000 su -s /bin/sh -c "$DAEMON restart" $steamcmd_user ;; diff --git a/tools/openrc/arkdaemon b/tools/openrc/arkdaemon index 7104607..d83f94c 100644 --- a/tools/openrc/arkdaemon +++ b/tools/openrc/arkdaemon @@ -14,6 +14,7 @@ depend(){ start(){ ebegin "Starting ARK manager daemon" + ulimit -n 100000 su -s /bin/sh -c "$DAEMON start" $steamcmd_user sleep 5 PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` diff --git a/tools/redhat/arkdaemon b/tools/redhat/arkdaemon index e51925c..411bcd1 100755 --- a/tools/redhat/arkdaemon +++ b/tools/redhat/arkdaemon @@ -42,6 +42,7 @@ 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}'` @@ -74,6 +75,7 @@ case "$1" in restart) echo -n "Restarting $NAME: " + ulimit -n 100000 su -s /bin/sh -c "$DAEMON restart" $steamcmd_user > /dev/null echo "OK" ;; diff --git a/tools/systemd/arkdaemon.init b/tools/systemd/arkdaemon.init index 6faa93e..2cde2ab 100755 --- a/tools/systemd/arkdaemon.init +++ b/tools/systemd/arkdaemon.init @@ -39,6 +39,7 @@ 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}'` @@ -69,6 +70,7 @@ case "$1" in restart) echo -n "Restarting $NAME: " + ulimit -n 100000 su -s /bin/sh -c "$DAEMON restart" $steamcmd_user > /dev/null echo "OK" ;; From 9bd8973f87d5a559ac328fde22852ec846b9748d Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 28 Jun 2015 23:43:36 +1000 Subject: [PATCH 40/50] Replace timestamp variable with timestamp function --- tools/arkmanager | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 3cd0921..124ab05 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -30,7 +30,6 @@ info="" thejob="" instver="" bnumber="" -timestamp=$( date +%T ) GREEN="\\033[1;32m" RED="\\033[1;31m" YELLOW="\\e[0;33m" @@ -44,6 +43,13 @@ arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer # functions #--------------------- +# +# timestamp +# +timestamp() { + date +%T +} + # # check configuration and report errors # @@ -222,11 +228,11 @@ doStart() { arkserveropts="${arkserveropts}?listen" # run the server in background - echo "$timestamp: start" >> "$logdir/$arkserverLog" + echo "`timestamp`: start" >> "$logdir/$arkserverLog" # set max open files limit before we start the server ulimit -n $maxOpenFiles nohup "$arkserverroot/$arkserverexec" "$arkserveropts" "$logdir/$arkserverLog" 2>&1 & # output of this command is logged - echo "$timestamp: start" >> "$logdir/$arkmanagerLog" + echo "`timestamp`: start" >> "$logdir/$arkmanagerLog" tput rc; tput ed; echo "The server is now up" fi @@ -245,7 +251,7 @@ doStop() { tput rc; tput ed; echo "The server has been stopped" - echo "$timestamp: stop" >> "$logdir/$arkmanagerLog" + echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" else echo "The server is already stopped" fi @@ -274,7 +280,7 @@ doUpdate() { forceUpdate else echo "Your server is already up to date! The most recent version is ${bnumber}." - echo "$timestamp: No update needed." >> "$logdir/update.log" + echo "`timestamp`: No update needed." >> "$logdir/update.log" fi; } @@ -289,7 +295,7 @@ forceUpdate(){ ./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid +quit # the current version should be the last version. We set our version getCurrentVersion - echo "$timestamp: update to $instver complete" >> "$logdir/update.log" + echo "`timestamp`: update to $instver complete" >> "$logdir/update.log" # we restart the server only if it was started before the update if [ $serverWasAlive -eq 1 ]; then @@ -305,14 +311,14 @@ safeUpdate(){ if isUpdateNeeded; then while [ ! `find $arkserverroot/ShooterGame/Saved/SavedArks -mmin -1 -name $serverMap.ark` ]; do - echo "$timestamp: Save file older than 1 minute. Delaying update." >> "$logdir/update.log" + echo "`timestamp`: Save file older than 1 minute. Delaying update." >> "$logdir/update.log" sleep 30s done - echo "$timestamp: Save file newer than 1 minute. Performing an update." >> "$logdir/update.log" + echo "`timestamp`: Save file newer than 1 minute. Performing an update." >> "$logdir/update.log" forceUpdate else echo "Your server is already up to date! The most recent version is ${bnumber}." - echo "$timestamp: No update needed." >> "$logdir/update.log" + echo "`timestamp`: No update needed." >> "$logdir/update.log" fi } @@ -369,11 +375,11 @@ case "$1" in ;; restart) doStop - echo "$timestamp: stop" >> "$logdir/$arkmanagerLog" + echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" sleep 10 doStart - echo "$timestamp: start" >> "$logdir/$arkmanagerLog" - echo "$timestamp: restart" >> "$logdir/$arkmanagerLog" + echo "`timestamp`: start" >> "$logdir/$arkmanagerLog" + echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog" ;; install) doInstall From ac88ed1a7a5ad73e16abc1b654b9ce713d4c05c9 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 28 Jun 2015 23:45:42 +1000 Subject: [PATCH 41/50] Add doRun function; background as subprocess --- tools/arkmanager | 58 +++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 124ab05..4f93f45 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -197,6 +197,38 @@ function isTheServerUp(){ fi } +# +# run function +# +doRun() { + arkserveropts=$serverMap + + # bring in ark_... options + for varname in "${!ark_@}"; do + name="${varname#ark_}" + val="${!varname}" + + # Port is actually one higher than specified + # i.e. specifying port 7777 will have the server + # use port 7778 + if [ "$name" == "Port" ]; then + (( val = val - 1 )) + fi + + if [ -n "$val" ]; then + arkserveropts="${arkserveropts}?${name}=${val}" + fi + done + + arkserveropts="${arkserveropts}?listen" + # run the server in background + echo "`timestamp`: start" + # set max open files limit before we start the server + ulimit -n $maxOpenFiles + "$arkserverroot/$arkserverexec" "$arkserveropts" + +} + # # start function # @@ -207,31 +239,7 @@ doStart() { tput sc echo "The server is starting..." - arkserveropts=$serverMap - - # bring in ark_... options - for varname in "${!ark_@}"; do - name="${varname#ark_}" - val="${!varname}" - - # Port is actually one higher than specified - # i.e. specifying port 7777 will have the server - # use port 7778 - if [ "$name" == "Port" ]; then - (( val = val - 1 )) - fi - - if [ -n "$val" ]; then - arkserveropts="${arkserveropts}?${name}=${val}" - fi - done - - arkserveropts="${arkserveropts}?listen" - # run the server in background - echo "`timestamp`: start" >> "$logdir/$arkserverLog" - # set max open files limit before we start the server - ulimit -n $maxOpenFiles - nohup "$arkserverroot/$arkserverexec" "$arkserveropts" "$logdir/$arkserverLog" 2>&1 & # output of this command is logged + doRun >"$logdir/$arkserverLog" 2>&1 & # output of this command is logged echo "`timestamp`: start" >> "$logdir/$arkmanagerLog" tput rc; tput ed; echo "The server is now up" From a28426e4a0bfe9a9617d8bd2e38dcf6caf6a922e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 28 Jun 2015 23:48:09 +1000 Subject: [PATCH 42/50] Log server exit status --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 4f93f45..c668302 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -226,7 +226,7 @@ doRun() { # set max open files limit before we start the server ulimit -n $maxOpenFiles "$arkserverroot/$arkserverexec" "$arkserveropts" - + echo "`timestamp`: exited with status $?" } # From 404a2663d41ed943990b773a855179bdbe9a533a Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Wed, 8 Jul 2015 13:41:18 +0200 Subject: [PATCH 43/50] added intro --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f461b7c..80956fc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # ARK: Survival Evolved Linux Server Tools +This tool allows you to manage any ARK: Survival Evolved linux server without having to remember long commands. +It provides a lot of features, to get the full list check the **Commands** section on the bottom of this page. + ## Pre-requisites To install ARK Server Tools you must have already installed **SteamCMD** following this guide: From 0ea4ae47821bc9ec3165cd5fcccbeea22dc9d1ca Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Wed, 8 Jul 2015 13:43:06 +0200 Subject: [PATCH 44/50] fixed config file name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 80956fc..86ec18d 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ arkmanager install To get a complete list of the script commands you can run `arkmanager --help` or `arkmanager -h`. #### arkmanager install -installs arkmanager to the directory specified in `.arkmanager.cfg` +installs arkmanager to the directory specified in `/etc/arkmanager/arkmanager.cfg` or `~/.arkmanager.cfg`. #### arkmanager start starts ARK server From c8f8ae87f6391acc8d9d87eaf2af67851539cd44 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Wed, 8 Jul 2015 22:26:13 +1000 Subject: [PATCH 45/50] Add ark backup feature --- tools/arkmanager | 15 +++++++++++++++ tools/arkmanager.cfg | 1 + 2 files changed, 16 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index aca1188..bf40e46 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -335,6 +335,18 @@ safeUpdate(){ fi } +# +# Copies server state to a backup directory +# +doBackup(){ + local datestamp=`date +"%Y-%m-%d_%H.%M.%S"` + local backupdir="${arkbackupdir}/${datestamp}" + mkdir -p "$backupdir" + cp "${arkserverroot}/ShooterGame/Saved/SavedArks/${serverMap}.ark" "${backupdir}/${serverMap}.ark" + cp "${arkserverroot}/ShooterGame/Saved/SavedArks/"*.arkprofile "${backupdir}" + cp "${arkserverroot}/ShooterGame/Saved/SavedArks/"*.arktribe "${backupdir}" + cp "${arkserverroot}/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini" "${backupdir}" +} # # Print the status of the server (running? online? version?) @@ -407,6 +419,9 @@ case "$1" in checkupdate) checkForUpdate ;; + backup) + doBackup + ;; broadcast) doInfo $2 ;; diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 23f96d7..9fd0cf3 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -10,6 +10,7 @@ steamcmd_appinfocache="/home/steam/Steam/appcache/appinfo.vdf" # cache of t # config environment arkserverroot="/home/steam/ARK" # path of your ARK server files (default ~/ARK) arkserverexec="ShooterGame/Binaries/Linux/ShooterGameServer" # name of ARK server executable +arkbackupdir="/home/steam/ARK-Backups" # path to backup directory # ARK server options - use ark_= # comment out these values if you want to define them From d192a1fe645860022f7c0e15b4c5675ead265c47 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Wed, 8 Jul 2015 15:05:56 +0200 Subject: [PATCH 46/50] forceupdate replaced by update --force and added documentation about the new backup command --- README.md | 3 +++ tools/arkmanager | 34 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 86ec18d..a54a416 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,9 @@ Check if a new version of the server is available but not apply it #### arkmanager upgrade Check for a new ARK Server Tools version and upgrades it if needed +#### arkmanager backup +Saves a backup of your server inside the backup directory + ## Credits Original author of arkmanager: LeXaT diff --git a/tools/arkmanager b/tools/arkmanager index bf40e46..4cdc7a9 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -410,11 +410,11 @@ case "$1" in doInstall ;; update) - doUpdate - #testfunction - ;; - forceupdate) - forceUpdate + if [ "$2" == "--force" ]; then + forceUpdate + else + doUpdate + fi ;; checkupdate) checkForUpdate @@ -433,18 +433,18 @@ case "$1" in ;; -h|--help) echo -e "Usage: arkmanager[OPTION]\n" - echo "Option Description" - echo "start Starts the server" - echo "stop Stops the server" - echo "restart Stops the server and then starts it" - echo "install Install the ARK server files from steamcmd" - echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again" - echo "forceupdate Apply update without check the current version" - echo "checkupdate Check for a new ARK server version" - echo "safeupdate Wait for server to perform world save and update." - echo "boradcast PLACEHOLDER, not supported yet" - echo "status Returns the status of the current ARK server instance" - echo "upgrade Check for a new ARK Server Tools version and upgrades it if needed" + echo "Option Description" + echo "backup Saves a backup of your server inside the backup directory" + echo "checkupdate Check for a new ARK server version" + echo "install Install the ARK server files from steamcmd" + echo "restart Stops the server and then starts it" + echo "start Starts the server" + echo "stop Stops the server" + echo "safeupdate Wait for server to perform world save and update." + 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 --force Apply update without check the current version" + echo "upgrade Check for a new ARK Server Tools version and upgrades it if needed" ;; *) echo "arkmanager v${arkstVersion}: no command specified" From 6ca7625d504dac6d5b01c70ca7ab88eb8fcc1958 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Thu, 9 Jul 2015 13:49:54 +0200 Subject: [PATCH 47/50] fixed two typos --- tools/arkmanager | 2 +- tools/openrc/arkdaemon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 4cdc7a9..f811713 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -80,7 +80,7 @@ checkConfig() { fi # arkserverexec if [ ! -f "$arkserverroot/$arkserverexec" ] ; then - echo -e "[" "$YELLOW" "WARN" "$NORMAL" "]" "\tYour SteamCMD exec could not be found." + echo -e "[" "$YELLOW" "WARN" "$NORMAL" "]" "\tYour ARK server exec could not be found." fi # Service configuration diff --git a/tools/openrc/arkdaemon b/tools/openrc/arkdaemon index d83f94c..4c2ddd0 100644 --- a/tools/openrc/arkdaemon +++ b/tools/openrc/arkdaemon @@ -9,7 +9,7 @@ LOGFILE="${logdir}/${NAME}.log" DAEMON="/usr/bin/arkmanager" depend(){ - require net + need net } start(){ From 39e2c7b8d2431937e5c16b5a5f51dae2ee7dbfff Mon Sep 17 00:00:00 2001 From: Marius Linge Date: Thu, 9 Jul 2015 18:31:30 +0200 Subject: [PATCH 48/50] Adds RCON specific arguments to support the RCON Protocol --- tools/arkmanager.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 9fd0cf3..3248c56 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -16,6 +16,8 @@ arkbackupdir="/home/steam/ARK-Backups" # path to ba # comment out these values if you want to define them # inside your GameUserSettings.ini file serverMap="TheIsland" # server map (default TheIsland) +ark_RCONEnabled="True" # Enable RCON Protocol +ark_RCONPort="32330" # RCON Port ark_SessionName="ARK Server Tools" # if your session name needs special characters please use the .ini instead ark_Port="7778" # ARK server port (default 7778) ark_QueryPort="27016" # ARK query port (default 27016) From 4a1ac5af593510aca7361a6f96b7ba434401f480 Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 10 Jul 2015 13:39:04 +0200 Subject: [PATCH 49/50] fixed safeupdate fixes #104 --- tools/arkmanager | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index f811713..aff9fa8 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -319,7 +319,7 @@ forceUpdate(){ # # Waits for server to perform save before update (until save file is newer than 1 minute) # -safeUpdate(){ +doSafeUpdate(){ cd "$arkserverroot" if isUpdateNeeded; then @@ -412,7 +412,9 @@ case "$1" in update) if [ "$2" == "--force" ]; then forceUpdate - else + elif [ "$2" == "--safe" ]; then + doSafeUpdate + else; then doUpdate fi ;; @@ -440,10 +442,10 @@ case "$1" in echo "restart Stops the server and then starts it" echo "start Starts the server" echo "stop Stops the server" - echo "safeupdate Wait for server to perform world save and update." 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 --force Apply update without check the current version" + echo "update --safe Wait for server to perform world save and update." echo "upgrade Check for a new ARK Server Tools version and upgrades it if needed" ;; *) From 50d8633fed57523265b7d99372a6d629083bad3f Mon Sep 17 00:00:00 2001 From: FezVrasta Date: Fri, 10 Jul 2015 13:40:13 +0200 Subject: [PATCH 50/50] fixed typo --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index aff9fa8..c6f87fa 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -373,7 +373,7 @@ doUpgrade() { arkstLatestVersion=`curl -s https://raw.githubusercontent.com/FezVrasta/ark-server-tools/${arkstChannel}/.version` if [[ $arkstLatestVersion > $arkstVersion ]]; then read -p "A new version was found! Do you want to upgrade ARK Server Tools to v${$arkstLatestVersion}?" -n 1 -r - echo -en "/n" + echo -en "\n" if [[ $REPLY =~ ^[Yy]$ ]]; then curl -s https://raw.githubusercontent.com/FezVrasta/ark-server-tools/${arkstChannel}/netinstall.sh | sudo bash -s ${steamcmd_user} ${arkstChannel} else