• 0
BuLaLaKaW

Auto Start RO when Server Accidentally Restart

Question

HI!

I tried to do this http://www.debian-administration.org/articles/28 in order to make my RO autostarts when server reboots accidentally.

#!/bin/bash

run=1

if [ "$run" -eq 1 ]; then
if [ $(ps | grep -e login-server | wc -l) -eq 0 ]; then
# Login server down
/home/RO_User01/rewrite/login-server_sql & > /dev/null
fi

if [ $(ps | grep -e char-server | wc -l) -eq 0 ]; then
# Char server down
/home/RO_User01/rewrite/char-server_sql & > /dev/null
fi

if [ $(ps | grep -e map-server | wc -l) -eq 0 ]; then
# Map server down
/home/RO_User01/rewrite/map-server_sql & > /dev/null
fi

sleep 10
/home/RO_User01/rewrite/auto-restarter.sh start &
fi

saved it as autorestart.sh , then I issue the command ...

chmod 755 /etc/init.d/autorestart.sh

then issue this command ...

update-rc.d autorestart.sh defaults

i thought that if i use this line

sleep 10
/home/RO_User01/rewrite/auto-restarter.sh start &
fi

this will run the auto-restarter.sh and make the whole thing auto run if ever the server shuts down, but did not work.

please help.

  • Upvote 1

Share this post


Link to post
Share on other sites

20 answers to this question

Recommended Posts

  • 0

Tnx @pveronneau, this guide work perfectly on Debian 9!

Edit: unfortunately I realized that with this system of auto reboot everything works but I can no longer have the "screen" of rathena logs in console via ssh like this image.
Does anyone know how to get a check like this even with the map server as a linux service in auto boot?

 

Hmxo9O.jpg

Edited by CyberDevil

Share this post


Link to post
Share on other sites

Hi V e r T i g O,

You should just edit your '/etc/rc.local' file and add the following line before 'end'.

./home/RO_User01/rewrite/start

Share this post


Link to post
Share on other sites

Hi V e r T i g O,

You should just edit your '/etc/rc.local' file and add the following line before 'end'.

./home/RO_User01/rewrite/start

tried it and this is how my rc.local looks now

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

./home/RO_User01/updated/rewrite/auto-restarter.sh
exit 0

seems not starting the program on reboot.

I am using Debian 5 x86, what OS are you using ?

Edited by V e r T i g O

Share this post


Link to post
Share on other sites

Hi V e r T i g O,

Try using this instead...

/home/RO_User01/updated/rewrite/auto-restarter.sh start

I'm not very familiar with using auto-restarter.sh, but how do you usually start it? Is it just with './auto-restarter.sh'?

Edited by Asura

Share this post


Link to post
Share on other sites

you start it by typing

./auto-restarter &

then it will start all the servers (map - char - login) then auto check every 10 seconds if one of the server (map - char - login) fails, it auto restarts them as well.

PS. I am using Debian 5, hope this is not an issue. Please tell me as well what OS uses rc.local effectively

thanks

Edited by V e r T i g O

Share this post


Link to post
Share on other sites

Hi V e r T i g O,

It should work fine in Debian 5. I would like to remind you that Debian has stopped supporting Lenny (5); so it's better to drop that Distro and move onto Squeeze (6).

Then I would recommend you use that line for the /etc/rc.local

./home/RO_User01/updated/rewrite/auto-restarter.sh &

  • Upvote 1

Share this post


Link to post
Share on other sites

Hi glemor123,

You can actually use the same bash script as V e r T i g O has provided.

Share this post


Link to post
Share on other sites

can you guide me how to setup this one...i save this code as auto-restarter.sh and placed it to my SVN folder then what will be the next?

#!/bin/bash
run=1
if [ "$run" -eq 1 ]; then
if [ $(ps | grep -e login-server | wc -l) -eq 0 ]; then
# Login server down
./login-server_sql & > /dev/null
fi
if [ $(ps | grep -e char-server | wc -l) -eq 0 ]; then
# Char server down
./char-server_sql & > /dev/null
fi
if [ $(ps | grep -e map-server | wc -l) -eq 0 ]; then
# Map server down
./map-server_sql & > /dev/null
fi
sleep 10
./auto-restarter.sh &
fi

Share this post


Link to post
Share on other sites

tried on mine but still doesn't work:

./root/Desktop/trunk/auto-restarter.sh &

my rc.local was located at /etc/rc.d/rc.local

Share this post


Link to post
Share on other sites

Hi Everyone,

After taking a closer look at the script; you can actually just add the script into the crontab to run per minute. Just open up your crontab with this command:

crontab -e

And then add this to the last line of your cron tasks

*/1 * * * * /location/to/file/auto-restarter.sh

Make sure you put the proper location to the file in the crontab, and also when you want the script to stop running; just edit the 'auto-restarter.sh' file and change 'run=1' to 'run=0'.

Share this post


Link to post
Share on other sites

Hi TwerkMaster,

 

I found this using Google.com; http://www.unix.com/shell-programming-scripting/17382-how-save-crontab.html

hi asura, im using asurahost too! hope u can help me on this one!

i am using herc, so i need to use gdb to start the map server and a 'run'/'r' response after...

 

so how to write the gdb and response parameter in it?

 

# Map server down
gdb /Desktop/lcola/map-server run & > /dev/null
fi

