Hi TmR
Thanks for posting this centos friendly script :-) I've been looking for one for a while. Have you played around with daemonizing this script so it can be run at startup as a different user? I'm told that running it as root isn't a good idea.
BR
Toffees
*EDIT* Managed to create a simple startup script that runs the bot as the b3 user in the background. Still have some work to do on error checking, but it works. Make sure your log files are owned by the b3 user that is used to run the process, otherwise you will see errors in the b3/logs/b3.bf3.start.log
#!/bin/bash
# chkconfig: 235 99 98
# description: Start and stop b3 bot
# B3 Bot
########### SETTINGS | ############
. /etc/rc.d/init.d/functions
B3_CONFIG="/home/b3/b3/conf/b3.bf3.xml"
B3_RUN="/home/b3/b3_run.py"
## where the python binary is located
PYTHON_BIN=/usr/bin/python
########### SETTINGS END ############
case "$1" in
start)
echo -n "Starting B3 for BF3: "
daemon --user=b3 "python $B3_RUN $B3_CONFIG > /home/b3/logs/b3.bf3.start.log 2>&1 &"
sleep 7
echo "b3 for BF3 is running (PID: `ps ax |grep b3|grep bf3|grep Sl|awk '{print $1;}'`)"
;;
stop)
echo -n "Stopping b3 for BF3: `ps ax |grep b3|grep bf3|grep Sl|awk '{print $1;}'`"
kill -9 `ps ax |grep b3|grep bf3|grep Sl|awk '{print $1;}'`
echo
;;
status)
echo
PID=`ps ax |grep b3|grep bf3|grep Sl|awk '{print $1;}'| wc -l`
if [ $PID -gt 0 ]; then
echo "b3 for BF3 is running (PID: `ps ax |grep b3|grep bf3|grep Sl|awk '{print $1;}'`)"
else
echo "b3 for BF3 is not running"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit 0
I'm having to sleep the script for 7 seconds whilst b3 starts in order that I can grab the process ID. I'm sure there's a better way to do this, but I'm a newbie at bash scripts :-)