Absurd Minds

More than 100 years without a motto.
It is currently 28 Mar 2024 10:50

All times are UTC-04:00




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

Joined: 25 Mar 2010 19:07
Posts: 8392
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.)
Code:
nano alpha.sh
To keep things simple, I named all my start scripts alphabetically.
Code:
#!/bin/bash

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 70.34.195.4 +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.
Code:
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.
Code:
#!/bin/bash

/home/gamer/go/server1/alpha.sh

sleep 30

/home/gamer/go/server2/bravo.sh

sleep 30

/home/gamer/go/server3/charlie.sh

#sleep 30

#/home/gamer/go/demo/delta.sh

sleep 30

/home/gamer/go/demo2/kilo.sh

sleep 30

/home/gamer/go/large/foxtrot.sh

sleep 30

/home/gamer/go/large2/golf.sh

sleep 30

/home/gamer/go/large3/hotel.sh

sleep 30

/home/gamer/go/deathmatch/india.sh

sleep 30

/home/gamer/go/arms2/juliett.sh

#sleep 30

#/home/gamer/go/nobots/lima.sh

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.
Code:
@reboot gamer /home/gamer/start2.sh
00 6 * * 0,2,3,4,5,6 amrestart /home/gamer/start2.sh

_________________
Server list
Donate


Top
   
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 5 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:  
cron
Powered by phpBB® Forum Software © phpBB Limited