PDA

View Full Version : DogMeat's keep alive Linux Script


rudedog
02-25-2005, 10:41 PM
LINUX SHELL SCRIPTS (not windows!)

LINUX SHELL SCRIPTS
(not windows!)

As I mentioned before, there are alot of things I want to add to these, mostly dealing with logs and detecting a "killfile". However in their current state they are rocksolid and don't do anything that would give your provider a reason not to implement them, such as run 3rd party programs.

Be sure and change the directories and commandline options for the mohaa server to what YOU need.

The first one is a simple loader script which uses SCREEN to place the MoHAA server on a detached console. Copy and paste into a file called mload.sh and chmod it 755.

#!/bin/bash

echo mload.sh: Load MoHAA With Screen

cd /lfs/game/mohaa

echo mload.sh: Screen Mohaa Detached Console

screen -S mohaa -m -d ./mlds.sh

echo mload.sh: Finished Screen Command


Next is the actual looping script itself, this can of course be used standalone without using mload.sh, but then you lose the benefits of SCREEN. Copy and paste into a file called mlds.sh and chmod it 755.

#!/bin/bash

echo mlds.sh: Launching Mohaa

cd /lfs/game/mohaa

echo mlds.sh: Loop Initialize
while true
do
echo mlds.sh: Loop Start
echo mlds.sh: To Exit Loop Hit CTRL-C While Sleeping
sleep 5
echo mlds.sh: Server Start
./mohaa_lnxded +set sv_chatter 1 +set developer 1 +exec servertest.cfg
echo mlds.sh: Server Exit
echo mlds.sh: To Exit Loop Hit CTRL-C While Sleeping
echo mlds.sh: Sleep 15 Seconds
sleep 15
echo mlds.sh: Loop Restart
done

This first script set is especially important because of it's simplicity, even novice linux admins can get it up and running and no server provider should object to the script or it's methods. Many new admins don't realize the secret power that an automatic restart script gives you, so those that do get to nod sagely while I discourse thereupon.

rcon quit

So we just exited our server, script runs sleeps loops and reloads the server again, ok so it works, so what... Well lets take a small step backwards, to what we did before giving the quit command. First we took a couple of maps we'd been trying out locally and FTP'd 'em to our directory on the game server. In order to get the server to load our new pak files we've of course got to completely restart the engine from scratch, which thanks to our simple script we can do at will and have the server up and accepting clients again in a minute. (I timed my 333Mhz RedHat system under X/Gnome: after a quit cmd it took 67 seconds before it was again responding to client requests, even with the built in 20 seconds sleep)

While some server providers have the web interfaces kicking, many more admins seem to be in an "email wait til tommorrow" situation.
Hopefully this will help get some folks out of that rut
Hope this helps, I'll post any future enhancements to the scripts here also.
_________________
DogMeat
Now where'd I put that cool signature...

buddy
07-17-2006, 01:31 AM
hi i have a linux sh server and i want to add these to my server but iam a complete noob to this as my last server had interface and was easy to use for noobslike me lol i dont know what chmod it 755 means can you tell me what to do please and what kind of file is it and where do i put it on my server any help please thank you :confused: :o

rudedog
07-17-2006, 09:16 AM
Before you even go through all this trouble, please remember that this was writen a while ago, when 99% of the GSPs and the GSP business was just getting started.

1) you normally don't have access to chmod any dir, on your server
2) Now a days they have their own script to keep your server running

I would ask them first before doing something that could mess up their box and your server.

This is great if your running your own box with Linux.

buddy
07-17-2006, 10:51 AM
:) ok thanks for the info i didnt know this thanks again [hand]

buddy
07-17-2006, 03:45 PM
yes my server does start again after rcon quit thanks for the advise [hand]

twl_viper
10-27-2006, 07:03 PM
Will this restart after a crash ? or with quit ?

rudedog
10-27-2006, 07:15 PM
a quit or crash of the exe not the whole box

