diff --git a/README.md b/README.md index e15f483..dde2f6e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,11 @@ We assume you have created the `steam` user to store steamcmd and your ARK serve ## Requirements Use this command to install soft requirement on your system ``` -apt-get install screen unzip +# Debian based/ Ubuntu +apt-get install screen + +# RHEL / CentOS / Fedora +yum install screen ``` Edit /etc/sysctl.conf and set: @@ -23,27 +27,24 @@ 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: +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. + ## Install ARK Server Tools -To install ARK Server Tools run these commands: +To install ARK Server Tools run this command: ```sh -cd ~ -wget https://github.com/FezVrasta/ark-server-tools/archive/master.zip -unzip master.zip -cd ark-server-tools-master/tools -chmod u+x install.sh -sudo sh install.sh steam +curl -s https://raw.githubusercontent.com/FezVrasta/ark-server-tools/master/netinstall.sh | sudo bash -s steam ``` -NB: You may want to change the `install.sh` parameter to fit your steam user if different from `steam`. +NB: You may want to change the `bash -s` parameter to fit your steam user if different from `steam`. -This will copy the `arkmanager` and the `arkdaemon` to the proper directories and will create an empty log directory in `/var/log` for ARK Server Tools. +This will copy the `arkmanager` and the `arkdaemon` to the proper directories and will create an empty log directory in `/var/log` for ARK Server Tools. ## Configure ARK Server @@ -83,7 +84,7 @@ Check if a new version of the server is available but not apply it broadcast a message to ARK server chat ```sh -arkmanager boradcast "here your message" +arkmanager broadcast "your message here" ``` ## Credits diff --git a/netinstall.sh b/netinstall.sh new file mode 100644 index 0000000..1f5f9bd --- /dev/null +++ b/netinstall.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# +# Net Installer, used with curl +# + +# Download and untar installation files +cd /tmp +wget https://github.com/FezVrasta/ark-server-tools/archive/master.tar.gz +tar -zxvf master.tar.gz + +# Install ARK Server Tools +cd ark-server-tools-master/tools +chmod +x install.sh +sh install.sh $1 + +status = $? + +# Remove the installation files +rm -f master.tar.gz +rm -rf /tmp/ark-server-tools-master + + +if [ $status == 0 ]; then + echo "ARK Server Tools were correctly installed in your system inside the home directory of $1!" +fi + +if [ $status == 1 ]; then + echo "Something where wrong :(" +fi + +if [ $status == 2 ]; then + echo "WARNING: A previous version of ARK Server Tools was detected in your system, your old configuration was not overwritten. You may need to manually update it." + echo "ARK Server Tools were correctly installed in your system inside the home directory of $1!" +fi diff --git a/tools/arkdaemon b/tools/arkdaemon index d8e39f6..5fb27d9 100644 --- a/tools/arkdaemon +++ b/tools/arkdaemon @@ -9,6 +9,8 @@ # ### END INIT INFO +# NOTICE: this daemon can work only if your system supports start-stop-daemon + # Using the lsb functions to perform the operations. . /lib/lsb/init-functions diff --git a/tools/arkmanager b/tools/arkmanager index 3d2bda2..1fabd9f 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -14,8 +14,10 @@ fi #--------------------- # Variables #--------------------- + # Global variables source /etc/arkmanager/arkmanager.cfg + # Local variables info="" thejob="" @@ -35,10 +37,11 @@ function testfunction(){ fi } + +# +# Check if a new version is available but not apply it +# function checkForUpdate(){ - # - # Check if a new version is available but not apply it - # if isUpdateNeeded; then echo "Current version:" $instver echo "Available version:" $bnumber @@ -48,18 +51,20 @@ function checkForUpdate(){ echo "No update available" fi } + +# +# Set the new current version in a file +# function setCurrentVersion(){ - # - # set the new current version in a file - # cd $arkserverroot echo $bnumber > arkversion } + +# +# Check if the server need to be updated +# Return 0 if update is needed, else return 1 +# function isUpdateNeeded(){ - # - # Check if the server need to be updated - # Return 0 if update is needed, else return 1 - # getCurrentVersion getAvailableVersion if [ "$bnumber" -eq "$instver" ]; then @@ -69,65 +74,52 @@ function isUpdateNeeded(){ fi } + +# +# Return the current version number +# function getCurrentVersion(){ - # - # Return the current version number - # cd $arkserverroot touch arkversion # If the file doesn't exist instver=`cat "arkversion"` return $instver } + +# +# Get the current available server version on steamdb +# function getAvailableVersion(){ - # - # Get the current available server version on steamdb - # 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` return $bnumber } +# +# Check id the server process is alive +# function isTheServerRunning(){ - # - # Check id the server process is alive - # SERVICE="ShooterGameServer" ps aux | grep -v grep | grep $SERVICE > /dev/null result=$? return $result } -function IsTheServerUp(){ - # - # Check if the server is up and visible in steam server list - # If the server is listenning on his port return 0, else return 1 - # +# +# Check if the server is up and visible in steam server list +# If the server is listenning on his port return 0, else return 1 +# +function isTheServerUp(){ PORT="7779" lsof -i |grep $PORT > /dev/null result=$? return $result } -# To speedup stuff, if you have not specified a command or the command is invalid, we skip everything and just give you the usage message -case "$1" in - start);; - stop);; - restart);; - install);; - update);; - checkupdate);; - broadcast);; - status);; - *) - echo "use arkmanager " - exit 0 - ;; -esac +# +# start function +# doStart() { - # - # start function - # if isTheServerRunning; then echo "The server is already running" else @@ -135,26 +127,29 @@ doStart() { thejob="$arkserverroot/$arkserverexec $arkserveropts" screen -dmS "$servicename" $thejob echo "$timestamp: start" >> "$logdir/arkserver.log" + tail -n 1 "$logdir/arkserver.log" fi } +# +# stop the ARK server +# doStop() { - # - # stop the ARK server - # if isTheServerRunning; then + echo "Stopping server..." screen -X -S "$servicename" -X stuff "^C" sleep 30 echo "$timestamp: stop" >> "$logdir/arkserver.log" + tail -n 1 "$logdir/arkserver.log" else echo "The server is already stopped" fi } +# +# install of ARK server +# doInstall() { - # - # install of ARK server - # if [ ! -d "$arkserverroot" ]; then mkdir $arkserverroot fi @@ -166,10 +161,10 @@ doInstall() { setCurrentVersion } +# +# Stop the server, update it and then start it back. +# doUpdate() { - # - # Stop the server, update it and then start it back. - # cd $arkserverroot if isUpdateNeeded; then @@ -185,6 +180,7 @@ doUpdate() { echo "$bnumber" > "$arkserverroot/arkversion" cd $steamcmdroot echo "$timestamp: update to $bnumber complete" >> "$logdir/update.log" + tail -n 1 "$logdir/arkserver.log" # we restart the server only if it was started before the update if [ $serverWasAlive -eq 1 ]; then @@ -197,10 +193,13 @@ doUpdate() { else echo "No update available" echo "$timestamp: No update needed." >> "$logdir/update.log" + tail -n 1 "$logdir/update.log" fi; } -#broadcast info +# +# Broadcast message to server +# doInfo() { if [ ! -z $1 ]; then info=$1 @@ -208,6 +207,9 @@ doInfo() { screen -S "$servicename" -p 0 -X stuff "broadcast $info $(printf \\r)" } +# +# Print the status of the server (running? online? version?) +# printStatus(){ if isTheServerRunning ;then echo -e "$NORMAL" "Server running:" "$GREEN" "Yes" @@ -215,13 +217,14 @@ printStatus(){ echo -e "$NORMAL" "Server running:" "$RED" "No" fi - if IsTheServerUp ;then + if isTheServerUp ;then echo -e "$NORMAL" "Server online:" "$GREEN" " Yes" else echo -e "$NORMAL" "Server online:" "$RED" " No" fi getCurrentVersion echo -e "$NORMAL" "Server version:" "$GREEN" $instver + echo -e "$NORMAL" } @@ -238,10 +241,13 @@ case "$1" in restart) doStop echo "$timestamp: stop" >> "$logdir/arkserver.log" + tail -n 1 "$logdir/arkserver.log" sleep 10 doStart echo "$timestamp: start" >> "$logdir/arkserver.log" + tail -n 1 "$logdir/arkserver.log" echo "$timestamp: restart" >> "$logdir/arkserver.log" + tail -n 1 "$logdir/arkserver.log" ;; install) doInstall diff --git a/tools/install.sh b/tools/install.sh index 4e38dc8..1a02ac9 100644 --- a/tools/install.sh +++ b/tools/install.sh @@ -13,14 +13,20 @@ if [ ! -z $1 ]; then mkdir -p /var/log/arktools chown $1 /var/log/arktools - # Copy arkmanager.cfg inside linux configuation folder - mkdir /etc/arkmanager - mv arkmanager.cfg /etc/arkmanager/arkmanager.cfg - chown $1 /etc/arkmanager/arkmanager.cfg + # Copy arkmanager.cfg inside linux configuation folder if it doesn't already exists + if [ -f /etc/arkmanager/arkmanager.cfg ]; then + mkdir -p /etc/arkmanager + cp -n arkmanager.cfg /etc/arkmanager/arkmanager.cfg + chown $1 /etc/arkmanager/arkmanager.cfg + else + echo "A previous version of ARK Server Tools was detected in your system, your old configuration was not overwritten. You may need to manually update it."; + exit 2 + fi else echo "You must specify your system steam user who own steamcmd directory to install ARK Tools." echo "Usage: ./install.sh steam" + exit 1 fi exit 0