Page 1 of 1

Cannot get monit to work

Posted: Saturday 07 August 2021 15:54
by sundodger
Hi all,
I am having some trouble getting Monit to run and would appreciate some guidance if possible.
I get the following error

Code: Select all

pi@raspberrypi:~ $  sudo systemctl status monit.service
● monit.service - LSB: service and resource monitoring daemon
   Loaded: loaded (/etc/init.d/monit; generated)
   Active: failed (Result: exit-code) since Sat 2021-08-07 10:56:14 IST; 3h 49min ago
     Docs: man:systemd-sysv-generator(8)

Aug 07 10:56:14 raspberrypi systemd[1]: Starting LSB: service and resource monitoring daemon...
Aug 07 10:56:14 raspberrypi monit[13627]: Starting daemon monitor: monit/etc/monit/monitrc:217: syntax error '/etc/init.d/httpd'
Aug 07 10:56:14 raspberrypi monit[13627]:  failed!
Aug 07 10:56:14 raspberrypi systemd[1]: monit.service: Control process exited, code=exited, status=1/FAILURE
Aug 07 10:56:14 raspberrypi systemd[1]: monit.service: Failed with result 'exit-code'.
Aug 07 10:56:14 raspberrypi systemd[1]: Failed to start LSB: service and resource monitoring daemon.
Checking the config file for syntax gives the error
/etc/monit/monitrc:222: syntax error '/etc/init.d/domoticz.sh'
It maybe something quite simple but my lack of knowledge has me at a dead end.
Thanks in advance.

Re: Cannot get monit to work

Posted: Saturday 07 August 2021 18:12
by jake
This is the last part of my file @ /etc/monit/monitrc

#
###############################################################################
## Includes
###############################################################################
##
## It is possible to include additional configuration parts from other files or
## directories.
#
include /etc/monit/conf.d/*
#
check process domoticz with pidfile /var/run/domoticz.pid
start program = "/etc/init.d/domoticz.sh restart"
stop program = "/etc/init.d/domoticz.sh stop"
if failed
url http://127.0.0.1:8080/json.htm?param=ge ... pe=command
and content = '"status" : "OK"'
for 2 cycles
then restart

Re: Cannot get monit to work

Posted: Saturday 07 August 2021 18:20
by FireWizard
Hi, sundodger,

This is my Domoticz-Monit part.

Code: Select all

## Check domoticz
  check process domoticz with pidfile /var/run/domoticz.pid
  start program = "/etc/init.d/domoticz.sh start"
  stop  program = "/etc/init.d/domoticz.sh stop"
  if failed
     url http://127.0.0.1:8080/json.htm?type=command&param=getversion
         and content = '"status" : "OK"'
     for 2 cycles
     then restart
  if 5 restarts within 5 cycles then exec "/sbin/reboot"
Perhaps it is helpful.

Regards

Re: Cannot get monit to work

Posted: Saturday 07 August 2021 19:47
by sundodger
Hi, thanks for the replies.
I have tried both of the above suggestions and even though i copy and pasted them into my own file i still get a syntax error '/etc/init.d/domoticz.sh' when i check syntax.
I must be missing something in setup.
Is it possible to totally remove Monit and setup again from scratch?

Re: Cannot get monit to work

Posted: Saturday 07 August 2021 21:23
by EddyG
I use this part

Code: Select all

start program = "/usr/bin/sudo /bin/systemctl restart domoticz.service"
stop  program = "/usr/bin/sudo /bin/systemctl stop domoticz.service"
What is in the part:

Code: Select all

monit/etc/monit/monitrc:217: syntax error '/etc/init.d/httpd'

Re: Cannot get monit to work

Posted: Saturday 07 August 2021 21:53
by sundodger
This is the line

Code: Select all

start program = "/etc/init.d/domoticz.sh start"

Re: Cannot get monit to work

Posted: Saturday 07 August 2021 22:04
by EddyG
That does not add up.
The error is about httpd on line 217 and you state that it is domoticz.
In my default monitrc is near that line (217) the apache (httpd) configuration.
I use separate config files in the conf.d directory because they are included at the end of monitrc.

Re: Cannot get monit to work

Posted: Sunday 08 August 2021 8:26
by eddieb
Same here,

I did not touch the /etc/monit/monitrc file, all mods are inside /etc/monit/conf-enabled/domoticz

Code: Select all

# cat /etc/monit/conf-enabled/domoticz 
## Domoticz
check process domoticzd with pidfile /var/run/domoticz.pid
start program = "/etc/init.d/domoticz.sh start"
stop program = "/etc/init.d/domoticz.sh stop"
if failed
   url http://127.0.0.1:8080/json.htm?type=command&param=getversion
       and content = '"status" : "OK"'
   for 2 cycles
   then restart
if 5 restarts within 5 cycles then exec "/sbin/reboot"
if cpu usage > 80% for 3 cycles then restart

Code: Select all

# cat /etc/monit/conf-enabled/apache2 
 check process apache with pidfile /var/run/apache2/apache2.pid
   group www
   group apache
   start program = "/etc/init.d/apache2 start"
   stop program  = "/etc/init.d/apache2 stop"
   if 4 restarts within 20 cycles then timeout
   if failed host localhost port 80 with protocol http and request "/server-status" with timeout 25 seconds for 4 times within 5 cycles then restart
   depend apache_bin
   depend apache_rc

 check file apache_bin with path /usr/sbin/apache2
   group apache
   include /etc/monit/templates/rootbin

 check file apache_rc with path /etc/init.d/apache2
   group apache
   include /etc/monit/templates/rootbin

 check host apache-port-tcp80 with address 127.0.0.1
   start program = "/etc/init.d/apache2 start"
   stop program  = "/etc/init.d/apache2 stop"
   if 4 restarts within 20 cycles then timeout
   if failed host localhost port 80 with protocol http and request "/server-status" with timeout 25 seconds for 4 times within 5 cycles then restart
   depend apache
works fine here

Re: Cannot get monit to work

Posted: Sunday 08 August 2021 17:31
by sundodger
I added what you have to /etc/monit/conf-enabled/domoticz and commented out the relevant lines in monitrc.
same error, so i deleted that section and the syntax error moves it is now at the point where it has a problem with the word "Disk" in the line that reads
# if failed gid "disk" then unmonitor.
Why is it giving me a problem with stuff that is commented out (#)
really odd..

Follow up. it seems anything in quotation marks even if commented out threw an error. After much deleting and trial and error i am passing the syntax check.

Re: Cannot get monit to work

Posted: Sunday 08 August 2021 20:40
by EddyG
'disk' is a 'reserved' word in monit see: https://mmonit.com/monit/documentation/ ... K-I-O-TEST

Re: Cannot get monit to work

Posted: Thursday 07 July 2022 13:41
by embee999
Hi,
I've just worked through the monit install/config and the issue I've had is that, using systemd services, no PID file is now created (for any service,actually). Monit cannot then see the process it wants to monitor in it's CHECK PROCESS line. Obviously systemctl can give you the running PID number. I solved this by adding a line like this after the ExecStart command of domoticz.service file :-
ExecStartPost=/bin/sh -c 'umask 022; pgrep YOURSERVICE > /var/run/YOURSERVICE.pid'
You need to give the domoticz user permission to create the file in the folder.
Don't forget to run systemctl daemon-reload before restarting the domoticz service and change the monit config file for the PID you've created.

Most of the monit install links show init.d style set=ups which WILL create the PID file.