This commit is contained in:
FezVrasta 2015-06-21 11:35:56 +02:00
parent 7cdcae0804
commit cddcf4c2cb

View File

@ -14,8 +14,10 @@ fi
#--------------------- #---------------------
# Variables # Variables
#--------------------- #---------------------
# Global variables # Global variables
source /etc/arkmanager/arkmanager.cfg source /etc/arkmanager/arkmanager.cfg
# Local variables # Local variables
info="" info=""
thejob="" thejob=""
@ -35,10 +37,11 @@ function testfunction(){
fi fi
} }
#
# Check if a new version is available but not apply it
#
function checkForUpdate(){ function checkForUpdate(){
#
# Check if a new version is available but not apply it
#
if isUpdateNeeded; then if isUpdateNeeded; then
echo "Current version:" $instver echo "Current version:" $instver
echo "Available version:" $bnumber echo "Available version:" $bnumber
@ -48,18 +51,20 @@ function checkForUpdate(){
echo "No update available" echo "No update available"
fi fi
} }
#
# Set the new current version in a file
#
function setCurrentVersion(){ function setCurrentVersion(){
#
# set the new current version in a file
#
cd $arkserverroot cd $arkserverroot
echo $bnumber > arkversion echo $bnumber > arkversion
} }
#
# Check if the server need to be updated
# Return 0 if update is needed, else return 1
#
function isUpdateNeeded(){ function isUpdateNeeded(){
#
# Check if the server need to be updated
# Return 0 if update is needed, else return 1
#
getCurrentVersion getCurrentVersion
getAvailableVersion getAvailableVersion
if [ "$bnumber" -eq "$instver" ]; then if [ "$bnumber" -eq "$instver" ]; then
@ -69,65 +74,52 @@ function isUpdateNeeded(){
fi fi
} }
#
# Return the current version number
#
function getCurrentVersion(){ function getCurrentVersion(){
#
# Return the current version number
#
cd $arkserverroot cd $arkserverroot
touch arkversion # If the file doesn't exist touch arkversion # If the file doesn't exist
instver=`cat "arkversion"` instver=`cat "arkversion"`
return $instver return $instver
} }
#
# Get the current available server version on steamdb
#
function getAvailableVersion(){ 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` 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 return $bnumber
} }
#
# Check id the server process is alive
#
function isTheServerRunning(){ function isTheServerRunning(){
#
# Check id the server process is alive
#
SERVICE="ShooterGameServer" SERVICE="ShooterGameServer"
ps aux | grep -v grep | grep $SERVICE > /dev/null ps aux | grep -v grep | grep $SERVICE > /dev/null
result=$? result=$?
return $result return $result
} }
#
# 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(){ 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="7779" PORT="7779"
lsof -i |grep $PORT > /dev/null lsof -i |grep $PORT > /dev/null
result=$? result=$?
return $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 <start|stop|restart|install|update|broadcast|status|checkupdate>"
exit 0
;;
esac
#
# start function
#
doStart() { doStart() {
#
# start function
#
if isTheServerRunning; then if isTheServerRunning; then
echo "The server is already running" echo "The server is already running"
else else
@ -139,10 +131,10 @@ doStart() {
fi fi
} }
#
# stop the ARK server
#
doStop() { doStop() {
#
# stop the ARK server
#
if isTheServerRunning; then if isTheServerRunning; then
screen -X -S "$servicename" -X stuff "^C" screen -X -S "$servicename" -X stuff "^C"
sleep 30 sleep 30
@ -153,10 +145,10 @@ doStop() {
fi fi
} }
#
# install of ARK server
#
doInstall() { doInstall() {
#
# install of ARK server
#
if [ ! -d "$arkserverroot" ]; then if [ ! -d "$arkserverroot" ]; then
mkdir $arkserverroot mkdir $arkserverroot
fi fi
@ -168,10 +160,10 @@ doInstall() {
setCurrentVersion setCurrentVersion
} }
#
# Stop the server, update it and then start it back.
#
doUpdate() { doUpdate() {
#
# Stop the server, update it and then start it back.
#
cd $arkserverroot cd $arkserverroot
if isUpdateNeeded; then if isUpdateNeeded; then
@ -204,7 +196,9 @@ doUpdate() {
fi; fi;
} }
#broadcast info #
# Broadcast message to server
#
doInfo() { doInfo() {
if [ ! -z $1 ]; then if [ ! -z $1 ]; then
info=$1 info=$1
@ -212,6 +206,9 @@ doInfo() {
screen -S "$servicename" -p 0 -X stuff "broadcast $info $(printf \\r)" screen -S "$servicename" -p 0 -X stuff "broadcast $info $(printf \\r)"
} }
#
# Print the status of the server (running? online? version?)
#
printStatus(){ printStatus(){
if isTheServerRunning ;then if isTheServerRunning ;then
echo -e "$NORMAL" "Server running:" "$GREEN" "Yes" echo -e "$NORMAL" "Server running:" "$GREEN" "Yes"