This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Monitoring Eggdrop with Monit

General support and discussion of Eggdrop bots.
Post Reply
d
danswano
Voice
Posts: 20
Joined: Thu Apr 07, 2011 7:53 am

Monitoring Eggdrop with Monit

Post by danswano »

Hello everyone i would like to know how to monitor eggdrop with monit cause it's deffcult for me to do so, the eggdrop won't run as root and monit run as root by default, i have tried many shell commands to run eggdrop from root as another users but eggdrop won't boot and give error or languages missing.

monit requires some stuff to be able to monitor a script/service:
1. PID file (can be found)
2. Start command
3. Stop command

i was able to get all those stuff but the problem that it won't run as root or as another user from root.

anyone can help me with this? :)
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You aren't allowed to run eggdrop as root due to security issues.

#1 question: In the configuration file there's:
# Specify here the filename Eggdrop will save its pid to. If no pidfile is
# specified, pid.(botnet-nick) will be used.
#set pidfile "pid.LamestBot"
#2 question:
If your eggdrop has an user file then start it normally with './eggdrop' if not start it 1 time with './eggdrop -m' if the configuration file is eggdrop.conf and with './eggdrop -m name-of-the-file.conf' if it's different (replace 'name-of-the-file.conf' with the actual name).

#3 question:

Code: Select all

kill -9 `cat pid.LamestBot`
(replace pid.LamestBot with the actual file name) should do what you want :)
Once the game is over, the king and the pawn go back in the same box.
d
danswano
Voice
Posts: 20
Joined: Thu Apr 07, 2011 7:53 am

Post by danswano »

Thanks buddy, i know how to get the pid/start/stop using kill or killall but my problem is how can i start eggdrop from root shell as another user without errors.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You can switch from root to any user without knowing his/her password via 'su username' and do whatever you wish from there. :)

Edit: From what I've just read, something like this should do what you want:

Code: Select all

 check process eggdrop with pidfile /home/user/eggdrop
       start = "/root/eggdrop start"
       stop = "/root/eggdrop stop"
And in '/root/eggdrop' you create a simple start/stop shell-script like here.
Last edited by caesar on Thu Apr 07, 2011 11:00 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
d
danswano
Voice
Posts: 20
Joined: Thu Apr 07, 2011 7:53 am

Post by danswano »

Great but how i will make as one command to put it in start command for monit ?

this works:
su username
./eggdrop

but tried:
su username ./eggdrop

it said

can't execute binary file

i want it as one line so i can put it in monit configuration file.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Here's a bash script that I did for you.

Code: Select all

#!/bin/bash

# set the user
user="username"

# and the path to eggdrop dir
path="/home/$user/eggdrop"

function getPid {
  pid=0
  file=`/bin/ls $path | grep pid`
  if [ -n "$file" ]; then
  pid=`cat $path/$file`
  fi
}

function getStatus {
  status=0
  if pidof eggdrop | grep [0-9] > /dev/null; then
  status=1
  fi
}

function status {
  getStatus
  case "$status" in
  0)
  echo -e "offline"
  ;;
  1)
  echo -e "online"
  ;;
  esac
}

function start {
  getStatus
  if [ "$status" -eq "0" ]; then
  su $user
  cd $path
  rm -fr *.pid
  ./eggdrop
  fi
}


function stop {
  getStatus
  if [ "$status" -eq "1" ]; then
  getPid
  kill -9 $pid
  rm -fr $path/*.pid
  fi
}

case "$1" in
   start)
      start
   ;;
   stop)
      stop
   ;;
   restart)
      restart
   ;;
   status)
      status
   ;;
   *)
      echo "Usage: $0 {start|stop|status}"
esac
Haven't tested if it really starts/stops the bot, but it should work just fine. :)
Once the game is over, the king and the pawn go back in the same box.
d
danswano
Voice
Posts: 20
Joined: Thu Apr 07, 2011 7:53 am

Post by danswano »

Hello dear, thanks for all replies, i've managed to run this command

su user -c /home/user/eggdrop/./eggdrop-1.6.20

and it working perfectly but monit requires a full path of the command and it means it wants it like this

/bin/su user -c /home/user/eggdrop/./eggdrop-1.6.20

but i'm getting this error after executing it.

[18:56:16] LANG: No lang files found for section core.

Eggdrop v1.6.20 (C) 1997 Robey Pointer (C) 2010 Eggheads
[18:56:16] --- Loading eggdrop v1.6.20 (Thu Apr 7 2011)
[18:56:16] * MSG534


any idea how can i bypass this ? :)
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Have you bothered to check out the script i did?
Once the game is over, the king and the pawn go back in the same box.
d
danswano
Voice
Posts: 20
Joined: Thu Apr 07, 2011 7:53 am

Post by danswano »

Hello again,

thanks buddy for the awesome script, it worked flawlessly for me but there is an issue still:

when i run the sh file as the following from root it runs fine and execute the bot but it give this error

Code: Select all

root@server [/home/eggdrop]# /bin/su eggdrop /home/eggdrop/autobot/./autobot.sh start
/home/eggdrop/eggdrop/./eggdrop.sh: line 39: /bin/su: Permission denied

Eggdrop v1.6.20 (C) 1997 Robey Pointer (C) 2010 Eggheads
[17:38:06] --- Loading eggdrop v1.6.20 (Fri Apr  8 2011)
[14:38:06] Listening at telnet port 8362 (all).
[14:38:06] Module loaded: channels
[14:38:06] Module loaded: dns
[14:38:06] Module loaded: transfer         (with lang support)
[14:38:06] Module loaded: share
[14:38:06] Module loaded: server
[14:38:06] Module loaded: ctcp
[14:38:06] Module loaded: irc
[14:38:06] Module loaded: notes            (with lang support)
[14:38:06] Module loaded: console          (with lang support)
[14:38:06] Module loaded: blowfish
[14:38:06] Module loaded: uptime
[14:38:06] RSS Syndication Script v0.5b1 (2007-12-17): Loaded.
[14:38:06] NickPlus : Loaded
[14:38:06] Writing channel file...
[14:38:06] Userfile loaded, unpacking...
[14:38:06] === eggdrop: 1 channels, 1 users.
Launched into the background  (pid: 4986)
/home/eggdrop/eggdrop/./eggdrop.sh: line 39: /bin/su: Permission denied

on line 39 there is

Code: Select all

  su $user
Thanks for help, appreciate it :)
Post Reply