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/README.md b/README.md index fb45856..a54a416 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: @@ -10,25 +13,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 @@ -82,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 @@ -99,12 +84,21 @@ 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 #### 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 + +#### arkmanager backup +Saves a backup of your server inside the backup directory + ## Credits Original author of arkmanager: LeXaT diff --git a/netinstall.sh b/netinstall.sh index ce21d88..8814143 100644 --- a/netinstall.sh +++ b/netinstall.sh @@ -4,19 +4,20 @@ # 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 -curl -L -k -s https://github.com/FezVrasta/ark-server-tools/archive/master.tar.gz | tar xz +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-master/tools +cd ark-server-tools-${channel}/tools chmod +x install.sh sh install.sh $1 > /dev/null status=$? -# Remove the installation files -rm -rf /tmp/ark-server-tools-master +rm -rf /tmp/ark-server-tools-${channel} # Print messages case "$status" in diff --git a/tools/arkmanager b/tools/arkmanager index 0129bc3..c6f87fa 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -35,10 +35,11 @@ info="" thejob="" instver="" bnumber="" -timestamp=$( date +%T ) GREEN="\\033[1;32m" RED="\\033[1;31m" +YELLOW="\\e[0;33m" 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 @@ -47,6 +48,48 @@ arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer # functions #--------------------- +# +# timestamp +# +timestamp() { + date +%T +} + +# +# 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 ARK server 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 # @@ -159,6 +202,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" + echo "`timestamp`: exited with status $?" +} + # # start function # @@ -169,32 +244,8 @@ doStart() { tput sc echo "The server is starting..." - cd "$arkserverroot" - - 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" - nohup "$arkserverroot/$arkserverexec" "$arkserveropts" "$logdir/$arkserverLog" 2>&1 & # output of this command is logged - echo "$timestamp: start" >> "$logdir/$arkmanagerLog" + 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" fi @@ -213,7 +264,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 @@ -242,7 +293,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; } @@ -257,7 +308,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 @@ -265,6 +316,38 @@ forceUpdate(){ fi } +# +# Waits for server to perform save before update (until save file is newer than 1 minute) +# +doSafeUpdate(){ + 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 +} + +# +# 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?) # @@ -285,9 +368,29 @@ 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 #--------------------- + +# check the configuration and throw errors or warnings if needed +checkConfig + case "$1" in start) doStart @@ -297,46 +400,56 @@ 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 ;; update) - doUpdate - #testfunction - ;; - forceupdate) - forceUpdate + if [ "$2" == "--force" ]; then + forceUpdate + elif [ "$2" == "--safe" ]; then + doSafeUpdate + else; then + doUpdate + fi ;; checkupdate) checkForUpdate ;; + backup) + doBackup + ;; broadcast) doInfo $2 ;; status) printStatus ;; + upgrade) + doUpgrade + ;; -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 "boradcast PLACEHOLDER, not supported yet" - echo "status Returns the status of the current ARK server instance" + echo -e "Usage: arkmanager[OPTION]\n" + 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 "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" ;; *) - 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 b888aac..3248c56 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 @@ -7,11 +10,14 @@ 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 # 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) 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..4c2ddd0 100644 --- a/tools/openrc/arkdaemon +++ b/tools/openrc/arkdaemon @@ -9,11 +9,12 @@ LOGFILE="${logdir}/${NAME}.log" DAEMON="/usr/bin/arkmanager" depend(){ - require net + need net } 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" ;;