You are here: Big Brother Bot ForumAdd-OnsConfigurations (Moderator: MordyT)bash script to start/stop/restart b3
Pages: [1] 2 3   Go Down
  Print  
Author Topic: bash script to start/stop/restart b3  (Read 9810 times) Bookmark and Share
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3483
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« on: July 29, 2008, 10:59:14 AM »

Hi

This is the script I use to start my b3 bot from linux.
It makes sure b3 is not already running before starting and does not kill the bot when you leave the console.

Note: I don't know is this work if you installed B3 as an egg.

Usage :
./bigbrotherbot <start|stop|restart|status>

when started, python does not give you back the console, so just hit the Enter Key to get it back. Then you can quit the console safely.


Copy/paste the following code into a file called 'bigbrotherbot' and make it executable (chmod +x bigbrotherbot)
Code:
#!/bin/bash

########### SETTINGS  ############

## the user that must be used to run the bot
USER=b3

## the big brother bot main config file
B3_CONFIGFILE="/home/urt/b3conf/b3.xml"

## where b3_run.py is located
B3_BIN="/home/urt/b3_run.py"

## where the python binary is located
PYTHON_BIN=/usr/bin/python

########### SETTINGS END ############

set -e
DEBUG=off
B3_OPTS="--config $B3_CONFIGFILE"
B3_PID_FILE="${HOME}/.b3-$(echo $B3_CONFIGFILE | tr '/' '_').pid"

if [ ! -f "$B3_CONFIGFILE" ]; then
  echo "ERROR: config file not found ($B3_CONFIGFILE)"
  exit 1
fi


if [ ! -f "$B3_BIN" ]; then
  echo "ERROR: file not found : '$B3_BIN'"
  exit 1
fi
if [ ! -x "$B3_BIN" ]; then
  echo "ERROR: cannot execute '$B3_BIN'"
  exit 1
fi
if [ ! -f "$PYTHON_BIN" ]; then
  echo "ERROR: file not found : '$PYTHON_BIN'"
  exit 1
fi
if [ ! -x "$PYTHON_BIN" ]; then
  echo "ERROR: cannot execute '$PYTHON_BIN'"
  exit 1
fi

if [ "$(whoami)" != "$USER" ]; then
echo "ERROR: you have to run that script as $USER"
exit 1
fi


function debug() {
if [ "$DEBUG" = "on" ]; then
echo DEBUG: $@
fi
}


function do_start {
cd $(dirname $B3_BIN)
$PYTHON_BIN $B3_BIN $B3_OPTS &
echo $! > $B3_PID_FILE
}

function do_stop {
NB_PROCESS=`ps ax | grep b3_run | grep "$B3_CONFIGFILE" | grep -v grep | wc -l`
if [ $NB_PROCESS -gt 1 ]; then
echo "ERROR: multiple b3 processes found, you'd better kill thoses processes by hand."
elif [ $NB_PROCESS -eq 1 ]; then
if [ -f $B3_PID_FILE ]; then
PID=$(cat $B3_PID_FILE)
NB_PROCESS=`ps hax $PID | grep b3_run | grep "$B3_CONFIGFILE" | grep -v grep | wc -l`
if [ $NB_PROCESS -eq 1 ]; then
kill -15 $PID
else
echo "ERROR: process N° $PID does not seem to be b3"
echo "kill b3 by hand"
fi
fi
else
echo "WARNING: are you sure b3 is running ?"
fi
}


kill_programme() {
        PID=`ps hax | grep "b3_run" | grep "$B3_CONFIGFILE" | grep -v grep | cut -d' ' -f1 | head -n1`
        echo "killing process [$PID]"
        kill -9 $PID
}


case "$1" in
  start)
echo "Starting Big Brother Bot"
NB_PROCESS=`ps ax | grep b3_run | grep "$B3_CONFIGFILE" | grep -v grep | wc -l`
if [ $NB_PROCESS -eq 0 ]; then
do_start
else
echo "ERROR: b3 is already running"
fi
;;
  stop)
echo -n "Stopping Big Brother Bot"
do_stop
echo "."
;;

  restart)
        echo -n "Restarting Big Brother Bot"
do_stop
sleep 1
do_start
;;

status)
debug "status:"
NB_PROCESS=`ps ax | grep b3_run | grep "$B3_CONFIGFILE" | grep -v grep | wc -l`
debug "NB_PROCESS: $NB_PROCESS"
if [ $NB_PROCESS -gt 1 ]; then
echo "WARNING: multiple b3 processes found !"
elif [ $NB_PROCESS -eq 1 ]; then
echo "running :)"
else
echo "not running :("
fi
;;

kill)
kill_programme
;;
  *)
PROG_NAME=`basename $0`
echo "Usage: $PROG_NAME {start|stop|restart|status}"
exit 1
esac

exit 0



« Last Edit: September 12, 2008, 12:25:40 AM by xlr8or » Logged


[ www.xlrstats.com ]
Project Lead
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: CoD, CoD2, CoD5, UrT
Posts: 2022
Offline Offline
WWW
Support Specialty: B3-Core, CoD/UrT/WoP/ETPro parsers, Plugin development
« Reply #1 on: July 29, 2008, 11:52:24 PM »

I'm using a very small restarter script from within screen. It automatically restarts the server/bot when it crashes (not when it hangs tho).

http://www.snt.utwente.nl/wiki/Howto_Server_Restarter

