collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Need Bebot To Start When Server Starts  (Read 11174 times)

0 Members and 1 Guest are viewing this topic.

Offline seknetari

  • BeBot User
  • **
  • Posts: 43
  • Karma: +0/-0
Need Bebot To Start When Server Starts
« on: February 26, 2012, 08:09:33 pm »
I've followed the instructions below to the best of my abilities. When I reboot the Ubuntu (11.10) server, I get the login prompt and nothing else. The bot is not running in the background. When I input my login info and password, I get the general $ prompt. And if I put "screen -r" I get the message that "There is no screen to be resumed."

Below, in the instructions, it says to make two script files. What should the script file extensions be? .sh? .php? Or something else? Following the directions I did not put an extension, maybe I was supposed to?

Wolf, your advice contains alot of inorrect stuff (prob old )
the main file is StartBot.php
it supports multi bots useing php StartBot.php botname

anyway this is how i have done it

ok this is the system i use

My script works well with multi bots useing screens

for starter i have a script file in the root directory of the bot folder
/home/Bots/all/ being the folder your bot is in

start_botname
Code: [Select]
cd /home/Bots/all/; su -c "php StartBot.php leetboss" Bots
Where Bots is the user that owns/runs the bots

then in etc/init.d/ i got the file names Botname
Code: [Select]
#!/bin/sh

case "$1" in
'start')
screen -dmS botname -s /home/Bots/all/start_botname
;;
'stop')
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
exit 0

and ive done that for each bot i run.

I have also tried these instructions with no luck either:
http://bebot.link/bebot-0-4-support/bebot-on-linux-vserver-absolute-beginner-here/

Any help with getting my bot to start when Linux boots up would be greatly appreciated.

-Sek

PS. FYI - this is my own Linux box in my house.

Offline Shelly

  • BeBot Apprentice
  • ***
  • Posts: 192
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #1 on: February 26, 2012, 08:42:30 pm »
I would not recommend running your bot as root. If you launch it from the /etc/init.d folder... it will be running as root.

I suggest creating a regular user to run the bots as. I use "botrunner" to run my bots. :)

I set up a *user* crontab entry that runs every 10 minutes that checks to see if the bot is running.
Code: [Select]
#Bot's Cron
# Check for running bots and start them if needed.
*/10 * * * * /home/bot/StartBots 2&>1 >/dev/null

The StartBots is a script to call the start scripts for the bots I run:
Code: [Select]
#!/bin/bash

/home/bot/start_bot1
sleep 5

/home/bot/start_bot2
sleep 5

/home/bot/start_bot3
sleep 5

/home/bot/start_bot4
sleep 5

/home/bot/start_bot5
sleep 5

## EOF

Each start_bot script really does all the work...
start_bot1:
Code: [Select]
#!/bin/bash
 
#
##
### Check for AO Bots and restart if necessary
##
#
# This script looks to see if your bot is actually running and does nothing if it is
# already running.
# If it is not running, it will email you the previous log, then compress it to concerve space.
#
# You will need to change "bot1" to the name of your bot.
#
# The BOT* items you will need to configure for your bot.
BOTHOME="/home/bot/RaidBots"
BOTNAME="bot1"
BOTLOGS="/home/bot"
BOTLOG_Archive=${BOTLOGS}/logs

mdate=`date +%b-%d-%Y`;
hdate=`date +%b-%d-%Y_%H%M_hrs`;

z=`ps -ef |grep ${BOTNAME} |grep -v grep`;
if [[ $z == "" ]]
then {
  # comment this next line out if you don't want the previous log emailed to you.
  mailx -s "Starting ${BOTNAME} bot " [email protected] <${BOTLOGS}/${BOTNAME}.log ;
  if [ -e "${BOTLOGS}/${BOTNAME}.log-${mdate}.gz" ]
  then {
    mv ${BOTLOGS}/${BOTNAME}.log ${BOTLOG_Archive}/${BOTNAME}.log-${mdate};
    /bin/gzip ${BOTLOG_Archive}/${BOTNAME}.log-${mdate};
  }
  else {
    mv ${BOTLOGS}/${BOTNAME}.log ${BOTLOG_Archive}/${BOTNAME}.log-${hdate};
    /bin/gzip ${BOTLOG_Archive}/${BOTNAME}.log-${hdate};
  };
  fi
  cd ${BOTHOME}; /usr/bin/php -f ${BOTHOME}/StartBot.php ${BOTNAME} 2>&1 > ${BOTLOGS}/${BOTNAME}.log &
}
fi

#EOF

Then if you want to monitor what is happening with the bot...

Code: [Select]
tail -f Bot1.log
I personally like this method better than the screen one... It seems simpler to use this method to me.

Make sure you "chmod 750 StartBots start_bot1" they need to be executable.

Also... this thread gives a lot of help on this topic also --> http://bebot.link/helpful-posts/bot-check-on-linux/

