Project Zomboid

Project Zomboid

評價次數不足
Dedicated Linux Server - Automatic Server Restart Script
由 acidicD01phin 發表
As the title says, I was after creating a working script that basically runs every X hours, and executes the following:
  • servermsg to all players about a restart x mins prior
  • quitting and restarting the server
  • wait for a minute
  • executing the start-server.sh file to start the server again
   
獎勵
加入最愛
已加入最愛
移除最愛
Intro
To schedule this script I used
crontab -e
in Linux, which is a basic task scheduler. In addition, I went the route of using Linux's screen, as you can create screens, name them, run them in the background, and shut them down. Sounds like a great solution to compartmentalising the tasks.
restart-server.sh
This is what I got:
- For restart-server.sh
#!/bin/bash screen -d -r proj_z screen -S proj_z -X stuff 'servermsg "RESTART after 1 minute."\r' sleep 55 screen -S proj_z -X stuff 'servermsg "RESTART in 5 seconds."\r' sleep 1 screen -S proj_z -X stuff 'servermsg "RESTART in 4 seconds."\r' sleep 1 screen -S proj_z -X stuff 'servermsg "RESTART in 3 seconds."\r' sleep 1 screen -S proj_z -X stuff 'servermsg "RESTART in 2 seconds."\r' sleep 1 screen -S proj_z -X stuff 'servermsg "RESTART in 1 second."\r' sleep 1 screen -S proj_z -X stuff 'servermsg "RESTART"\r' sleep 1 screen -X -S proj_z quit screen -wipe proj_z sleep 5 # restart screen -dmS proj_z sh ~/Steam/proj_z/start-server.sh
scheduling using crontab -e
- For scheduling using
crontab -e
# m h dom mon dow command */120 * * * * sh /home/steam/Zomboid/Server/restart-server.sh
(for some reason it went into a never-ending loop if I use hours for the time instead)
first server start-up
- Once you set both of those up, just launch your server using the sh file for the server start:
screen -dmS proj_z sh ~/Steam/proj_z/start-server.sh
Enjoy your auto-refreshing server.
DONE

Let me know if you have any questions, this guide assumes you already know how to setup a dedicated server. Doh.

Credits to this post [theindiestone.com] as it helped me a lot, but seems a little outdated.
2 則留言
Zigla Nauthiz 2023 年 10 月 24 日 上午 8:46 
Hi man, great guide but I have a couple of newbie questions hehe
1) In the restart-server.sh, why is that the path to start-server.sh? isnt in Zomboid/Server?
2) When scheduling, I do I have to be also in Zomboid/Server?
3) When scheduling, can I just copy paste what you shared? 120 is the hours?
4) So your user where you installed SteamCMD is called proj_z? Then I think if I replace all of those with my own (pz) should be fine right?

first time working with Linux commands so thank you for your patience :)
🅾️rder💲 2023 年 2 月 7 日 上午 5:06 
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⡶⢶⣦⡀
⠀⠀⠀⣴⡿⠟⠷⠆⣠⠋⠀⠀⠀⢸⣿
⠀⠀⠀⣿⡄⠀⠀⠀⠈⠀⠀⠀⠀⣾⡿
⠀⠀⠀⠹⣿⣦⡀⠀⠀⠀⠀⢀⣾⣿
⠀⠀⠀⠀⠈⠻⣿⣷⣦⣀⣠⣾⡿ ㅤㅤ Rated :heart_me:
⠀⠀⠀⠀⠀⠀⠀⠉⠻⢿⡿⠟