Jump to content
  • 0

Auto Start RO when Server Accidentally Restart


BuLaLaKaW

Question


  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  125
  • Reputation:   7
  • Joined:  11/19/11
  • Last Seen:  

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
Link to comment
Share on other sites

23 answers to this question

Recommended Posts

  • 2

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  2
  • Reputation:   3
  • Joined:  01/26/13
  • Last Seen:  

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
  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.02
  • Content Count:  242
  • Reputation:   37
  • Joined:  02/25/18
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  125
  • Reputation:   7
  • Joined:  11/19/11
  • Last Seen:  

On 3/18/2014 at 8:55 AM, pveronneau said:

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.

This might be late .. better late than never .. thank you very much!!!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  402
  • Reputation:   89
  • Joined:  02/07/13
  • Last Seen:  

On 2/4/2019 at 2:17 PM, CyberDevil said:

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

Just add in service file those lines

StandardOutput=append:/home/user/logs/map-server.log
StandardError=append:/home/user/logs/map-server-error.log

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  707
  • Reputation:   168
  • Joined:  01/26/12
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  125
  • Reputation:   7
  • Joined:  11/19/11
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  707
  • Reputation:   168
  • Joined:  01/26/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  125
  • Reputation:   7
  • Joined:  11/19/11
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  707
  • Reputation:   168
  • Joined:  01/26/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  125
  • Reputation:   7
  • Joined:  11/19/11
  • Last Seen:  

thanks Asura, I will use this.

thanks!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  318
  • Topics Per Day:  0.07
  • Content Count:  931
  • Reputation:   13
  • Joined:  12/20/11
  • Last Seen:  

how about for centos and eathena SVN?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  707
  • Reputation:   168
  • Joined:  01/26/12
  • Last Seen:  

Hi glemor123,

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  318
  • Topics Per Day:  0.07
  • Content Count:  931
  • Reputation:   13
  • Joined:  12/20/11
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.01
  • Content Count:  530
  • Reputation:   33
  • Joined:  01/17/12
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  29
  • Topics Per Day:  0.01
  • Content Count:  270
  • Reputation:   20
  • Joined:  12/10/11
  • Last Seen:  

Anyone having problem with this still?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  707
  • Reputation:   168
  • Joined:  01/26/12
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  197
  • Reputation:   13
  • Joined:  05/14/12
  • Last Seen:  

thanks edward and markus :) 

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  26
  • Topics Per Day:  0.01
  • Content Count:  53
  • Reputation:   1
  • Joined:  01/07/12
  • Last Seen:  

Hi,

 

This is a noob question, but how do you save in crontab -e?

 

Thanks!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  707
  • Reputation:   168
  • Joined:  01/26/12
  • Last Seen:  

Hi TwerkMaster,

 

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  4
  • Reputation:   0
  • Joined:  10/07/13
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3122
  • Reputation:   1614
  • Joined:  03/26/12
  • Last Seen:  

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.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  4
  • Reputation:   0
  • Joined:  10/07/13
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  166
  • Topics Per Day:  0.04
  • Content Count:  789
  • Reputation:   50
  • Joined:  04/16/12
  • Last Seen:  

how to do this in CentOS?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...