Cannot get monit to work

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
sundodger
Posts: 29
Joined: Sunday 11 August 2019 17:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Cannot get monit to work

Post 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.
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Cannot get monit to work

Post 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
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Cannot get monit to work

Post 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
sundodger
Posts: 29
Joined: Sunday 11 August 2019 17:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Cannot get monit to work

Post 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?
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Cannot get monit to work

Post 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'
sundodger
Posts: 29
Joined: Sunday 11 August 2019 17:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Cannot get monit to work

Post by sundodger »

This is the line

Code: Select all

start program = "/etc/init.d/domoticz.sh start"
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Cannot get monit to work

Post 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.
eddieb
Posts: 279
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Cannot get monit to work

Post 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
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
sundodger
Posts: 29
Joined: Sunday 11 August 2019 17:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Cannot get monit to work

Post 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.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Cannot get monit to work

Post by EddyG »

'disk' is a 'reserved' word in monit see: https://mmonit.com/monit/documentation/ ... K-I-O-TEST
embee999
Posts: 9
Joined: Tuesday 08 March 2022 21:39
Target OS: Linux
Domoticz version:
Contact:

Re: Cannot get monit to work

Post 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.
Post Reply

Who is online

Users browsing this forum: janpep and 0 guests