MiNi Me
11-02-2006, 04:37 AM
Okay, so I drop these scripts in my /mohaa directory
now to start the server do I still use the command string

screen ./mohaa_lnxded +set net_IP xxx.xxx.xxx.xxx +set fs_basepath ./ +set com_zoneMegs 30 +set vm_game 0 +set ttycon 0 +set dedicated 2 +exec server.cfg

That is the string I've been using to start the server, I've upped those two .sh files above to the /mohaa directroy, I've changed the path to point to where my mohaa directory lives on the server, but I think I'm missing something rather obvious here because as I've done it it's not working.

How do I tell the server to execute those scripts and reset the server in the event of a crash or rcon quit command?

Thanks for any help

GaSplat
11-06-2006, 12:43 AM
There are two scripts Rudedog has up there. The first one is the outer shell that uses the Linux "screen" command to launch a process that won't close down when you log off. This is called mload.sh and THATS what you use to start your server.

mload.sh will call the second script called mlds.sh. In mlds.sh, you need to edit the line after the "Server Start" comment to look like the command line you currently use. That way it will start with all the settings you want and call your config.

Hope that clarifies.:)

MiNi Me
11-06-2006, 07:07 AM
Okay, thanks for that have edited the mlds.sh script and added my start line after the ./mohaa_lnxded etc ...

Now, I'm sorry cause I"m pretty new to Linux, but to start the server with the mload.sh file, what's the command?

I've tried the obvious one from within the /mohaa directory I try
./mload.sh start , ./mload start, ./mload.sh etc etc
It just says no such file or directory

GaSplat
11-08-2006, 12:54 AM
it's been a while for me, but I think all you have to do is open a shell, cd to the correct directory, and type

mload.sh

Nat_Greene
11-08-2006, 08:32 PM
Hi,

I'm running a mohaa server on Linux Fedora Core 5. I tried to use these scripts and had some trouble getting the fist one (mload.sh) to do it's thing. However, I was able to get the second one to run alone and it works great. To get it to open in a terminal window I, using the GUI, double click on the mlds.sh file and tell it to run in terminal and it does fine. I'd like to figure out what I'm doing wrong and I'd also like to know if a nice or renice argument could be added to the script that would change the priority of mohaa automatically.

I have the server running from the /usr/games/mohaa_tdm directory and here is how I have the scripts set up in that directory. Any thoughts on what I'm doing wrong with mload.sh? :confused:

#!/bin/bash

echo mload.sh: Load mohaa_tdm With Screen

cd /usr/games/mohaa_tdm

echo mload.sh: Screen mohaa_tdm Detached Console

screen -S mohaa_tdm -m -d ./mlds.sh

echo mload.sh: Finished Screen Command


#!/bin/bash

echo mlds.sh: Launching mohaa_tdm

cd /usr/games/mohaa_tdm

echo mlds.sh: Loop Initialize
while true
do
echo mlds.sh: Loop Start
echo mlds.sh: To Exit Loop Hit CTRL-C While Sleeping
sleep 5
echo mlds.sh: Server Start
./mohaa_lnxded +set sv_chatter 1 +set developer 1 +exec tdm.cfg
echo mlds.sh: Server Exit
echo mlds.sh: To Exit Loop Hit CTRL-C While Sleeping
echo mlds.sh: Sleep 15 Seconds
sleep 15
echo mlds.sh: Loop Restart
done



Thanks.

GaSplat
11-09-2006, 02:52 AM
Nothing jumps out, and I never played w/Fedora. What happens when you try to execute mload.sh?

Nat_Greene
11-09-2006, 09:16 AM
Nothing jumps out, and I never played w/Fedora. What happens when you try to execute mload.sh?

Unfortunately, nothing at all.

Any thoughts on adding a nice or renice command to mlds.sh in order to change the priority of mohaa?

Thanks for the imput! :salute:

MiNi Me
11-10-2006, 03:04 AM
oi! sif hijack my question time :P ;)