Shelly
« Last Edit: February 29, 2012, 12:24:30 pm by Shelly »

Offline seknetari

  • BeBot User
  • **
  • Posts: 43
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #2 on: February 26, 2012, 10:00:47 pm »
Thx Shelly! I'll give this a try.
-Sek

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Need Bebot To Start When Server Starts
« Reply #3 on: February 26, 2012, 11:19:09 pm »
In addition you could add another cronjob that will run upon reboot
Code: [Select]
@reboot /home/bot/StartBots 2&>1 >/dev/null

This will allow the bot to potentially start faster on reboot. I recommend running it in addition to the 10 minute cronjob which will catch any crashes and restart the bot.
BeBot Founder and Fixer Kingpin

Offline seknetari

  • BeBot User
  • **
  • Posts: 43
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #4 on: February 28, 2012, 06:08:27 am »
Thank you very much for the help. I am learning as I go and I am finding Linux to be quite interesting.

I have another question. Will the bot start on reboot even if I have to login? OR do I need to make some changes to my system that allow for it to log me in automatically?

-Sek

Offline Shelly

  • BeBot Apprentice
  • ***
  • Posts: 192
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #5 on: February 29, 2012, 12:20:45 pm »
Thank you very much for the help. I am learning as I go and I am finding Linux to be quite interesting.
Linux is fun :)

I have another question. Will the bot start on reboot even if I have to login? OR do I need to make some changes to my system that allow for it to log me in automatically?
Setting it up like Khalem and I have suggested ... you do not need to login. It will start automatically.

Shelly
« Last Edit: February 29, 2012, 12:25:38 pm by Shelly »

Offline seknetari

  • BeBot User
  • **
  • Posts: 43
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #6 on: March 05, 2012, 05:12:09 am »
I followed the instructions above and the bot is not starting. Is there something wrong with my code? Here is what I have...

Here is my start_bot1 file:
Code: [Select]
#!/bin/bash

#
##
### Check for AOC Bots and restart if necessary
##
#
# This script looks to see if your bot is actually running and does nothing if it is
# already running.
# If it is not running, it will email you the previous log, then compress it to concerve space.
#
# You will need to change "bot1" to the name of your bot.
#
# The BOT* items you will need to configure for your bot.
BOTHOME="/home/kevin-0/Bots/bebot"
BOTNAME="Rosy"
BOTLOGS="/home/bot"
BOTLOG_Archive=${BOTLOGS}/logs

mdate=`date +%b-%d-%Y`;
hdate=`date +%b-%d-%Y_%H%M_hrs`;

z=`ps -ef |grep ${BOTNAME} |grep -v grep`;
if [[ $z == "" ]]
then {
# comment this next line out if you don't want the previous log emailed to you.
mailx -s "Starting ${BOTNAME} bot " [email protected] <${BOTLOGS}/${BOTNAME}.log ;
if [ -e "${BOTLOGS}/${BOTNAME}.log-${mdate}.gz" ]
then {
mv ${BOTLOGS}/${BOTNAME}.log ${BOTLOG_Archive}/${BOTNAME}.log-${mdate};
/bin/gzip ${BOTLOG_Archive}/${BOTNAME}.log-${mdate};
}
else {
mv ${BOTLOGS}/${BOTNAME}.log ${BOTLOG_Archive}/${BOTNAME}.log-${hdate};
/bin/gzip ${BOTLOG_Archive}/${BOTNAME}.log-${hdate};
};
fi
cd ${BOTHOME}; /usr/bin/php -f ${BOTHOME}/StartBot.php ${BOTNAME} 2>&1 > ${BOTLOGS}/${BOTNAME}.log &
}
fi

#EOF

Here is my StartBots file:
Code: [Select]
#!/bin/bash

/home/kevin-0/Bots/bebot/start_bot1
sleep 5

## EOF

And here is what I put into my crontab file. The original # text is there, and I added:
Code: [Select]
#Bot's Cron
# Check for running bots and start them if needed.
*/10 * * * * /home/kevin-0/Bots/bebot/StartBots 2&>1 >/dev/null
@reboot /home/kevin-0/Bots/bebot/StartBots 2&>1 >/dev/null

I ran chmod 750 on the two files too.

I'm not sure what I am missing?
-Sek

Offline Getrix

  • Contributor
  • *******
  • Posts: 509
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #7 on: March 05, 2012, 07:03:18 am »
Did you make sure to append cronlines to crontab?

"crontab -l" will list currently added stuff to crontab

"crontab _CRONFILE_" will add lines from _CRONFILE_ into crontab. This will overrun stuff that allready is in crontab if you have, so make sure you dont have any lines from before. If you do add them to _CRONFILE_ before doing "crontab _CRONFILE_"

2ndly, +x on the two files should be good.
You can also try to alter your cron with adding /bin/bash before file

