add some function to check the status of the server

This commit is contained in:
Sispheor 2015-06-21 10:02:07 +02:00 committed by FezVrasta
parent 88928da026
commit e7adfc7dac
2 changed files with 84 additions and 8 deletions

89
tools/arkmanager Normal file → Executable file
View File

@ -3,13 +3,60 @@
# ARK: survival evolved manager # ARK: survival evolved manager
# #
# Original author: LeXaT # Original author: LeXaT
# Maintainer: FezVrasta # Maintainer: FezVrasta, Sispheor
# Check the user is not currently running this script as root
if [ "$(id -u)" == "0" ]; then if [ "$(id -u)" == "0" ]; then
echo "This script must NOT be run as root" 1>&2 echo "This script must NOT be run as root" 1>&2
exit 1 exit 1
fi fi
#---------------------
# Variables
#---------------------
# Global variables
source /etc/arkmanager/arkmanager.cfg
# Local variables
info=""
thejob=""
timestamp=$( date +%T )
GREEN="\\033[1;32m"
RED="\\033[1;31m"
NORMAL="\\033[0;39m"
#---------------------
# functions
#---------------------
function getServerVersion(){
#
# Get the current available server version on steamdb
#
echo "Checking for update, this may take a while"
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`
echo "Available server version: "$bnumber
}
function isTheServerRunning(){
#
# Check id the server process is alive
#
SERVICE="ShooterGameServer"
ps -a | 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
#
PORT="7776"
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 # 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 case "$1" in
start);; start);;
@ -18,6 +65,7 @@ case "$1" in
install);; install);;
update);; update);;
broadcast);; broadcast);;
status);;
*) *)
echo "use arkmanager <start|stop|restart|install|update|broadcast>" echo "use arkmanager <start|stop|restart|install|update|broadcast>"
exit 0 exit 0
@ -67,25 +115,38 @@ doStop() {
# install function # install function
doInstall() { doInstall() {
if [ ! -d "$arkserverroot" ]; then
mkdir $arkserverroot
fi
cd $steamcmdroot cd $steamcmdroot
./$steamcmdexec +login $steamuser $steampass +force_install_dir "$arkserverroot" +app_update $appid validate +quit ./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid validate +quit
} }
# update function # update function
doUpdate() { doUpdate() {
cd $arkserverroot
touch arkversion # If the file doesn't exist
instver=`cat "arkversion"`
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`
if ["$bnumber" = "$instver"]; then
patch=0
fi
if (($patch == 1)) if (($patch == 1))
then then
if [ -f "$arkserverroot/arkupdate.timed" ] if [ -f "$arkserverroot/arkupdate.timed" ]
then then
doStop doStop
cd $steamcmdroot cd $steamcmdroot
./$steamcmdexec +login $steamuser $steampass +force_install_dir "$arkserverroot" +app_update $appid validate +quit ./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid validate +quit
cd $logdir cd $logdir
echo "$bnumber" > "$arkserverroot/arkversion" echo "$bnumber" > "$arkserverroot/arkversion"
cd $steamcmdroot cd $steamcmdroot
doStart doStart
echo "$timestamp: update to $bnumber complete" >> "$logdir/update.log" echo "$timestamp: update to $bnumber complete" >> "$logdir/update.log"
mail -a $logdir/update.log -s "Update-Log" $servermail < /dev/null if [ $servermail != "" ]; then
mail -a $logdir/update.log -s "Update-Log" $servermail < /dev/null
fi
rm "$arkserverroot/arkupdate.timed" rm "$arkserverroot/arkupdate.timed"
tail -n 1 "$logdir/update.log" tail -n 1 "$logdir/update.log"
else else
@ -107,7 +168,9 @@ doInfo() {
screen -S "$servicename" -p 0 -X stuff "broadcast $info $(printf \\r)" screen -S "$servicename" -p 0 -X stuff "broadcast $info $(printf \\r)"
} }
# parameter select #---------------------
# Main program
#---------------------
case "$1" in case "$1" in
start) start)
doStart doStart
@ -133,7 +196,21 @@ case "$1" in
broadcast) broadcast)
doInfo $2 doInfo $2
;; ;;
status)
if isTheServerRunning ;then
echo -e "$NORMAL" "Server running:" "$GREEN" "Yes"
else
echo -e "$NORMAL" "Server running:" "$RED" "No"
fi
if IsTheServerUp ;then
echo -e "$NORMAL" "Server online:" "$GREEN" " Yes"
else
echo -e "$NORMAL" "Server online:" "$RED" " No"
fi
#getServerVersion
;;
*) *)
echo "use arkmanager <start|stop|restart|install|update|broadcast>" echo "use arkmanager <start|stop|restart|install|update|broadcast|status>"
;; ;;
esac esac

View File

@ -18,5 +18,4 @@ logdir="/var/log/arktools" # Logs path
appid=376030 # Linux server App ID appid=376030 # Linux server App ID
# admin information # admin information
notify_update_by_email=0 # if you want to receive a mail on each update (SMTP client must be configured) servermail="" # Log email, leave blank if you dont want to receive mail
servermail=mail@domain.com # Log email