BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Age of Conan Archive => AoC 0.6.x Custom/Unofficial modules => Topic started by: seknetari on February 26, 2012, 08:09:33 pm

Title: Need Bebot To Start When Server Starts
Post by: seknetari 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/ (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.
Title: Re: Need Bebot To Start When Server Starts
Post by: Shelly 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/ (http://bebot.link/helpful-posts/bot-check-on-linux/)

Shelly
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari on February 26, 2012, 10:00:47 pm
Thx Shelly! I'll give this a try.
-Sek
Title: Re: Need Bebot To Start When Server Starts
Post by: Khalem 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.
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari 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
Title: Re: Need Bebot To Start When Server Starts
Post by: Shelly 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
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari 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
Title: Re: Need Bebot To Start When Server Starts
Post by: Getrix 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
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari 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.
Title: Re: Need Bebot To Start When Server Starts
Post by: Getrix 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..
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari 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?

Title: Re: Need Bebot To Start When Server Starts
Post by: Getrix 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
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari 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
Title: Re: Need Bebot To Start When Server Starts
Post by: Shelly 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
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari 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.
Title: Re: Need Bebot To Start When Server Starts
Post by: Shelly on March 08, 2012, 03:15:40 am
As the user that runs the bot... try "/bin/bash" and see if you get a new shell or an error message.

It really sounds like the bot user does not have access to /bin/bash ... maybe /usr/bin/bash?

If there is no error running /bin/bash... try changing
mailx -s "Starting ${BOTNAME} bot " [email protected] <${BOTLOGS}/${BOTNAME}.log ;

to
#mailx -s "Starting ${BOTNAME} bot " [email protected] <${BOTLOGS}/${BOTNAME}.log ;

If that works then "find / -name mailx" it may not be in the user's normal path. A faster way is also to use "which mailx" as this search only uses the user's known path statement.


Title: Re: Need Bebot To Start When Server Starts
Post by: Getrix on March 08, 2012, 10:49:32 am
: No such file or directorys: line 2: /home/kevin-0/Bots/start_bot1

Are you sure you using the right paths for the script?...

"cat /home/kevin-0/Bots/start_bot1" should give you a output of the file if its correct path..
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari on March 08, 2012, 12:24:29 pm
As the user that runs the bot... try "/bin/bash" and see if you get a new shell or an error message.

It really sounds like the bot user does not have access to /bin/bash ... maybe /usr/bin/bash?

If there is no error running /bin/bash... try changing
mailx -s "Starting ${BOTNAME} bot " [email protected] <${BOTLOGS}/${BOTNAME}.log ;

to
#mailx -s "Starting ${BOTNAME} bot " [email protected] <${BOTLOGS}/${BOTNAME}.log ;

If that works then "find / -name mailx" it may not be in the user's normal path. A faster way is also to use "which mailx" as this search only uses the user's known path statement.

When I type "/bin/bash" I get a new prompt (is that what you mean by "shell"?) [I'm still learning the lingo]. When I type /usr/bin/bash I get an error that it isn't found. Since the /bin/bash command didn't give me an error, I did your second suggestion. I get the same result when I run the script.



: No such file or directorys: line 2: /home/kevin-0/Bots/start_bot1

Are you sure you using the right paths for the script?...

"cat /home/kevin-0/Bots/start_bot1" should give you a output of the file if its correct path..

When I use the cat command, I get the text of the file. I did this with both files just to be sure.

I have a hunch that the "-" in my name may be screwing up the path. Whether it is or isn't, I am thinking of starting over from scratch and re-installing Ubuntu. I think it would be good practice for me too.

When I install Ubuntu again, what suggestions do you have for a clean server install? Should I create a user account and install Bebot there? If I am using the "adduser _NEWUSERNAME_" command, are there any modifications I need to make at this time to get the Bebot to work (permissions?)?

I have been making a modified bebot zip file with all of my scripts and updated Bebot files to make it easier to install the next time. Although my bot works, I do get 4 error messages when it starts. I will start a new thread to address those before I re-install.

Again, I want to stress how thankful I am to Getrix, Shelly, and everyone else that has tried to help me. I realize you are donating your time to help out a stranger and I GREATLY appreciate it. Thank you, thank you, thank you!!
Title: Re: Need Bebot To Start When Server Starts
Post by: Getrix on March 08, 2012, 09:01:44 pm
You can actually try with another user before you reinstall Ubuntu.

sudo adduser USERNAME

Try without any special chars this time, only letter from a to z. Was also thinking if that could be your problem..
You should not need to set special permission, other then password, and set a homedir (/home/username)
Then login with the new user, ex from ssh or local terminal. Download Bebot from start and try from start again.
Title: Re: Need Bebot To Start When Server Starts
Post by: Shelly on March 09, 2012, 02:31:54 am
When I type "/bin/bash" I get a new prompt (is that what you mean by "shell"?) [I'm still learning the lingo].

Yep! That's correct.

BUT!! Don't reinstall yet....

on the first line of your start_bot1 file modify it from:
#!/bin/bash

-to-
#!/bin/bash -vx

Then try to run the script. It should show you everything it is doing. then we can pinpoint the error... hopefully :)

Paste that here if you can.

Shelly
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari on March 11, 2012, 10:44:33 pm
When I type "/bin/bash" I get a new prompt (is that what you mean by "shell"?) [I'm still learning the lingo].

Yep! That's correct.

BUT!! Don't reinstall yet....

on the first line of your start_bot1 file modify it from:
#!/bin/bash

-to-
#!/bin/bash -vx

Then try to run the script. It should show you everything it is doing. then we can pinpoint the error... hopefully :)

Paste that here if you can.

Shelly

Okay, I used the command: "/bin/bash start_bot1" and here is what I get:

Quote
start_bot1: line 2: $'\r': command not found
start_bot1: line 19: $'\r': command not found
start_bot1: line 20: $'\r': command not found
start_bot1: line 21: $'\r': command not found
start_bot1: line 22: $'\r': command not found
start_bot1: line 23: $'\r': command not found
start_bot1: line 24: syntax error in conditional expression
'tart_bot1: line 24: syntax error near ']]
'tart_bot1: line 24: 'if [[ $z == "" ]]

I hope this helps makes sense of what is going on.
-Sek
Title: Re: Need Bebot To Start When Server Starts
Post by: Shelly on March 12, 2012, 02:40:42 am
Okay, I used the command: "/bin/bash start_bot1" and here is what I get:

Quote
start_bot1: line 2: $'\r': command not found
start_bot1: line 19: $'\r': command not found
start_bot1: line 20: $'\r': command not found
start_bot1: line 21: $'\r': command not found
start_bot1: line 22: $'\r': command not found
start_bot1: line 23: $'\r': command not found
start_bot1: line 24: syntax error in conditional expression
'tart_bot1: line 24: syntax error near ']]
'tart_bot1: line 24: 'if [[ $z == "" ]]