Quote
#Bot's Cron
# Check for running bots and start them if needed.
*/10 * * * * /bin/bash /home/kevin-0/Bots/bebot/StartBots 2&>1 >/dev/null
@reboot /bin/bash /home/kevin-0/Bots/bebot/StartBots 2&>1 >/dev/null
« Last Edit: March 05, 2012, 07:05:10 am by Getrix »
Success is not final, failure is not fatal: it is the courage to continue that counts.
- Sorry, i dont have time to reply question on PM. Make a topic.

Offline seknetari

  • BeBot User
  • **
  • Posts: 43
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #8 on: March 06, 2012, 04:14:26 am »
Did you make sure to append cronlines to crontab?

"crontab -l" will list currently added stuff to crontab

"crontab _CRONFILE_" will add lines from _CRONFILE_ into crontab. This will overrun stuff that allready is in crontab if you have, so make sure you dont have any lines from before. If you do add them to _CRONFILE_ before doing "crontab _CRONFILE_"

2ndly, +x on the two files should be good.
You can also try to alter your cron with adding /bin/bash before file

Still not working and starting to drive me nuts.  ???

I did all of the above suggestions except add /bin/bash before the file. I'm not sure where you want me to put the /bin/bash. It is in the crontab already.

I only have one user on the system (kevin-0 seen above). I never added any users since this machine is only for Bebot. My bot is already running under kevin-0 if I do it manually. Could this have something to do with it?

Should the StartBots and start_bot1 files be in the same directory as Bebot?

Thanks again for your help.

Offline Getrix

  • Contributor
  • *******
  • Posts: 509
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #9 on: March 06, 2012, 06:50:52 am »
Type:
Code: [Select]
crontabl -l and post result here.

If you type
Code: [Select]
/bin/bash /home/kevin-0/Bots/bebot/StartBots what happen?

EDIT:
Change:
Code: [Select]
BOTLOGS="/home/bot"
To :
Code: [Select]
BOTLOGS="/home/kevin-0/Bots" or another path you have access to..
« Last Edit: March 06, 2012, 08:06:07 am by Getrix »
Success is not final, failure is not fatal: it is the courage to continue that counts.
- Sorry, i dont have time to reply question on PM. Make a topic.

Offline seknetari

  • BeBot User
  • **
  • Posts: 43
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #10 on: March 06, 2012, 12:25:33 pm »
Type:
Code: [Select]
crontabl -l and post result here.

Here is what I get (/bin/bash was not there, I put it in, and it still doesn't work):
Code: [Select]
#Bot's Cron
# Check for running bots and start them if needed.
*/10 * * * * /bin/bash /home/kevin-0/Bots/StartBots 2&>1 >/dev/null
@reboot /bin/bash /home/kevin-0/Bots/StartBots 2&>1 >/dev/null

If you type
Code: [Select]
/bin/bash /home/kevin-0/Bots/bebot/StartBots what happen?

"Permission denied" was the response. :(
 
I think we just found the problem. I have done chmod 750 on both files. What else do I need to do to allow permissions?


Offline Getrix

  • Contributor
  • *******
  • Posts: 509
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #11 on: March 06, 2012, 03:26:19 pm »
If you use "/bin/bash /home/kevin-0/Bots/StartBots" default permission should be enough..

Try with chmod 755 and if thats not working, try chmod +x file
Success is not final, failure is not fatal: it is the courage to continue that counts.
- Sorry, i dont have time to reply question on PM. Make a topic.

Offline seknetari

  • BeBot User
  • **
  • Posts: 43
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #12 on: March 07, 2012, 12:37:30 am »
Alright, I did that. Now I get this message:
: No such file or directorys: line 2: /home/kevin-0/Bots/start_bot1

I have checked and double checked. The start_bot1 file is there. Any ideas? I don't understand it.

Thank you again for your help and to everyone before you. I have been researching your suggestions along the way and learning quite a bit.
-Sek

Offline Shelly

  • BeBot Apprentice
  • ***
  • Posts: 192
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #13 on: March 07, 2012, 03:24:00 am »
do "find / -name bash - print"

Looks like your bash is not in the standard location... or the user account you are running your bot under does not have access to it.

Also... remove the command "/bin/bash" before the "/home/kevin-0/Bots/StartBots" in your crontab. The 1st line in the scripts tell it where to find the bash interpreter. You will need to adjust the 1st line of the scripts depending on what you find in the above command.

Shelly
« Last Edit: March 07, 2012, 03:28:45 am by Shelly »

Offline seknetari

  • BeBot User
  • **
  • Posts: 43
  • Karma: +0/-0
Re: Need Bebot To Start When Server Starts
« Reply #14 on: March 07, 2012, 04:14:29 am »
I found bash in /bin/bash and three other results also showed. When I first used the "find" command, I received many permission denied messages. So I used "sudo" to get the 4 results.

 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 455
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal