Jump to content

Server running and scripting


theanimal

Recommended Posts

Hi
 

I'm running a Hungarian server and I've done a lot of reading and experimenting. I would like to share the result of this with you. 

 

I apologize for my English. If I do not write correctly please forgive me.

 

Unfortunately, I noticed that there is not a comprehensive description of the operation.

I have tried several ways to make the server stable. Docker, AMP and others. So far the most stable is when I installed it directly on a linux. 
Based on this: https://pzwiki.net/wiki/Dedicated_Server#Linux 

The important thing is that the game must be run as a service

 

However, if I run it natural I can't use many things that were very convenient. E.g. automatic reboot daily, writing logins and logouts to DC, etc... I started to program these.

According to the wiki description above, if you have installed the server then the files are in /home/pzuser/Zomboid. These are what we will be operating with. I'll try to guide you through so you can use the ones I've already developed.

I run the server on Ubuntu 22.0.4

If you have any feedback or ideas, please let me know... 

I am developing the scripts, I will update the changes here

 

My first task was the daily restart. Obviously this is done by crone on linux, but I didn't want to reboot the server with brute force in a barbaric way. I was afraid of losing data.

Make a restart.sh file in your home directory. 

yourname SHOULD ALWAYS BE CHANGED TO YOUR LINUX USERNAME!

 

touch /home/yourname/restarter.sh

 

restarter.sh contents: 
 

#!/bin/bash

#V0.9
#
#Todo:
#Checking stemCMD server status

#Start DateTime
date +'%Y.%m.%d %T'
echo "Start PZ server restart"

#POST request to Discord Webhook
#
# CHANGE YOUR DISCORD WEBHOOK URL
#
dc_channel="YOUR DC WEBHOOK URL"
rcon_passwd="YOUR RCON PASSWD"

#send message to discord channel function
sendDC () {
    curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"$1\"}" $dc_channel
}

sendDC "Starting restart method..."
echo "30 sec"
rcon -H localhost -p 27015 -P $rcon_passwd servermsg \"Restart after 30sec\"
sleep 20
echo "10 sec"
rcon -H localhost -p 27015 -P $rcon_passwd servermsg \"Restart after 10sec\"
sleep 5
echo "5 sec"
rcon -H localhost -p 27015 -P $rcon_passwd servermsg \"Restart after 5sec\"
sleep 5

sendDC "Status: Save and Quit"
date +'%Y.%m.%d %T'
#PZ server save and quit
rcon -H localhost -p 27015 -P $rcon_passwd quit

#TODO checking in loop 10 sleep
#wait 3m for it to expire for sure
sleep 3m
#check service status
serviceStatus=$( systemctl is-active zomboid.service )
echo "Service status: $serviceStatus";

if [ $serviceStatus == 'active' ]
then
    date +'%Y.%m.%d %T'
    echo "Server running... waiting..."
    systemctl stop zomboid.service
    echo "Server stopped after sysctl stopping!"
    sendDC "Status: Stopped"
    sleep 30
else
    date +'%Y.%m.%d %T'
    echo "Server stopped!"
    sendDC "Status: Stopped"
fi

#start service
date +'%Y.%m.%d %T'
echo "Starting"
sendDC "Status: Starting..."
systemctl start zomboid.service

#wait 3m before connecting
sleep 3m
echo "Ready"
sendDC "Status: Ready"

echo "----------";


now create a log file where the output of the script will be saved...  (don't forget to change your name)

 

touch /home/yourname/log

 

now set the script to run every day at 04:00... 
 

crontab -e


copy to the bottom of the file (don't forget to change your name)

 

0 4 * * * /home/yourname/restarter.sh >> /home/yourname/log


I will continue soon with the description of the script that monitors player logins

Edited by theanimal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...