Still need to know the command to execute the mload.sh file
these are what I have tried with no success

./mload.sh start
./mload.sh
./mload

It always says no such file (I'm trying to execute from the /mohaa file where
the mload.sh lives. If I try and execute from / then the same problem, no such file....

If I try anything without the ./ command then it just says no such command
ie mload.sh - error mload.sh not a recognized command....

Or alternatively if I want to use the mlds.sh script as a stand alone and just put the 'screen' command in there prior to the ./mohaa_lnxded etc etc etc
I can't figure the command to launch that one either

Zepplin
11-10-2006, 09:20 AM
Here's some files including one of my command lines from my server_list used to restart game servers when there down OS is centos

server_list

mohaa = cd /home/gs/mohaa/mohaa; screen -dmS mohaa ./mohaa_lnxded +set net_IP 203.88.125.104 +set net_port 12200 +set fs_basepath ./ +set com_zoneMegs 30 +set vm_game 0 +set ttycon 0 +set ui_console 1 +set dedicated 2 +set developer 2 +set cheats 0 +set fs_outputpath ./ +set sv_maxrate 15000 +exec server1.cfg
#

games.local

#!/bin/bash
/usr/bin/screen -dmS server_recovery /home/gs/server_recovery.pl

echo `date` >> /home/gs/games-local-log

server_recovery.pl

#!/usr/bin/perl -w

#use strict;

my $time_to_sleep = 30; # seconds
my $server_regex = '[A-Za-z0-9]{1,20}'; # regex matching a server name

use constant DEBUGGING => 0; # lots of debug info
use constant DRYRUN => 0; # don't actually start any servers
use constant SERVERS_FILE => '/home/gs/server_list';
use constant LOGFILENAME => '/home/gs/server_recovery.log'; # server = command format, # for comment lines
use constant LOGGING => 1;

if ($ARGV[0] =~ /restart/i) {
$oldoutput = `screen -ls`; # we are in optimum state, no server starting instantly required
} else {
$oldoutput = ''; # servers need to be started immidiately - we're NOT in optimum state
}

print "Old output: $oldoutput\n" if DEBUGGING;

while (1) {
$screenls = `screen -ls`;
print "New output: $screenls\n" if DEBUGGING;
#is screen -ls output the same as last time? If so, we're still fine
if ($oldoutput ne $screenls) {
print "Some differrence!" if DEBUGGING;
@output = split(/\n/, $screenls);
@required = ();
@runme = ();
@servers = ();
$line = '';
$req = '';
$command = '';
foreach $line (@output) {
if ($line =~ /^\s+\d+\.($server_regex)\s+(?:\(Detached\)|\(Attac hed\))$/i) {
push(@servers, $1);
print "Pushing $1 to servers from $line\n" if DEBUGGING;
}
}
$servers = "#" . join('#', @servers) . '#';
open (SERVERS, "<".SERVERS_FILE);
while (<SERVERS>) {
chomp;
s/#.*//;
s/^\s+//;
s/\s+$//;
next unless length;
if ( /($server_regex)\s*=\s*(.+)/ ) { # servername = command
$commands{$1} = $2;
push(@required, $1);
print "Commands $1 becoming $2 from $_\n" if DEBUGGING;
print "Pushing $1 to required from $_\n" if DEBUGGING;
}
}
close(SERVERS);

foreach $req (@required) {
if ($servers !~ /#$req#/) {
push(@runme, $commands{$req});
print "Pushing " . $commands{$req} . " to runme from $servers\n" if DEBUGGING;
}
}

foreach $command (@runme) {
unless (DRYRUN) {
$return = `$command`;
if (LOGGING) {
open (LOGFILE, ">>" . LOGFILENAME);
print LOGFILE "Performed $command at " . time() . ". Returned $return.\n";
close(LOGFILE);
}
}
print "Would execute: $command\n" if DRYRUN;
}

$oldoutput = `screen -ls`;
}

# Don't run too often - as often as the variable wants - conserves resources
sleep ($time_to_sleep);
}

GaSplat
11-11-2006, 05:52 PM
Truth be told, you really don't need to run mload.sh. Just open a shell and enter these commands (these are the only ones that do anything meaningful in mload.sh)


cd /usr/games/mohaa_tdm

screen -S mohaa_tdm -m -d ./mlds.sh


You might also see if the system help has any entries for the screen command. I don't recall needing to enter a run directory so you might get by with different options or parameters. Bottom line, go to the mohaa directory and screen mlds.sh using whatever options you need. You can always try typing screen -help to see if the built in help can tell you anything. I suspect your screen syntax is different and its can't find the file. I have no clue why mload.sh won't run. You do have BASH installed as your shell, right? Many systems default to that. Try typing BASH (or bash - Linux is case sensitive) and see if that opens a different shell. If it does, then run your script from the new shell.

Nat_Greene
11-13-2006, 09:23 AM
I did search and realized that many Linux distros don't come with the Screen utility installed. To install I keyed yum install screen (as SU) and it installed the screen utility. Go figure. Thanks for your help, I'll see how it works from here. BTW Fedora Core5 uses bash as it's default shell and I use gnome-terminal to access it.

GaSplat
11-14-2006, 12:17 AM
No screen???!!!!!:eek::confused::rolleyes: Screen is da bomb.

That should definitely help solve the problem.

Nat_Greene
11-17-2006, 11:23 AM
Well, I was able to get the mload.sh script to load and also the mlds.sh script. The good news is that the server keeps running regardless of whether I'm logged in. The problem I'm having now is that the screen window still does not pop up and I can't control the server using gnome-terminal (bash). :rolleyes: I figured out that I can shut it down by just killing the screen process.

GaSplat
11-18-2006, 03:58 AM
scope out the docs on screen more.

man screen <- old school way

As long as you are logging back on with the same account that launched it, you should be able to reconnect to your server. I think the command is something like screen -r to reattach.

Nat_Greene
11-18-2006, 01:41 PM
Thanks G-splat for the help! The screen -r command did the trick.

Any thoughts on the renice command in the loop script or a seperate script to devote more power to the server? The reason I want to do this is that 'm running the mohaa server on an old Dell Poweredge 2550 with a 1.2 GHz processor, 1 GB of ram and a 133MHz FSB. The server does nothing but run mohaa and that small FSB has me worried so I just wanted to devote as much power as possible to the game.

Thanks! :cool:

GaSplat
11-19-2006, 12:24 AM
This has a lot of really useful info (http://en.wikipedia.org/wiki/Special:Search?search=nice+priority+linux&fulltext=Search). Note that if you are not root, your priority setting may be limited from 0 (highest) to 19 (lowest). If you are root, then -20 is the highest priority. ) may well be high enough. I would not run a program higher than -5. You don't want to preempt standard system programs.

Nat_Greene
11-22-2006, 12:47 PM
Thanks GaSplat.

I am root (here me roar ;))so that's not a problem. I'm able to renice the process once it's running. As SU I just key renice -10 -p ##### (process number) and that works fine. I'm just totally inexperienced at actual script writing so I was asking for help on actually incorporating the renice command into the looping script. And if that's not possible I was just looking for some help writing a seperate script to handle the renice.

Thanks! :D

GaSplat
11-23-2006, 04:30 PM
Edit your mlds.sh like this

nice --adjustment=-10 ./mohaa_lnxded +set sv_chatter 1 +set developer 1 +exec servertest.cfg

Currently this line should be in your mlds.sh. Replace it with

According to the nice man page, that should result in its running at 0 priority. http://www.netadmintools.com/html/1nice.man.html

You can always just type nice to see what the current priorities are.

Good luck.

Nat_Greene
11-23-2006, 11:26 PM
I will give it a try. Thanks! :)