Check if Bot is running (Linux)

Back to PHP-IRC Feature Requests

Page: 1  
From User Message Body
hery
Post #818
Member
Date: 11:00 am, Sep 26 2008
Posts: 15


Just if you might need

The checkbot.sh file can be put in crontab every 10 min

First create a bot.sh file to run bot.php

bot.sh

Code

#!/bin/bash
cd /home/your_bot_folder
php5 bot.php bot.conf > /dev/null & 
PID=$! 
echo $PID > /home/your_bot_folder/php-irc.pid


then


checkbot.sh

Code


#!/bin/sh
# Check if bot is runing then exit otherwise restart
# in crontab
# 0,10,20,30,40,50 * * * * /home/your_bot_folder/checkbot.sh


MYPATH=/home/your_bot_folder/ 

PID=0

if test -r $MYPATH/php-irc.pid; then
    PID=$(cat $MYPATH/php-irc.pid)
fi

if [ 0 -ne $PID ]; then
    running=`ps --pid $PID | grep $PID |wc -l` 

    if [ $running -eq 1 ]; then
        exit 1 
    fi
fi

cd $MYPATH
./bot.sh & >/dev/null


   

Back to PHP-IRC Feature Requests