Absurd Minds

More than 100 years without a motto.
It is currently 16 Jun 2019 12:55

All times are UTC-04:00

Post new topic  Reply to topic  [ 1 post ] 
Author Message
PostPosted: 12 Feb 2013 18:14 
User avatar

Joined: 25 Mar 2010 19:07
Posts: 8381
You can use bash scripts to automatically start and restart your servers.

Basic server start script
This is an example of a start script I use to start a server. Instead of having to type in a really long server command line, all I have to do is run the script.

First, create a bash script within the server's parent directory. For a GO server, this would be in, for example, /user/GO. (Within GO would be directories like /bin or /csgo.)
nano alpha.sh
To keep things simple, I named all my start scripts alphabetically.

screen -X -S alpha quit
sleep 4
cd /home/gamer/go/server1
/usr/bin/screen -dmS alpha ./srcds_run -game csgo +game_type 0 +game_mode 1 -authkey ############+host_workshop_collection 125645871 +workshop_start_map 125498851 -ip +port 27018 -usercon -nowatchdog -auutoupdate -tickrate 128 -nohltv -autoupdate -steam_dir /home/gamer/go/steamcmd -steamcmd_script server1.txt
Line 1 tells the server that I'm running a bash script.
Line 2 kills any previous screen sessions that might be running. (Notice, to keep it simple, I named my screen alpha since the alpha script is starting it.
Line 3 allows it to sleep for 4 seconds, just to make sure all the processes are dead.
Line 4 moves to the correct directory in which to start the server. (I had to add this line for the script to executable from a "parent script" that I use to restart all the servers at once. More on that in a minute.)
Line 5 starts my server in a detached screen with the name alpha.

Now I want to make sure the script is executable.
chmod +x alpha.sh
Now, if I want to start the server, I can just go into the /home/gamer/go/server1/ directory and type ./alpha.sh. This will automatically start the server.

Creating a "parent" restart script
Since I run a lot of servers, it's really nice to be able to just run one script to start all my servers instead of having to go through a whole bunch of directories starting a whole bunch of different scripts. So I made this script in my user's home directory.


sleep 30


sleep 30


#sleep 30


sleep 30


sleep 30


sleep 30


sleep 30


sleep 30


sleep 30


#sleep 30


exit 0
Note: lines started # are comments, meaning those scripts won't be run. It's a really easy way to disable or enable servers as needed. Don't forget to change this script to executable!

If I want to be able to manually restart all my servers at once, for example after updating them all, I just have to go to /home/gamer and type in ./start2.sh.

Getting them to start automatically
I can add a line in crontab so these will start automatically if the server reboots. I've also provided an example of how to restart the scripts every morning at 6am.
@reboot gamer /home/gamer/start2.sh
00 6 * * 0,2,3,4,5,6 amrestart /home/gamer/start2.sh

Server list

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1 post ] 

All times are UTC-04:00

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited