<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3ARestartScript</id>
	<title>Scripts:RestartScript - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3ARestartScript"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:RestartScript&amp;action=history"/>
	<updated>2026-08-06T01:09:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://bf2tech.uturista.pt/index.php?title=Scripts:RestartScript&amp;diff=130&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;__TOC__ =  Server Restart Script (Linux Only)  =  The two scripts underneath are to be used in combination. These have as purpose to re-run the Battlefield 2 Dedicated Server...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:RestartScript&amp;diff=130&amp;oldid=prev"/>
		<updated>2018-06-22T15:36:50Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__ =  Server Restart Script (Linux Only)  =  The two scripts underneath are to be used in combination. These have as purpose to re-run the Battlefield 2 Dedicated Server...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
=  Server Restart Script (Linux Only)  =&lt;br /&gt;
&lt;br /&gt;
The two scripts underneath are to be used in combination. These have as purpose to re-run the Battlefield 2 Dedicated Server when it crashes or quits.&lt;br /&gt;
&lt;br /&gt;
==  startit.sh  ==&lt;br /&gt;
&lt;br /&gt;
This script initializes the servermonitor script in a screen. If you wish to run multiple server instances you need to change &amp;#039;screenname&amp;#039; to a different name.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;NOTE: Make sure to change /path/to/bf2 to your bf2 install dir!!!&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
&lt;br /&gt;
screen -dmS screenname /path/to/bf2/servermonitor&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==  /path/to/bf2/servermonitor  ==&lt;br /&gt;
&lt;br /&gt;
This script constantly runs to check wheter the server still runs and restarts it when it doesnt run anymore.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;NOTE: Make sure to change /path/to/bf2 to your bf2 install dir!!!&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The only line needed to be changed will be &amp;#039;exec=/path/to/bf2/start.sh&amp;#039; (line 4)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
&lt;br /&gt;
#full path to the start script for the process you want to monitor&lt;br /&gt;
exec=/path/to/bf2/start.sh&lt;br /&gt;
&lt;br /&gt;
#interval the script checks to see if the process is still running&lt;br /&gt;
interval=10&lt;br /&gt;
&lt;br /&gt;
while :&lt;br /&gt;
do&lt;br /&gt;
pid=$(ps ax | grep bf2 | grep bin | grep -v grep | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
echo $pid&lt;br /&gt;
if [ -z &amp;quot;$pid&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
date &amp;gt;&amp;gt; restartlog&lt;br /&gt;
echo $procName has stopped!!!! Starting $procName!!!! &amp;gt;&amp;gt; restartlog&lt;br /&gt;
echo &amp;quot; &amp;quot;&lt;br /&gt;
echo &amp;quot; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
$exec&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
sleep $interval&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=  Made By  =&lt;br /&gt;
&lt;br /&gt;
These scripts where delivered to me by David Stevens and according to him they have been build by Rene Belloq.&lt;br /&gt;
&lt;br /&gt;
--Mortis 13:05, 11 Jul 2005 (MDT)&lt;br /&gt;
&lt;br /&gt;
=  Addendum  =&lt;br /&gt;
&lt;br /&gt;
Just copying the scripts above did not work for me on an actual Linux dedicated server with SuSE 10.2 running.&lt;br /&gt;
&lt;br /&gt;
You should now that i wanted to use them for our BF2 server running the AIX mod on it.&lt;br /&gt;
&lt;br /&gt;
First: I used as screenname &amp;quot;AIXMOD&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
&lt;br /&gt;
screen -dmS AIXMOD /path/to/bf2/servermonitor&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But &amp;quot;servermonitor&amp;quot; did not work, because the command for calling BF2 with the Mod parameter &amp;quot;exec=/path/to/bf2/start.sh +modPath mods/aix&amp;quot; is not known by the bash. Try to use a line calling it the way the shell can handle it instead:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
 &lt;br /&gt;
#full path to the start script for the process you want to monitor&lt;br /&gt;
exec=&amp;#039;./start.sh +modPath mods/aix +ignoreAsserts +fileMonitor 1&amp;#039;&lt;br /&gt;
&lt;br /&gt;
#interval the script checks to see if the process is still running&lt;br /&gt;
interval=10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
O.K., finally &amp;quot;servermonitor&amp;quot; started the BF2 server with the AIX mod. But then, the next &amp;quot;problem&amp;quot;: After the BF2 server crashed, the &amp;quot;servermonitor&amp;quot; did just a loop, always writing into the &amp;quot;restartlog&amp;quot; that the server is restarting. Again and again, but the server did not come up again. A short &amp;quot;ps x | grep bf2&amp;quot; showed why:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
11743 ?        S      0:00 sshd: bf2server@notty&lt;br /&gt;
11804 ?        S      0:00 sshd: bf2server@pts/1&lt;br /&gt;
11982 ?        Ss     0:00 SCREEN -dmS AIXMOD /home/bf2server/bf2/servermonitor&lt;br /&gt;
11983 pts/2    Ss+    0:00 /bin/sh /home/bf2server/bf2/servermonitor&lt;br /&gt;
11984 pts/2    Rl+    4:38 /home/bf2server/bf2/bin/amd-64/bf2 +modPath mods/aix&lt;br /&gt;
12328 pts/1    S+     0:00 grep bf2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script finds way too many pids, if you install your server files e.g. into a directory called &amp;quot;bf2&amp;quot; (as we did). So we checked the default grep command of the script and got 2 pids:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
bf2server@s15259444:~/bf2&amp;gt; ps x | grep bf2 | grep bin | grep -v grep | awk &amp;#039;{print $1}&amp;#039;&lt;br /&gt;
11983&lt;br /&gt;
11984&lt;br /&gt;
bf2server@s15259444:~/bf2&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One of the &amp;quot;servermonitor&amp;quot; itself (pid:11983) and one of the BF2 server running (pid:11984). In order to get just the &amp;quot;interesting&amp;quot; pid we changed the grep command towards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
bf2server@s15259444:~/bf2&amp;gt; ps x | grep bf2 | grep bin | grep -v grep | grep -v servermonitor | awk &amp;#039;{print $1}&amp;#039;&lt;br /&gt;
11984&lt;br /&gt;
bf2server@s15259444:~/bf2&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You see ^^, now we get only the pid of the &amp;quot;running&amp;quot; BF2 server, if the BF2 server crashes, that pid will be missing and the restart should work as intended. You should have got the principle how it works, change yours accordingly ;) Hope it helps.&lt;br /&gt;
&lt;br /&gt;
I forgot: You can also change the original grep command &amp;quot;grep bf2&amp;quot; towards a call for the part &amp;quot;amd-64&amp;quot; or &amp;quot;ia-32&amp;quot;, depending which you&amp;#039;re using on your running AIX server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
bf2server@s15259444:~&amp;gt; ps x | grep amd-64 | grep bin | grep -v grep | awk &amp;#039;{print $1}&amp;#039;&lt;br /&gt;
11984&lt;br /&gt;
bf2server@s15259444:~&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt; --BlackBears1 10:36, 16 January 2008 (MST)&lt;br /&gt;
&lt;br /&gt;
=  NARS (Not Another Restart Script)  =&lt;br /&gt;
&lt;br /&gt;
This Script has been made to be used under a Linux [http://www.rackaid.com/resources/tips/linux-screen.cfm Screen ]&lt;br /&gt;
&lt;br /&gt;
==  Script  ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# Press Ctrl+C to stop the restarting&lt;br /&gt;
echo &amp;quot;##########################&amp;quot;&lt;br /&gt;
echo &amp;quot;# Bf2 Server Starting #&amp;quot;&lt;br /&gt;
echo &amp;quot;##########################&amp;quot;&lt;br /&gt;
echo To stop the restarting press Ctrl+C when the server is being restarted&lt;br /&gt;
echo&lt;br /&gt;
trap &amp;#039;echo; echo $SRV Server Restarter has been STOPPED!; exit 1&amp;#039; 2&lt;br /&gt;
C1=0&lt;br /&gt;
while true&lt;br /&gt;
do&lt;br /&gt;
C1=$((C1+=1))&lt;br /&gt;
cd /home/bf2srv/bf2&lt;br /&gt;
# Modify the line bellow to match your server execution command line&lt;br /&gt;
./start.sh&lt;br /&gt;
echo &amp;quot;Bf2 server restarted $C1 time(s)!&amp;quot;&lt;br /&gt;
sleep 10&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==  Usage  ==&lt;br /&gt;
&lt;br /&gt;
First, modify the path to the BF2 server directory on the script. Also you can add some extra variables to the ./start.sh script (like modPath or others). Then save the script as, for example, server_start.sh and store it on the bf2 directory.&lt;br /&gt;
&lt;br /&gt;
Do a:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod +x server_start.sh &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, open a new screen (just type screen, then enter), &amp;#039;inside&amp;#039; the screen, go to the BF2 server directory and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./server_start.sh &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The server will start normally, then detach the screen by pressing &amp;#039;CTRL + A&amp;#039; and then &amp;#039;D&amp;#039;, the results must be something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[detached] &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Yo can resume the screen and check the server console by doing a:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r PID &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While PID is the process ID of the screen. If there are no other screen instanses running, you can resume this one using only screen -r&lt;br /&gt;
&lt;br /&gt;
If there is other screens running, the screen -r command will tell you the PIDs of those screens.&lt;br /&gt;
&lt;br /&gt;
===  Notes  ===&lt;br /&gt;
&lt;br /&gt;
This script will restart your server if it crashes or quit. Is very simple on the practice, dont be scared.&lt;br /&gt;
&lt;br /&gt;
--DarkPepe 03:32, 14 May 2006 (MDT)&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>