Jump to content

MaNGOS Restarter ?


Guest Darkhunter

Recommended Posts

cron.d, corn.daily, corn.hourly are for system cronjobs and should not be used by users for several reasons, instead,

In console execute:

crontab -e

To edit current users crontab entries

To stop mangos-worldd and mangos-realmd use

pkill "mangos-*"

Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Looking at the script(s) in this thread it should start MaNGOS if it is not currently running.

Cron checks every minute if MaNGOS is not running it will start it

If you stop MaNGOS in-game, from console, or it crash this cron job should start it back up

Edit:

You can confirm the cron job is running by stopping MaNGOS

pkill "mangos-*"

wait 1-2 minutes, then run

pgrep "mangos"

If you get 2 lines of numbers back then MaNGOS is running, if you don't get any lines returned then it is not working

Link to comment
Share on other sites

Create a file name like this loop_mangos.sh give him execute permission

#!/bin/bash

while :

do

echo "MaNGOS daemon restarted"

echo `date` >> /opt/mangos2/crash.log &

sleep 4

/opt/mangos2/bin/mangos-worldd -c /opt/mangos2/etc/mangosd.conf 2>&1 | tail -n 30 >> /opt/mangos2/crash.log

echo " " >> /opt/mangos2/crash.log &

pid=`ps ax | awk '($5 ~ /mangos-worldd/) { print $1 }'`

wait $pid

sleep 2

echo `date` ", MaNGOS daemon crashed and restarted." >> /opt/mangos2/serverlog

sleep 10

mv /opt/mangos2/Server.log "/opt/mangos2/Server-`date +%Y-%m-%d-%H:%M:%S`.log"

done

this will create a "serverlog" file with data like when the server crashed, and a file "crash.log" with data like whi the server is crashed (console output i think)

for realmd something like this: loop_realmd.sh

#!/bin/bash

err=1

until [ $err == 0 ];

do

sleep 10

/opt/mangos2/bin/mangos-realmd -c /opt/mangos2/etc/realmd.conf

done

You have to change the directories :)

you can call this files from /etc/rc.d/rc.local then you have an auto restart from pc restart too :)

Link to comment
Share on other sites

Currently I have this python script

#! /usr/bin/python

import commands
import os
from sys import exit

# exit()

servername = 'mangos'

daemons = {
   'logon' : '/path/to/mangos/mangos-realmd',
   'world' : '/path/to/mangos/mangos-worldd'
}

for name, path in daemons.iteritems():
   if not os.path.basename(path) in commands.getoutput('ps -A'):
       os.chdir(os.path.dirname(path))
       os.system('screen -A -m -d -S ' + servername + '_' + name + '  sudo -u mangos_user ./' + os.path.basename(path))
       print 'Starting ' + name
   else:
       print name + ' is already running'

together with this cron job

  * *  *   *   *     python /path/to/restarter.py

Now that is being helpful. Wish there were many more like you on this forum....

Link to comment
Share on other sites

  • 2 weeks later...

this ist another simple but good working restarter for cron-job

#!/bin/sh

# Names to search for

W1='World1'

W2='World2'

R1='Realm'

# commands to start worldd/realmd

RESTART_WORLD1='screen -AdmS '$W1' /path/to/mangos-worldd -c /path/to/mangosd.conf'

RESTART_WORLD2='screen -AdmS '$W2' /path/to/mangos-worldd -c /path/to/mangosd2.conf'

RESTART_REALM1='screen -AdmS '$R1' /path/to/mangos-realmd'

# check if World/Realm is already running

OUTPUT1=`ps ax | grep $W1 | grep -v grep`

OUTPUT2=`ps ax | grep $W2 | grep -v grep`

OUTPUT3=`ps ax | grep $R1 | grep -v grep`

# if not running, start them

if ! echo $OUTPUT1 | grep $W1 1>/dev/null ; then

$RESTART_WORLD1

fi

if ! echo $OUTPUT2 | grep $W2 1>/dev/null ; then

$RESTART_WORLD2

fi

if ! echo $OUTPUT3 | grep $R1 1>/dev/null ; then

$RESTART_REALM1

fi

ps: this is a modification of a restarter which i found in this forum, but don't know the original poster anymore.

Link to comment
Share on other sites

Lol! Corn Job...

Anyway, I run parallel test and production realms. Multiplying the number of realms makes starting, stopping and restarting the realms a little more difficult and since a number of people here run Ubuntu, I'd strongly recommend using Upstart. It's bundled in Ubuntu and it understands whether a process disappeared and needs restarting. This obviates the need for various restart scripts as all maintenance can now be done with .server commands from within MaNGOS. Later versions also has a WaitAtStartupError configuration option, which is immensely helpful. No chewing up CPU for no reason no mo.

But seriously, Upstart is a good thing. Read up on it.

Link to comment
Share on other sites

Upstart has nothing to do with Cron. AFAIK it's only Ubuntu's replacement of sysv startup mechanism, no daemon, nothing that can restart mangos.

Anyway I don't really see the point in making things ugly. Why the hell has somebody EVER came with the idea to use cron as mangos restarter? It's totally ... ahem. Imagine it has to run every minute just to check if mangos is running or not, it has to match against some binary name in process list, in a rare case it could launch mangos 2 or more times!

Much simplier solution is to use a wrapper script with infinite loop, similar to what others posted, not only it can restart your mangos immediately (and not after 1-60 seconds), it can easily even check for it's return value (if it's 0 or 1, ie. shutdown or error, then don't restart). Furthermore it's a lot cleaner, since it doesn't have to check every minute for running mangos and it's binary-name-safe, so if some other user starts "cat" masked as "mangos-worldd" 20 times, it won't ever confuse your restarter, because it doesn't care about processes, it doesn't need to retrieve process list from the kernel.

Also it's worthless to make restarters for realmd as it (from my experience) never crashes.

edit: I admit I haven't properlz read all those posts above. Last time I checked Upstart (some years ago) it was just a paralell startup script system. If it's daemon now (that can restart services upon crash), it's at least as good as cron (if it *just* checks processes periodically).

The basic loop script can be easily used when you need to run multiple mangos+realmd pairs, you don't even have to rename them as each restarter takes care of it's one server.

An example:

#!/bin/sh
while true
do
   ./mangos-worldd
   [ $? < 2 ] && exit 1
   sleep 5
done;

This is a very simple and clean (doesn't waste any unnecessary resources) restarter that exits when you .server shutdown your server (instead of restarting it) and when some error occurs (ie. DBCs out of date), so it won't meaninglessly start and error down all the time.

Save this script as restarter.sh in the directory where mangos-worldd is, make it executable (chmod +x restarter.sh) and fire up a screen session using this script, ie. "screen -d -m -S mangosd ./restarter.sh". That's all.

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 4 weeks later...
  • 2 weeks later...
  • 2 months later...
  • 1 month later...

I have this:

restarter:

screen -A -m -d -S mangos_restarter ./restarter-bin

restarter-bin

#! /bin/bash

while true
do
   PID1=$(pidof mangos-worldd)
   if (( PID1 < 1 ))
   then
       ./startw
   fi

   PID2=$(pidof mangos-realmd)
   if (( PID2 < 1 ))
   then
       ./startl
   fi

   sleep 20
done

startl:

screen -A -m -d -S mangos-realmd ./mangos-realmd

startw:

screen -A -m -d -S mangos-worldd ./mangos-worldd
ulimit -c unlimited

could it works with mtmaps?

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use