Jump to content

[Ubuntu/Linux] Restart Script with Countdown Announcement


HellCap

Recommended Posts

In this Script Installation, we’ll be using Ubuntu 12.04, but outside of the installation process, everything should be the same on every modern distribution.

 

To get the Script running you need the Screen Console installed.

 

Use “apt-get” to install on Ubuntu:

sudo apt-get update
sudo apt-get install screen

 

Next Step, go to your Installation path of your Avorion Server (there should be your server.sh etc. too) and create with your favorite editor a new file called "restart.sh" ( I´ll be using VI Editor for this Tutorial )

 

vi restart.sh

 

Use "I" to get in insert mode and copy paste this script and edit the HOMEPATH

 

#!/bin/sh
screen -S avorion -X eval 'stuff "/say Next Restart in 15Min..."\015'
sleep 300
screen -S avorion -X eval 'stuff "/say Next Restart in 10Min..."\015'
sleep 300
screen -S avorion -X eval 'stuff "/say Next Restart in 5Min..."\015'
sleep 240
screen -S avorion -X eval 'stuff "/say Next Restart in 1Min..."\015'
sleep 50
screen -S avorion -X eval 'stuff "/say Restart in 10Sek..."\015'
sleep 5
screen -S avorion -X eval 'stuff "/say Restart in 5..."\015'
sleep 1
screen -S avorion -X eval 'stuff "/say Restart in 4..."\015'
sleep 1
screen -S avorion -X eval 'stuff "/say Restart in 3..."\015'
sleep 1
screen -S avorion -X eval 'stuff "/say Restart in 2..."\015'
sleep 1
screen -S avorion -X eval 'stuff "/say Restart in 1..."\015'
sleep 1
screen -S avorion -X eval 'stuff "/stop"\015'
sleep 30
cd /home/gameservers/SteamCMD/avorion
./start.sh

 

Exit the Insert Mode by using the ESC-Button and type ":wq" to save and quit the editor.

 

This Script will now announce a Restart Countdown and will stop the server.

 

Make the restart.sh executable

 

chmod +x restart.sh

 

 


Now we need another file called start.sh to start the server again.

 

vi start.sh

 

Use "I" again for insert mode and copy paste this script

 

#/bin/bash
screen -dmS avorion sh server.sh

 

Exit the Insert Mode by using the ESC-Button and type ":wq" to save and quit the editor.

 

The "-dmS" for screen will run the session in "daemon" mode which starts the session detached

To attach the session again you can use "screen -r avorion"

 

Make the start.sh executable

 

chmod +x start.sh

 

 


To get this automatic running we use a simple cron job

 

crontab -e

 

*may you get asked what kind of editor you want to use, Select number 3, it should be the VI Basic Editor*

 

and add to the last line (dont forget to edit the HOMEPATH)

 

0 */3 * * * sh /home/gameservers/SteamCMD/avorion/restart.sh

 

This crontab is now a schedule, it will start the restart.sh (15min countdown) every  3 hours.

Link to comment
Share on other sites

  • 2 weeks later...

vi can be Virtually Impossible for many.  Here is an option for the vi impaired:

 

# grab the current crontab to a new file

crontab -l > ./crontmp

# append the new conr rule

echo '0 */3 * * * sh /home/gameservers/SteamCMD/avorion/restart.sh' >> ./crontmp

# pull the file back into crontab and make it live

crontab crontmp

 

verify with:

 

crontab -l

 

 

or, as an easy one-liner:

 

crontab -l > ./crontmp;echo '0 */3 * * * sh /home/gameservers/SteamCMD/avorion/restart.sh' >> ./crontmp;crontab crontmp

 

 

 

YMMV - .MutieG.

Link to comment
Share on other sites

  • 3 weeks later...

Áfter recently moving over to Linux I still have a lot to discover so perhaps you could help me with getting in the right direction.

I am using Aki's server manager, which issues the command "./manager start" to start the server.

Can the script be adjusted to issue that command or do I need to configure the server.sh correctly for it to work?

 

I have another question assuming I've already answered my own question above, will this interfere with a similar service that is checking if the process has crashed?

Might be easier to integrate the crash handling also in this script, which would be perfect :)

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...