Page 1 of 1

Monit works partially

Posted: Friday 30 August 2024 15:42
by jvmaanen
If the power of the raspberry has been off, it takes more than half an hour before domoticz is restarted. This happens after the script has performed the reboot.

I'm using these lines:
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
host 127.0.0.1 port 8080 protocol http
and request "/json.htm?type=command&param=getversion"
and content = '"status" : "OK"'
for 3 cycles
then restart
if 5 restarts within 5 cycles then exec "/sbin/reboot"

It looks like the "if failed" part is not working correctly.

When I check the Monit web page, I get the following error:
Monit error for Domoticz process.png
Monit error for Domoticz process.png (48.89 KiB) Viewed 1097 times

After more than half an hour, the raspberry has been rebooted based on the "If 5..." statement and then after 5 minutes the domoticz server is finally started.
Monit succesfully started domoticz.png
Monit succesfully started domoticz.png (62.14 KiB) Viewed 1097 times

What is wrong in the "if failed..." statement and how can I test this on the raspberry (terminal).

Re: Monit works partially

Posted: Saturday 31 August 2024 7:19
by Kedi
I don't understand the "it takes more than half an hour before domoticz is restarted"
I suppose the script "/etc/init.d/domoticz.sh" is present, which should start domoticz right after the boot.
The default monit install has a 'start' delay of 60 or more seconds before it starts checking.
After that delay domoticz should already be up and responding to monit requests.

And beter change

Code: Select all

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

Code: Select all

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

Re: Monit works partially

Posted: Saturday 31 August 2024 10:49
by jvmaanen
It surely helped a lot changing from start to restart.

There is still a difference between a reboot command and a power failure. After a reboot command domoticz is running, after a power failure domoticz is started, but not running:

pi@raspberrypi:~ $ sudo service domoticz status
● domoticz.service - LSB: Home Automation System
Loaded: loaded (/etc/init.d/domoticz.sh; generated)
Active: active (exited) since Sat 2024-08-31 10:17:16 CEST; 7min ago

Also the pidfile at /var/run/domoticz.pid is not available

After 5 minutes Moni becomes active and now restarts domoticz. Domoticz is now running again:
pi@raspberrypi:~ $ sudo service domoticz status
● domoticz.service - LSB: Home Automation System
Loaded: loaded (/etc/init.d/domoticz.sh; generated)
Active: active (running) since Sat 2024-08-31 10:27:08 CEST; 1min 7s ago

So, I still need Moni to activate domoticz, but with the restart option (instead of start) it now takes 5 minutes after the boot when Moni starts who checks for the missing pidfile and restarts domoticz. After the restart domoticz is active and running. In the previous situation I had to wait more than 30 minutes for the reboot command to kick in.

Re: Monit works partially

Posted: Saturday 31 August 2024 11:14
by Kedi
Then there is something wrong with your system.
In both case (reboot / power failure) Domoticz should start directly after the system is started up.

B.t.w. I use a start delay of 60 seconds for Monit to do its job.

Re: Monit works partially

Posted: Saturday 31 August 2024 12:32
by jvmaanen
It looks like it starts after a power failure, but than exits. When I check there is no pidfile.

What can I do or check, to make sure that it starts correctly?

Re: Monit works partially

Posted: Saturday 31 August 2024 14:33
by Kedi
Put on complete debug logging and simulate power failure. See wiki for howto.
In that logging should be a cause.
Post (partial) logging here as attachment or spoiler.
Don't forget to put normal logging back.

Re: Monit works partially

Posted: Saturday 31 August 2024 18:35
by waltervl
What version of Domoticz are you using? The issue that Domoticz stops right after a cold reboot (power off) because of the time difference should be fixed in recent versions.

Another option is to have a extra Domoticz startup delay parameter on your environment so it will be sure the time has been synced before Domoticz is started. See for more info wiki page https://www.domoticz.com/wiki/Troublesh ... _cold_boot

Re: Monit works partially

Posted: Saturday 31 August 2024 19:20
by jvmaanen
Updating to the latest version solved the problem. I tested this several times. Now domoticz starts right after the power has been restored.
Thanks for all the advices.