thank you /Jan-Henrik Haukeland, thank you /quizequing, I have put stop and start commands into scripts ~/imwheelinit and ~/imwheelstop respectively these scripts do work, when run from command line, as demonstrated below, however for some reason monit does execute only the imwheelstop. Below is the output of my console, first I run both scripts from the command line. Later start monit and try to start/stop imwheel. Only the stopping works. Please tell me what am I missing. I tried putting commands directly into .monitrc too, as suggested by /Jan-Henrik Haukeland/. That other version is listed on the end of my message. The result is the same. What I noticed is that now the stop program works perfect, after I replaced /bin/cat /dev/null > /tmp/imwheel.pid with just plain remove rm /tmp/imwheel.pid
Becasue of that I think that monit doesn't handle the redirection, as suggested by quizequing, I mean the > thing is the problem. But how can I write pid of imwheel process to a file without using it? olek% cat .monitrc set httpd port 2812 use address localhost allow localhost allow admin:monit set daemon 5 check process imwheel with pidfile /tmp/imwheel.pid start program = "/home/olo/imwheelinit" stop program = "/home/olo/imwheelstop" if cpu usage > 3% for 1 cycles then restart olek% cat imwheelinit #!/bin/bash /usr/bin/imwheel -k -X :0.0 /bin/pidof imwheel > /tmp/imwheel.pid olek% cat imwheelstop #!/bin/bash rm -v /tmp/imwheel.pid imwheel -k -q olek% ./imwheelinit INFO: imwheel started (pid=9373) olek% cat /tmp/imwheel.pid 9373 olek% pidof imwheel 9373 olek% ./imwheelstop removed `/tmp/imwheel.pid' INFO: imwheel(pid=9373) killed. olek% cat /tmp/imwheel.pid olek% pidof imwheel olek% pidof monit olek% monit -v -l /home/olo/Desktop/monit.log monit: Debug: Adding host allow 'localhost' monit: Debug: Skipping redundant host 'localhost' monit: Debug: Skipping redundant host 'localhost' monit: Debug: Adding credentials for user 'admin'. Runtime constants: Control file = /home/olo/.monitrc Log file = /home/olo/Desktop/monit.log Pid file = /home/olo/.monit.pid Debug = True Log = True Use syslog = False Is Daemon = True Use process engine = True Poll time = 5 seconds with start delay 0 seconds Mail server(s) = localhost Mail from = (not defined) Mail subject = (not defined) Mail message = (not defined) Start monit httpd = True httpd bind address = localhost httpd portnumber = 2812 httpd signature = True Use ssl encryption = False httpd auth. style = Basic Authentication and Host/Net allow list The service list contains the following entries: Process Name = imwheel Pid file = /tmp/imwheel.pid Monitoring mode = active Start program = '/home/olo/imwheelinit' timeout 30 second(s) Stop program = '/home/olo/imwheelstop' timeout 30 second(s) Pid = if changed 1 times within 1 cycle(s) then alert Ppid = if changed 1 times within 1 cycle(s) then alert CPU usage limit = if greater than 3.0% 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert System Name = olek Monitoring mode = active ------------------------------------------------------------------------------- monit: pidfile '/home/olo/.monit.pid' does not exist Starting monit daemon with http interface at [localhost:2812] olek [monit -v -l /home/olo/Desktop/monit.log] ~ 08-12-03 12:52AM olek% monit status The Monit daemon 5.0_beta4 uptime: 0m Process 'imwheel' status not monitored monitoring status not monitored data collected Wed Dec 3 00:52:30 2008 System 'olek' status Monit instance changed monitoring status monitored load average [0.87] [0.59] [0.55] cpu -1.0%us -1.0%sy -1.0%wa memory usage 994712 kB [47.9%] data collected Wed Dec 3 00:52:30 2008 olek% monit start imwheel olek% monit status monit: cannot read status from the monit daemon olek% monit status The Monit daemon 5.0_beta4 uptime: 1m Process 'imwheel' status Execution failed - start pending monitoring status monitored data collected Wed Dec 3 00:53:35 2008 System 'olek' status running monitoring status monitored load average [0.65] [0.56] [0.54] cpu 8.6%us 6.1%sy 0.1%wa memory usage 1003740 kB [48.3%] data collected Wed Dec 3 00:53:35 2008 olek% ./imwheelinit INFO: imwheel started (pid=9625) olek% monit status The Monit daemon 5.0_beta4 uptime: 1m Process 'imwheel' status running monitoring status monitored pid 9625 parent pid 1 uptime 0m childrens 0 memory kilobytes 812 memory kilobytes total 812 memory percent 0.0% memory percent total 0.0% cpu percent 0.0% cpu percent total 0.0% data collected Wed Dec 3 00:54:15 2008 System 'olek' status running monitoring status monitored load average [0.68] [0.57] [0.55] cpu 21.2%us 29.3%sy 0.0%wa memory usage 1003972 kB [48.3%] data collected Wed Dec 3 00:54:15 2008 olek% pidof imwheel 9625 olek% monit stop imwheel olek% monit status The Monit daemon 5.0_beta4 uptime: 2m Process 'imwheel' status not monitored monitoring status not monitored data collected Wed Dec 3 00:54:59 2008 System 'olek' status running monitoring status monitored load average [0.90] [0.63] [0.56] cpu 7.5%us 2.6%sy 0.0%wa memory usage 1011668 kB [48.7%] data collected Wed Dec 3 00:54:59 2008 olek% pidof imwheel olek% cat /tmp/imwheel.pid cat: /tmp/imwheel.pid: No such file or directory olek% monit start imwheel olek% monit status The Monit daemon 5.0_beta4 uptime: 3m Process 'imwheel' status not monitored - start pending monitoring status not monitored data collected Wed Dec 3 00:55:49 2008 System 'olek' status running monitoring status monitored load average [0.50] [0.56] [0.54] cpu 7.4%us 3.1%sy 0.0%wa memory usage 1011884 kB [48.7%] data collected Wed Dec 3 00:55:49 2008 olek% monit status The Monit daemon 5.0_beta4 uptime: 3m Process 'imwheel' status initializing monitoring status initializing data collected Wed Dec 3 00:56:24 2008 System 'olek' status running monitoring status monitored load average [0.50] [0.56] [0.54] cpu 7.4%us 3.1%sy 0.0%wa memory usage 1011884 kB [48.7%] data collected Wed Dec 3 00:56:24 2008 olek% monit status The Monit daemon 5.0_beta4 uptime: 4m Process 'imwheel' status not monitored monitoring status not monitored data collected Wed Dec 3 00:56:24 2008 System 'olek' status running monitoring status monitored load average [0.44] [0.55] [0.54] cpu 9.5%us 7.0%sy 0.0%wa memory usage 1012208 kB [48.7%] data collected Wed Dec 3 00:56:24 2008 olek% I ALSO TRIED THIS APPROACH AS SUGGESTED BY /Jan-Henrik Haukeland/ set httpd port 2812 use address localhost allow localhost allow admin:monit set daemon 5 check process imwheel with pidfile /tmp/imwheel.pid start program = "/bin/bash -c '/usr/bin/imwheel -k -X :0.0; /bin/pidof imwheel > /tmp/imwheel.pid'" stop program = "/bin/bash -c '/bin/rm -v /tmp/imwheel.pid; imwheel -k -q'" if cpu usage > 3% for 1 cycles then restart the killing part works fine (imwheel -k -q does the killing), stil it can't start process. 齐泽青 wrote: > olo,你好! > you'd better rewrite the start and stop script and made it a simple > command without redirect and some other arguments. > and plese make sure when you write the start or stop script all > declares are correct , like the first line of scrit "#!/usr/bin" > sometimes the command can be executed under the command line but when > in monitrc ,it won't work. > ------------------------------------------------------------------------ > 齐泽青 22:05:21 2008-12-02 > Intelligent Peripheral Department > EB Information Technology Ltd. > Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > Tel 010-82325588-8263 > [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > Add:1503 15 Floor, Kunxun Building, No.9 Zhichun Road > Haidian District, Beijing PC:100191 > ------------------------------------------------------------------------ > *发件人:* olo > *发送时间:* 2008-12-02 21:42:33 > *收件人:* [email protected] > *抄送:* > *主题:* [monit] Monit won't start any process. Please help. > Hi, I don't know why but monit fails to start processes, and its the > same for version 4.10 or 5.0 beta4. I want it to keep an eye on imwheel > process, which occasionally hangs and consumes lots of CPU. The process > has no PID file, so I made it create it. Monit does kill the > process if I start it manually. I tried writing stop/start > commands all inside .monitrc and in separate executable files called > from within .monitrc with the same results. They do work properly if I > run them directly from the command line. Here is > my configuration, and log: > CONFIG (~/.monitrc): > set httpd port 2812 > use address localhost > allow localhost > allow admin:monit > set daemon 5 > check process imwheel with pidfile /tmp/imwheel.pid > start program = "/usr/bin/imwheel -k -X :0.0; /bin/pidof imwheel > > /tmp/imwheel.pid" > stop program = "/usr/bin/killall imwheel; /bin/cat /dev/null > > /tmp/imwheel.pid" > if cpu usage > 3% for 1 cycles then restart > This is what is logged after starting monit and after short time giving > it this command: monit start imwheel > (it won't start it neither by itself nor after this direct command) > [CET Dec 2 09:45:25] debug : monit: pidfile '/home/olo/.monit.pid' > does not exist > [CET Dec 2 09:45:25] info : Starting monit daemon with http > interface at [localhost:2812] > [CET Dec 2 09:45:25] info : Starting monit HTTP server at > [localhost:2812] > [CET Dec 2 09:45:25] info : monit HTTP server started > [CET Dec 2 09:45:25] info : 'olek' Monit started > [CET Dec 2 09:45:25] error : http server: Could not create a server > socket at port 2812 -- Address already in use > [CET Dec 2 09:45:25] error : monit HTTP server not available > [CET Dec 2 09:45:25] error : 'imwheel' process is not running > [CET Dec 2 09:45:25] info : 'imwheel' trying to restart > [CET Dec 2 09:45:25] debug : Monitoring disabled -- service imwheel > [CET Dec 2 09:45:25] info : 'imwheel' start: /usr/bin/imwheel > [CET Dec 2 09:45:55] error : 'imwheel' failed to start > [CET Dec 2 09:45:55] debug : Monitoring enabled -- service imwheel > [CET Dec 2 09:46:00] info : 'olek' Monit has not changed > [CET Dec 2 09:46:00] error : 'imwheel' process is not running > [CET Dec 2 09:46:00] info : 'imwheel' trying to restart > [CET Dec 2 09:46:00] debug : Monitoring disabled -- service imwheel > [CET Dec 2 09:46:00] info : 'imwheel' start: /usr/bin/imwheel > [CET Dec 2 09:46:30] error : 'imwheel' failed to start > [CET Dec 2 09:46:30] debug : Monitoring enabled -- service imwheel > [CET Dec 2 09:46:35] error : 'imwheel' process is not running > [CET Dec 2 09:46:35] info : 'imwheel' trying to restart > [CET Dec 2 09:46:35] debug : Monitoring disabled -- service imwheel > [CET Dec 2 09:46:35] info : 'imwheel' start: /usr/bin/imwheel > And here is the output of starting monit, when imwheel is already runing > with pid file set > olek [cd] ~ 08-12-02 > 9:49AM > olek% ./imwheelinit > INFO: imwheel started (pid=11735) > olek [./imwheelinit] ~ 08-12-02 9:49AM > olek% cat /tmp/imwheel.pid > 11735 > and giving: monit stop imwheel, does kill imwheel but ... > [CET Dec 2 09:51:36] debug : monit: pidfile '/home/olo/.monit.pid' > does not exist > [CET Dec 2 09:51:36] info : Starting monit daemon with http > interface at [localhost:2812] > [CET Dec 2 09:51:36] info : Starting monit HTTP server at > [localhost:2812] > [CET Dec 2 09:51:36] error : http server: Could not create a server > socket at port 2812 -- Address already in use > [CET Dec 2 09:51:36] error : monit HTTP server not available > [CET Dec 2 09:51:36] info : monit HTTP server started > [CET Dec 2 09:51:36] info : 'olek' Monit started > [CET Dec 2 09:51:36] debug : 'imwheel' zombie check succeeded > [status_flag=0000] > [CET Dec 2 09:51:36] debug : 'imwheel' cpu usage check succeeded > [current cpu usage=0.0%] > [CET Dec 2 09:51:41] info : 'olek' Monit has not changed > [CET Dec 2 09:51:41] debug : 'imwheel' zombie check succeeded > [status_flag=0000] > [CET Dec 2 09:51:41] debug : 'imwheel' PID has not changed since > last cycle > [CET Dec 2 09:51:41] debug : 'imwheel' PPID has not changed since > last cycle > [CET Dec 2 09:51:41] debug : 'imwheel' cpu usage check succeeded > [current cpu usage=0.0%] > [CET Dec 2 09:51:46] debug : 'imwheel' zombie check succeeded > [status_flag=0000] > [CET Dec 2 09:51:46] debug : 'imwheel' PID has not changed since > last cycle > [CET Dec 2 09:51:46] debug : 'imwheel' PPID has not changed since > last cycle > [CET Dec 2 09:51:46] debug : 'imwheel' cpu usage check succeeded > [current cpu usage=0.0%] > [CET Dec 2 09:51:51] debug : 'imwheel' zombie check succeeded > [status_flag=0000] > [CET Dec 2 09:51:51] debug : 'imwheel' PID has not changed since > last cycle > [CET Dec 2 09:51:51] debug : 'imwheel' PPID has not changed since > last cycle > [CET Dec 2 09:51:51] debug : 'imwheel' cpu usage check succeeded > [current cpu usage=0.0%] > [CET Dec 2 09:51:56] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:51:56] error : 'imwheel' process is not running > [CET Dec 2 09:51:56] info : 'imwheel' trying to restart > [CET Dec 2 09:51:56] debug : Monitoring disabled -- service imwheel > [CET Dec 2 09:51:56] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:51:56] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:51:56] info : 'imwheel' start: /usr/bin/imwheel > [CET Dec 2 09:51:56] debug : 'imwheel' Error testing process id > [11735] -- No such process > .... .... .... > [CET Dec 2 09:52:25] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:52:26] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:52:26] error : 'imwheel' failed to start > [CET Dec 2 09:52:26] debug : Monitoring enabled -- service imwheel > [CET Dec 2 09:52:31] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:52:31] error : 'imwheel' process is not running > [CET Dec 2 09:52:31] info : 'imwheel' trying to restart > [CET Dec 2 09:52:31] debug : Monitoring disabled -- service imwheel > [CET Dec 2 09:52:31] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:52:31] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:52:31] info : 'imwheel' start: /usr/bin/imwheel > [CET Dec 2 09:52:31] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:52:31] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:52:32] debug : 'imwheel' Error testing process id > [11735] -- No such process > [CET Dec 2 09:52:33] debug : 'imwheel' Error testing process id > [11735] -- > Still, it does just part of the job, killing imwheel, but won't clean > pid file as I intended by putting cat /dev/null > /tmp/imwheel.pid in > my stop command: > olek [monit quit] ~ 08-12-02 > 9:54AM > olek% cat /tmp/imwheel.pid > 11735 > If I just execute the comands: > /usr/bin/imwheel -k -X :0.0; /bin/pidof imwheel > /tmp/imwheel.pid > and > /usr/bin/killall imwheel; /bin/cat /dev/null > /tmp/imwheel.pid > from the command line everything seems to work perfectly fine. It is not > imwheel specific, as I tried same thing with other programs, such as > sleep or cat. killall and kill seems to work fine with monit. Other > programs not. I suspect it's something with pid, but monit does see > imwheel with correct pid when I start it manually (monit status does > show it, and everything is correct). > Still won't do the stop command as expected. I use zsh if it makes any > difference, but tried running everything from bash with the same result. > I have Debian/testing. > What am I missing? Help will be greatly appreciated. > -- > To unsubscribe: > http://lists.nongnu.org/mailman/listinfo/monit-general -- To unsubscribe: http://lists.nongnu.org/mailman/listinfo/monit-general
