Hyperion
Founder
Tutorial taken from the NomWiki, here.
Linux\BSD Auto-Restart Checker
(1)Intro
Not many people host their wow cores on *nix, but this does come in handy as
an auto check for running daemons on your machine. You can use this same method
on any other script you run.
First off, open notepad, or vi, or pico, whatever you use to script or edit
with. I personally prefer Notepad++. When you have your empty script open just
name it something like, 'restart_check.sh'.
In the script, first will we begin with adding →
This also depends on what Linux/BSD distribution you are running. But usually, on
Linux it's /bin/bash, on BSD it's /usr/local/bin/bash.
We add this line at the top, so your shell knows what type of interpreter to run.
(2)The loop check
Now let's get the simple loop added after the shell interpreter. On the next line add→
Let's start on the first string, 'while true;' meaning while the script is running. Then
we have 'do' which is what's telling the script what to do during the loop. Next will be
some editing on your part to use the correct paths and daemon names.
First, change /home/server/serverbin to where you have your wow core installed on the server.
Then you will need to change ./worldserver to the name of your core daemon.
At the end of this part, it will 'wait' until the daemon crashes. So in this script, you
should have it looking like →
Save the script and move on to the next step.
(3)The Daemon
First, make sure you have the 'screen' package installed.
CentOS\RedHat →
Ubuntu\Debian →
As the same as step one, make another file, name it 'restart.sh'. Also
add the same interpreter →
and under it put →
This will give us our variable name. You can name it whatever you'd like I
will explain it's reason at the end of the tutorial.
After the session line add →
This will tell our 'DAEMON' variable how to run the screen.
On the next few lines add →
This will run the screen under the name “worldserver”, what we put in the SESSION
variable. Under that screen it will launch the restart_check.sh script we made earlier.
Your file should now look like ->
Save this file.
Take both the file's we made, restart.sh and restart_check.sh, and put them both
into your wow core's server bin. (Wherever your core daemon is located) then cd to that dir.
Then you will need to run the following →
This will allow the scripts to run.
Now you can simply run the restarter by typing: ./restart.sh
Your daemon is now launched and is checking whenever it goes down, it will
automatically restart it. Good for in-game server restarts when editing the
database and you have no need to login to the hosting server.
Now remember the SESSION name? In this tutorial we used 'worldserver'. So
when you need to do something via console on the server, you can simple type
“screen -r worldserver” on your shell. This will attach you to the screen thats
running the server daemon. To detach from this screen without interrupting the
server, just hold CTRL then a+d.
Linux\BSD Auto-Restart Checker
(1)Intro
Not many people host their wow cores on *nix, but this does come in handy as
an auto check for running daemons on your machine. You can use this same method
on any other script you run.
First off, open notepad, or vi, or pico, whatever you use to script or edit
with. I personally prefer Notepad++. When you have your empty script open just
name it something like, 'restart_check.sh'.
In the script, first will we begin with adding →
Code:
#!/bin/bash
This also depends on what Linux/BSD distribution you are running. But usually, on
Linux it's /bin/bash, on BSD it's /usr/local/bin/bash.
We add this line at the top, so your shell knows what type of interpreter to run.
(2)The loop check
Now let's get the simple loop added after the shell interpreter. On the next line add→
Code:
while true; do
cd /home/server/serverbin
./worldserver
wait
done
Let's start on the first string, 'while true;' meaning while the script is running. Then
we have 'do' which is what's telling the script what to do during the loop. Next will be
some editing on your part to use the correct paths and daemon names.
First, change /home/server/serverbin to where you have your wow core installed on the server.
Then you will need to change ./worldserver to the name of your core daemon.
At the end of this part, it will 'wait' until the daemon crashes. So in this script, you
should have it looking like →
Code:
#!/bin/bash
while true; do
cd /home/server/serverbin
./worldserver
wait
done
Save the script and move on to the next step.
(3)The Daemon
First, make sure you have the 'screen' package installed.
CentOS\RedHat →
Code:
yum install screen
Ubuntu\Debian →
Code:
apt-get install screen
As the same as step one, make another file, name it 'restart.sh'. Also
add the same interpreter →
Code:
#!/bin/bash
and under it put →
Code:
SESSION="worldserver"
This will give us our variable name. You can name it whatever you'd like I
will explain it's reason at the end of the tutorial.
After the session line add →
Code:
DAEMON="screen -d -m -S $SESSION /home/server/serverbin/restart_check.sh"
This will tell our 'DAEMON' variable how to run the screen.
On the next few lines add →
Code:
screen -r $SESSION -ls -q 2>&1 >/dev/null
echo -e ""
echo "Worldserver has been launched into the background."
echo -e ""
if [ $? -le 10 ]; then
echo "Restarting $DAEMON"
$DAEMON
fi
wait
This will run the screen under the name “worldserver”, what we put in the SESSION
variable. Under that screen it will launch the restart_check.sh script we made earlier.
Your file should now look like ->
Code:
#!/bin/bash
SESSION="worldserver"
DAEMON="screen -d -m -S $SESSION /home/server/serverbin/restart_check.sh"
screen -r $SESSION -ls -q 2>&1 >/dev/null
echo -e ""
echo "Worldserver has been launched into the background."
echo -e ""
if [ $? -le 10 ]; then
echo "Restarting $DAEMON"
$DAEMON
fi
wait
Save this file.
Take both the file's we made, restart.sh and restart_check.sh, and put them both
into your wow core's server bin. (Wherever your core daemon is located) then cd to that dir.
Then you will need to run the following →
Code:
chmod a+x restart.sh && chmod a+x restart_check.sh
This will allow the scripts to run.
Now you can simply run the restarter by typing: ./restart.sh
Your daemon is now launched and is checking whenever it goes down, it will
automatically restart it. Good for in-game server restarts when editing the
database and you have no need to login to the hosting server.
Now remember the SESSION name? In this tutorial we used 'worldserver'. So
when you need to do something via console on the server, you can simple type
“screen -r worldserver” on your shell. This will attach you to the screen thats
running the server daemon. To detach from this screen without interrupting the
server, just hold CTRL then a+d.