[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Very simple monit of a perl file - how to do it?

From: EzCom Keith
Subject: Re: Very simple monit of a perl file - how to do it?
Date: Wed, 29 Dec 2010 16:16:20 -0800

On Wed, Dec 29, 2010 at 2:14 PM, Bruce B <address@hidden> wrote:
Just to update to my previous e-mail, I removed the allow and I can now get access to the webpage and pressed on Run Service and my .pl script started working. It's nice info that is shown there and I am already thinking of moving all my scripts to monit and using M/monit.

I still want to have your input on the httpd authentication method as I don't think this is very secure to not have a password on it and also how to avoid multiple instances from starting.

Thanks again,

On Wed, Dec 29, 2010 at 5:05 PM, Bruce B <address@hidden> wrote:
Amazing, amazing guide through. Not only I know much more about Monit now, I have also learned the daemon processes with your help as well. So, thank you very much.

I have changed the PID file to point to /var/run/ and added `status` as well to my daemon which works beautifully. I also change the awaken section to 20 for 20 seconds but left the delay to 60 so that if the computer is restarted it waits until chkconfig runs my program and then it start monitoring.

Few problems I am encountering now:

1- Tailing the /var/log/monit.log file doesn't show me anything if I kill the process. I waited the 20 seconds required but I don't see any logs generated in /var/log/monit.log and also the program didn't re-spawn. Here is what I have in /etc/monit.d/monitrc

# Start monitrc
set daemon  5 with start delay 5

set logfile /var/log/monit.log
set httpd port 2812 and
     allow localhost
     allow # I insert my home IP here
     allow <username>:<password>

check process holdreport with pidfile /var/log/
   #group Reports
   start program = "/etc/init.d/holdreport start"
   stop program = "/etc/init.d/holdreport stop"

   if 5 restarts within 5 cycles then timeout

2- Can't get access to the httpd page at :2812 because I can't authenticate. Where is the actuall username/pass defined? Are these apache htapsswd file username and passwords or could it be just plain    username:passsword    format and then use "username" and "password" for authentication?

3- Multiple instances - There is a chance that my file might run in multiple instances and if it does it can duplicate all of it's reports which is not desireable. I guess I have to do an "if condition" in my start scrip to make sure another instance is not running? or is there something in monit that can check for other instances of the program?


In your monitrc file, the line:

allow <username>:<password>

is to be edited by YOU. Replace <username>:<password> with what you want it to be...
ex., allow sysadmin:secret

it's just basic HTTP auth, similar to what you'd do with .htaccess

You can also configure the server to run SSL, but you'd have to dig through the documentation about that. All we've tried
to do here is get your script as a service, and then get Monit to 'see' it so it can be monitored. This verifies that pretty much
everything is indeed working. The rest of it, you'll have to dig through the manual, and anything in there you might want to
fuss with can be added to your monitrc file. This would include setting up email alerts, etc. Use the Monit FAQ for real
example monitrc file entries, and adjust as necessary for your environment.

This is a GREAT admin tool, but it's also not very friendly right out of the pkg. It will take time to tweak a solid monitrc that
best fits your needs. That will take a bit of time, trial and error.

If your script is correctly setup as a daemon, there is nigh no possibility of multiple instances. If multiple instances are somehow
spawned, this is a situation you will have to code to correct it. Monit cannot do this for you, nor can it kill any unwanted
instances, as it's not that good at guessing which one is 'supposed' to be there, and which one isn't. Some jobs are still going
to be your responsibility (as they should be) ! : )

If you are killing your script, and Monit isn't instantly trying to restart it, that would be a problem... you might need a lock
file, not too sure... let me know if you cannot resolve and I will try to help you adjust your daemon file. Are you including the
functions file at the top of your daemon file? I would recommend this, if you don't have it in your daemon file:

# description: Starts/stops HoldReport Recording program - Records duration of HOLD to SQL
# Source function library.
. /etc/rc.d/init.d/functions

start() {
        echo -n "Starting HoldReport:  "
        daemon nohup perl /usr/src/holdReport/ & >> /dev/null
        sleep 2

etc, etc, rest of your daemon file...

Note the inclusion of the functions file, and the command 'daemon' added to your start function. Try that and see how it goes.

- Keith

reply via email to

[Prev in Thread] Current Thread [Next in Thread]