I hope this helps makes sense of what is going on.
-Sek

Looks like something got misplaced in your script. Please load this one with your bot details and see if it works.

And I suggest using an editor on your linux machine to edit with. Windows editors are different formats.
Title: Re: Need Bebot To Start When Server Starts
Post by: Glarawyn on March 12, 2012, 04:02:47 pm
Here's how I used to do it with screen. Hope it's helpful.


Code: [Select]
#!/bin/bash

BOTDIR=/home/botrunner/bots

# Start the guild relay bot first.
cd ${BOTDIR}/relaybot
screen -dmS relaybot php StartBot.php
# Wait for relay bot to startup and connect before starting the rest of the guild bots.
sleep 30s

cd ${BOTDIR}/guildbot
screen -dmS guildbot php StartBot.php
cd ${BOTDIR}/partybot
screen -dmS partybot php StartBot.php
cd ${BOTDIR}/dosbott
screen -dmS guildbot2 php StartBot.php


I so rarely rebooted my bot server (it was under my stairs on a good UPS) so I never bothered setting up a start on boot, if I did it would have been an @reboot cron entry.

I created a .screenrc in my botrunner account's home directory.

Code: [Select]
multiuser on
addacl root

And then I had an attach script:
botattach:
Code: [Select]
#!/bin/bash
namereq="root"
name="$LOGNAME"

command="/usr/bin/screen -r $1"

if [ $namereq != $name ];  then
    command="/usr/bin/sudo /usr/local/bin/attach $1"
fi

$command

And the following entries in /etc/sudoers:
Code: [Select]
User_Alias BOTADMINS = user1, user2, user3
# Cmnd alias specification
Cmnd_Alias BOTATTACH = /usr/local/bin/botattach
BOTADMINS ALL = NOPASSWD: ATTACH

So the other admins of Campalot or the various guildbots could log into my Linux server, run botattach botname, and pull up the screen for that bot. There are some security holes there to be sure, but it worked well enough for trusted administrators. Fixing the security issues wasn't important enough to me with trusted bot administrators, the goal was to make it easy to pull up the bot console and restart the bot if need be.
Title: Re: Need Bebot To Start When Server Starts
Post by: Shelly on March 14, 2012, 12:36:11 am
Okay, I used the command: "/bin/bash start_bot1" and here is what I get:

Quote
start_bot1: line 2: $'\r': command not found
start_bot1: line 19: $'\r': command not found
start_bot1: line 20: $'\r': command not found
start_bot1: line 21: $'\r': command not found
start_bot1: line 22: $'\r': command not found
start_bot1: line 23: $'\r': command not found
start_bot1: line 24: syntax error in conditional expression
'tart_bot1: line 24: syntax error near ']]
'tart_bot1: line 24: 'if [[ $z == "" ]]

I hope this helps makes sense of what is going on.
-Sek

Actually... I bet you edited the script with Notepad and then copied it to your bot... :) Try using "
Code: [Select]
dos2unix start_bot1"

I have a feeling that will fix your original start script. :)

Oh and... you don't need the "/bin/bash " in front of your script. If you are in the bot's home folder just "
Code: [Select]
./start_bot1" should do it.

Shelly
Title: Re: Need Bebot To Start When Server Starts
Post by: seknetari on March 15, 2012, 03:21:52 am
Hi Shelley. I hope you are right. I haven't had a chance to play with the bot yet. I should be able to check that file tomorrow. I'll post the results. AND I did edit the file in Windows before zipping it up and transfering it to my Ubuntu box. I thought it would make my life easier... guess not.  ::)
SimplePortal 2.3.7 © 2008-2024, SimplePortal