Share this post


Link to post
Share on other sites

I do wish you guys would stop resurrecting old topics.

 

Cloanx: if you're using asura hosting, why don't you submit a ticket on their site and get them to help you there instead? Also, google'ing gdb brings up the answers to your question.

the last post is october.. i guess this thread is not 'that' old

Share this post


Link to post
Share on other sites

Sorry to resurrect the thread, however this is the first topic Google finds on the subject.  

 

I wanted to provide a simple method for people to manage their Linux based rAthena servers.

 

Modern Linux systems have moved away from the old system-v-init system and have now started to use systemd.  Setting up rAthena correctly using systemd is actually very easy.

 

For this example, I assume that you are using mysql as a database.  I also assume that you run all services (login, character and map) and the database on the same system.  

 

The logic we want to use is as follows:

 

Wait until the system goes multi user -> make sure networking has started -> verify the database has started -> start the login server -> start the character server -> start the map server.

 

You need to make sure your rAthena setup is working correctly, and starts with the "./athena-start start" command before setting this up.  Be sure to stop the rAthena before setting this up.

 

 

** NOTE ** All these commands are done as root.

 

Step 1 - Set your working path to the systemd services directory.

cd /lib/systemd/system/

** Warning ** this directory may change based on your distribution!  Most use this path, however some may use a different location.  Refer to your Linux distribution documentation for the correct path.  This path should be correct for Fedora and Debian, possibly others.

 

Step 2 - Create the service file for the login server.

Using the editor of your choice (vi, emacs, nano) create the following file. You need to modify it to set your install path and the rathena user.

 

rathena-login.service

[Unit]
Description=rAthena login server
After=syslog.target network.target mysqld.service

[Service]
WorkingDirectory=<rAthena install directory>
User=rathena
ExecStart=<rAthena install directory>/login-server
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

Step 3 - Create the service file for the character server

Using the editor of your choice (vi, emacs, nano) create the following file.  You need to modify it to set your install path and the rathena user.

 

 

rathena-char.service

[Unit]
Description=rAthena character server
After=syslog.target network.target mysqld.service rathena-login.service

[Service]
WorkingDirectory=<rAthena install directory>
User=rathena
ExecStart=<rAthena install directory>/char-server
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

Step 4 - Create the service file for the map server

Using the editor of your choice (vi, emacs, nano) create the following file.  You need to modify it to set your install path and the rathena user.

 

 

rathena-map.service

[Unit]
Description=rAthena map server
After=syslog.target network.target mysqld.service rathena-login.service rathena-char.service

[Service]
WorkingDirectory=<rAthena install directory>
User=rathena
ExecStart=<rAthena install directory>/map-server
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

Step 5 - Restart systemd

systemctl daemon-reload

*If you modify the service files, you need to run this step again.

 

Step 6 - Start the services and verify they are running

systemctl start rathena-login.service
systemctl start rathena-char.service
systemctl start rathena-map.service

systemctl status rathena-login.service
systemctl status rathena-char.service
systemctl status rathena-map.service

Verify each service correctly started.  If you have a failure, verify your paths in the services file and retry.

 

Step 7 - Enable the services on boot

** WARNING ** Do not do this step until you have verified services are running properly in step 6.  Failure to do so *may* result in your system hanging on boot.

systemctl enable rathena-login.service
systemctl enable rathena-char.service
systemctl enable rathena-map.service

That's it, your now running a fully daemonized rAthena server.  With this configuration systemd will watch the services, and if they crash will automatically restart them after 42 seconds.

 

Here are the commands to manage your server.

 

Start the server

systemctl start rathena-login.service
systemctl start rathena-char.service
systemctl start rathena-map.service

Stop the server

systemctl stop rathena-login.service
systemctl stop rathena-char.service
systemctl stop rathena-map.service

Restart the server

systemctl restart rathena-login.service
systemctl restart rathena-char.service
systemctl restart rathena-map.service

Additonal notes:

 

If you use a different database server such as Maria or PostgreSQL, be sure to change the

After=syslog.target network.target mysqld.service

Line to read

After=syslog.target network.target mariadb.service ...

or

After=syslog.target network.target postgresql.service ...

If you have split the servers onto different machines, you also need to modify this line to remove the load dependency.

 

This currently will not work on CentOS!

CentOS 6 still uses the old SystemVinit system.  CentOS 7 is rumored to have systemd support, however after the acquisition by Redhat the projects future is uncertain.  I suggest you move over to Fedora for all the new hotness, or wait for RHEL7 if you need an enterprise grade Linux distribution.

 

If your absolutely stuck on CentOS, you need to look into writing a proper init script.  See https://blog.hazrulnizam.com/create-init-script-centos-6/ for an example on how to do this.  Knowledge of shell scripting is required.

 

Can't I just have one service?

Short anwser, no.

 

rAthena runs under three process threads and need to be monitored by systemd independently.  If you ran all services under one script, process failures could not be detected/logged correctly.

If your really lazy, I think you can do a "systemctl status rathena*" to do all three processes at once.  It just doesn't work 100% of the time.  Best practice is not to be lazy, and call all services independently.

 

Does this work with other emulators?

Yes, it should work just fine with Hercules and eathena.

Edited by pveronneau
  • Upvote 2

Share this post


Link to post
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