When you have multiple accounts that should be able to access the running processes for the gameserver and/or bot we have a more comprehensive set of scripts available, but it is quite a hassle to set it up. Interested how it looks? Take a look here: http://www.snt.utwente.nl/wiki/Howto_StartStopScripts
Logged

Jr. Member
**
Posts: 17
Offline Offline
« Reply #2 on: July 30, 2008, 10:02:00 AM »

Hi

This the script I use to start my b3 bot from linux.
It makes sure b3 is not already running before starting and does not kill the bot when you leave the console.



Tomdesinto,

I just wanted to thank you for your script.  You have completely solved my b3 issues of having to manually restart it once a day.  Thank you again!
« Last Edit: July 30, 2008, 02:50:36 PM by ThorN » Logged
Jr. Member
**
Posts: 17
Offline Offline
« Reply #3 on: July 30, 2008, 10:02:37 AM »

Can we sticky this???
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3483
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #4 on: July 30, 2008, 10:05:21 AM »

Cheesy glad it help you ...
« Last Edit: July 30, 2008, 11:32:24 AM by Courgette » Logged

Newbie
*
Posts: 1
Offline Offline
« Reply #5 on: December 03, 2008, 11:55:27 PM »

Is there anything similar for windows?
Logged
B3 Contrib/Support
*
OS: --No B3 installed--
Type: --No B3 installed--
Posts: 1225
Offline Offline
Support Specialty: B3-Core, CoD/BFBC2 parsers, FTP-functionality, Plugin development
« Reply #6 on: December 04, 2008, 09:36:35 AM »

not that I know of, but a quick autorestart script:
Code:
:TOP
path-to-b3_run eg C:\b3\b3_run.py
GOTO TOP
that will restart it
otherwise you could use firedaemon to do that for you.
Logged

Beta Testers
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: BF3,Cod2,Cod4,Cod5,Cod6,Cod7
Posts: 257
Offline Offline
WWW
« Reply #7 on: November 28, 2010, 02:54:27 PM »

Nice Script, but the Ingame Command !restart kills BB is there an Option do put --restart in the script?

LG
Logged

Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3483
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #8 on: November 28, 2010, 03:23:19 PM »

just set
Code:
B3_OPTS="--config $B3_CONFIGFILE --restart"
Logged

Moderator
*
OS: Windows
Type: Gameserver Rental Co.
Gameservers: 2x CoD4, 1x BF3
Posts: 2625
Offline Offline
Owner of Host4B3.com - Over 70 bots hosted!
WWW
« Reply #9 on: December 26, 2010, 01:45:30 AM »

Trying to implement this but small issue: error: cannot execute b3_run.py
Logged

Need B3 Bot hosting? Check out Host4B3.com
Check Twitter.com/Host4B3 for updates if the site it down.

Help will be given to those with a b3.log

System: Python 2.7.1 - B3 Source Code - Locally hosted MySQL & Apache - Win 2k3
Jr. Member
**
OS: --No B3 installed--
Type: --No B3 installed--
Gameservers: BFBC2
Posts: 42
Offline Offline
« Reply #10 on: January 22, 2011, 09:42:35 PM »

Trying to implement this but small issue: error: cannot execute b3_run.py

Same here, path is definately correct.
« Last Edit: January 22, 2011, 09:45:48 PM by epiacum » Logged
Jr. Member
**
OS: Linux
Type: Renting Server, no B3
Gameservers: Black Ops
Posts: 29
Offline Offline
« Reply #11 on: February 16, 2011, 12:04:29 PM »

@ mordy chmod u+x b3_run.py 

the chmod should be imported into the script. at least check 4 it.
Logged
Moderator
*
OS: Windows
Type: Gameserver Rental Co.
Gameservers: 2x CoD4, 1x BF3
Posts: 2625
Offline Offline
Owner of Host4B3.com - Over 70 bots hosted!
WWW
« Reply #12 on: February 16, 2011, 12:43:33 PM »

@ mordy chmod u+x b3_run.py 

the chmod should be imported into the script. at least check 4 it.
Will try and let you know. Thanks for the help!
Logged

Need B3 Bot hosting? Check out Host4B3.com
Check Twitter.com/Host4B3 for updates if the site it down.

Help will be given to those with a b3.log

System: Python 2.7.1 - B3 Source Code - Locally hosted MySQL & Apache - Win 2k3
Jr. Member
**
OS: --No B3 installed--
Type: --No B3 installed--
Gameservers: BFBC2
Posts: 42
Offline Offline
« Reply #13 on: February 16, 2011, 01:09:06 PM »

Thanks, Im getting this :

ERROR: you have to run that script as b3
Logged
Full Member
***
OS: Windows
Type: Renting Server, no B3
Gameservers: CoD7
Posts: 75
Offline Offline
« Reply #14 on: March 04, 2011, 03:42:36 AM »

Thanks, Im getting this :

ERROR: you have to run that script as b3
you should make a user called b3 i think, or change
Code:
## the user that must be used to run the bot
USER=b3
to your unix username (not really safe to use root imho)
-edit-
hm i couldnt change it to my user, so  i did use root.
Gonna reboot now
-edit2-
works like a charm (using 3 b3 bots so far)
« Last Edit: March 04, 2011, 05:54:53 AM by TmR » Logged


Tags:
Pages: [1] 2 3   Go Up
  Print  
 
Jump to:  


Rate this page +1 at Google Search


SimplePortal 2.3.1 © 2008-2009, SimplePortal