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/holdreport.pid 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
holdreport.pl 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 172.16.0.6 # I insert my home IP here
allow <username>:<password>
check process holdreport with pidfile /var/log/holdreport.pid
#group Reports
start program = "/etc/init.d/holdreport start"
stop program = "/etc/init.d/holdreport stop"
if 5 restarts within 5 cycles then timeout
# EOF
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?
Regards,
On Wed, Dec 29, 2010 at 3:29 PM, EzCom Keith
<address@hidden> wrote:
On Wed, Dec 29, 2010 at 9:58 AM, Bruce B
<address@hidden> wrote:
Seems that I solved the output problem and so my script is now ready for implementation in Monit. Let's move on to what happens when the server restarts and also what to put in monit.conf and how to test that monit works and re-spawns the program when needed.
Here is what I have in my daemon file:
start() {
echo -n "Starting HoldReport: "
sleep 2
}
stop() {
echo -n "Stopping HoldReport: "
kill `cat /var/log/manager.pid`
}
Here is output of "ps aux" for the program:
root 11747 0.9 0.4 16572 9204 pts/1 S 12:55 0:00 perl /usr/src/holdReport/
holdreport.pl
Regards,
On Wed, Dec 29, 2010 at 11:03 AM, Bruce B
<address@hidden> wrote:
Thanks for the amazing details.
A- I have installed Monit using Yum Repository for CentOS and I can't locate the monitrc file but I have monit.conf and monit.d directory which is empty.
B- Here is the file I created for daemon but when I run the ./
xyz.pl start it hangs for ever. I know it's started already because I can see it in "ps aux" but it just hangs there. This was the exact same behavour when I run the file directly from the shell prompt as well. What is the work-around to this?
#!/bin/sh
# description: Starts/stops HoldReport Recording program - Records duration of HOLD to SQL
start() {
echo -n "Starting HoldReport: "
sleep 2
}
stop() {
echo -n "Stopping HoldReport: "
kill `cat /var/log/manager.pid`
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: holdreport {start|stop|restart}"
exit
esac
C- Now that I have a start/stop script what should go in my monit.conf file?
Thanks
On Wed, Dec 29, 2010 at 2:27 AM, EzCom Keith
<address@hidden> wrote:
On Tue, Dec 28, 2010 at 9:10 PM, Bruce B
<address@hidden> wrote:
Thanks for the feedback. To clarify things:
I have a perl program named "
test.pl" which runs fine if I simply run it like this at the shell level:
nohup perl /tmp/
test.pl >> /dev/null
Once above line is entered, the program
test.pl creates a /var/log/test.pid file which includes the PID of the program running and keeps doing the things I need it to do which is some report recording to SQL. So, I guess as you suggested I can run monit after running the program and have it monitor the PID file however I am not sure at all how to do it. Because all the examples have PROCESS in the first line and I don't think my simple program is a process like HTTP or others. Plus I don't have a START or STOP script for it. I only do "nohup" because I want it it to run if I am closing the terminal window and ">> /dev/null" is so there are no outputs on the screen.
I hope I am a bit more clear and I appreciate if you can give me a sample of what should go in the /etc/monit.conf.
In addition, I would appreciate it if you point me to monit.log (or whatever it's called) and also let me know what happens if the system is restarted? Should I expect Monit to start the program for me automatically?
Thanks,
On Tue, Dec 28, 2010 at 10:19 PM, EzCom Keith
<address@hidden> wrote:
Anything to this guys?
Thanks,
On Mon, Dec 27, 2010 at 9:57 PM, Bruce B
<address@hidden> wrote:
Hi Everyone,
I am very new to monit. I have a perl program (
test.pl) which should be running 24/7 and should re-spawn if it goes dead. Of course monit is the right tool for it but I have no clue how to use it.
Here is what I do to start the program each time:
nohup perl /usr/src/
test.pl >> /dev/null
The program actually creates a file with PID in it in /var/log/test.pid
I have the following so far in my /etc/monit.conf ( I am running CentOS) and it doesn't seem to work.
check process holdreport with pidfile /var/log/test.pid
start program = "/usr/src/holdReport/startTest.sh"
if 5 restarts within 5 cycles then timeout
And startTest.sh includes:
nohup perl /usr/src/
test.pl >> /dev/null
I would love to receive alerts to my gmail if program shuts down. Please enlighten me on that too.
Thanks,
Bruce
--
To unsubscribe:
http://lists.nongnu.org/mailman/listinfo/monit-general
Sorry Bruce,
Not enough info for me to be much help. When you say "it doesn't seem to work", what does that mean, exactly?
I can assume that if you run sh /usr/src/holdReport/startTest.sh from your shell, the script creates a pid file and
begins to do its job. So what happens when you request Monit to start monitoring? Does it do anything at all?
Can you post the relevant section of your Monit log? Best thing to do is (especially if this is the only process you
are attempting to monitor atm), rm -f your entire monit log. Manually start your perl script, then start monit. Check
the Monit webserver and note anything it says there regarding your script (also note if it does not even exist there).
Shut down Monit, and cat your monit log, copy/paste it to here.
As stated in an earlier thread, I used the 'wrapper' technique, outlined in the Monit FAQ, to successfully monitor
a PHP script that runs 24/7. It was surprisingly easy, and worked as advertised. Review that section, and see if
any of it can help you try a few things.
http://mmonit.com/wiki/Monit/FAQ
Best,
- Keith
--
To unsubscribe:
http://lists.nongnu.org/mailman/listinfo/monit-general
--
To unsubscribe:
http://lists.nongnu.org/mailman/listinfo/monit-general
Ok, lotta questions.. let's get the easy ones outta the way ; D
In your monitrc file, you can specify the monit logfile in this way:
set logfile /var/log/monit.log
Of course, your path and filename can be whatever you wish, but this is what's usual (I run CentOS as well).
Making a start/stop/restart (pretty much daemonizing) is also really simple. If you examine the files in your
/etc/rc.d/init.d directory, those are all generally daemon start stop scripts. Viewing some of the smaller files
will give you a quick tutorial. You can also Google for more information there if anything isn't clear. I would
suggest that you get your script daemonized in this way, and when you have it correct, you should be able
to start your process with:
/etc/rc.d/init.d/test start (replace 'test' with whatever you used for your daemon file name)
You should then be able to do:
/etc/rc.d/init.d/test status
and the system should tell you 'test' is running, it's stopped. or it appears dead but PID exists.
You should also be able to do 'stop' and 'restart'. All of these commands will be in your daemon file once you
have it setup. Test them all from the prompt, and verify they all behave exactly as expected. If your .pl script
has a bang at the top (ex., #!/usr/bin/perl -qC [or whatever]), you can probably delete the .sh startup script period.
When that is working to your satisfaction, you might be able to figure out the rest of the stuff you'll need for your
monitrc, and if not, post back and we'll get that going.
As for your actual file, I have some questions (off topic to Monit, my apologies). When you say you don't want
output after you've left the terminal, does this script normally have output? If it does, are you aware of the screen
command? It allows you to run a process, detach it, and logout of your shell. You can log back in, and re-attach
to it at will. It will also capture output to a file if you might ever want to look backwards. If your script truly runs
completely blind, then I guess the way you're doing it will work. If you're satisfied that your script is running and
doing exactly as you want in the environment as you have it, then disregard this part... ; )
As far as what happens at system restart, we are getting way ahead of ourselves. Let's get your script running
as a service, and Monit monitoring it, and then move on from there.
Best,
- Keith
--
To unsubscribe:
http://lists.nongnu.org/mailman/listinfo/monit-general
--
To unsubscribe:
http://lists.nongnu.org/mailman/listinfo/monit-general
Ok, your monit.conf file should be in /etc
If you view that file, near the very end should be this line, uncommented (no # before it):
include /etc/monit.d/*
The usual way to control Monit is to leave the .conf file alone, and create a new file called monitrc in the /etc/monit.d
directory. It will be included when the monit.conf is read. When I say 'the usual way', it is meant as a way to communicate
with other Monit users for support questions. You will be referred to your monitrc file many times, so it's best for everyone
to be on the same page there.
There _might_ be a monitrc file already at that location, I forget whether or not it is created by the YUM pkg. If it is not
there, create it. Here is the minimum necessary to have in it. This will create the webserver, the monit log, and also begin
monitoring your holdreport service:
# Start monitrc
set daemon 60 with start delay 60
set logfile /var/log/monit.log
set httpd port 2812 and
allow localhost
allow xx.xx.xx.xx # I insert my home IP here
allow <username>:<password>
check process holdreport with pidfile /var/log/manager.pid
#group Reports
start program = "/etc/init.d/holdreport start"
stop program = "/etc/init.d/holdreport stop"
if 5 restarts within 5 cycles then timeout
# EOF
Notes:
Start and Stop program section, 'holdreport' is the assumed name you gave your daemon file. Edit that if it's wrong (you didn't specify).
Your PID file is told to be found in /var/log, but the usual place for PID files is /var/run. You should probably correct that for cleanliness.
If you change that in your file that creates the PID file, change the path in the monitrc above.
The set daemon command tells Monit to awaken every 60 secs and check the requested services. The start delay tells it to wait 60
seconds after initial startup before it begins checking any services. You can change those to your needs, they are just starting
points.
The HTTP server will start, without SSL (you can add that later, once everything appears to be working). The allow list should be
self-explanatory. User and Pass are separated by a colon :
The group section is commented out, and is there for an example. If you have more than one type of report service in the future, you
can force those to be displayed in the web page as a group. Each monitored process with a same group name will be grouped
together for easier viewing.
If the service fails, Monit will try to restart it 5 times. If after 5 restarts it still cannot verify the service has restarted, it will stop
monitoring it (necessary to stop endless loops that might crash your server eventually, ie., something is VERY wrong).
Now then, start your service with your daemon command from your prompt. Verify it's running with 'status'.
Start Monit
Wait 60 seconds
Open a web browser and surf to your domain, adding :2812 at the end of the URL (ex., http://www.yoursite.com:2812). You should
be presented with a normal realm login prompt. Provide the user/pass you edited into the monitrc You should now be presented with
the Monit page, and hopefully everything is working.
If there are problems, do a cat /var/log/monit.log and see if it offers any insight.
May the Farce be with you... ; )
Best,
- Keith
--
To unsubscribe:
http://lists.nongnu.org/mailman/listinfo/monit-general