check domoticz with monit and restart when check fails Topic is solved

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

Moderators: leecollings, remb0

Theedoek
Posts: 9
Joined: Wednesday 08 August 2018 22:09
Target OS: -
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by Theedoek »

That worked thanks. Finally solved it by checking the access rights. My monit control file now looks like this:

Code: Select all

###############################################################################
## Monit control file
###############################################################################

SET DAEMON 300    # check services at 2-minute intervals
WITH START DELAY 240    # optional: delay the first check by 4-minutes (by default Monit check immediately after Monit start)
SET LOGFILE /var/ramdrive/monit.log
SET IDFILE /var/lib/monit/id
SET STATEFILE /var/lib/monit/state
SET EVENTQUEUE
    BASEDIR /var/lib/monit/events
    SLOTS 100

SET MAILSERVER
    <mailserver address> port 465
    USERNAME "<username>" PASSWORD "<password>"

SET HTTPD PORT 2812
ALLOW localhost
ALLOW 10.0.0.0/24       # allow local network
ALLOW admin:monit      # require user 'admin' with password 'monit'
ALLOW @monit              # allow users of group 'monit' to connect read/write
allow @users readonly     # allow users of group 'users' to connect readonly

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"
Next step is to figure out why monit reboots my Raspberry Pi every exact 3 hours :S
plenkske
Posts: 5
Joined: Saturday 01 February 2020 15:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by plenkske »

I have followed the steps in the wiki https://www.domoticz.com/wiki/Monitoring_domoticz
All seems to be fine up to the point of trying

sudo monit start all


Then I get the following message:
There is no service named "domoticz"


Someone knows why ?
I tried the different configs posted in this thread and checked the ip's and all.
And yes, domoticz is running.



EDIT:
I have got it working now.
I think I forgot to realod the monit service. Got it all working after stopping the service and starting it again. No more error messages when I use the reload command or start command.
And I can see the status in both putty and webservice.
Kruu
Posts: 49
Joined: Tuesday 17 January 2017 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: check domoticz with monit and restart when check fails

Post by Kruu »

Is it possible thar monit restarts my RPI3 (recently upgraded to Buster, and upgraded Domoticz)?

After all upgrades I get random reboots od RPI, middle of night, during day, every 2-3 days.

Before all updates RPI was allive 180 days.

thx
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: check domoticz with monit and restart when check fails

Post by jake »

Kruu wrote:Is it possible thar monit restarts my RPI3 (recently upgraded to Buster, and upgraded Domoticz)?

After all upgrades I get random reboots od RPI, middle of night, during day, every 2-3 days.

Before all updates RPI was allive 180 days.

thx
Well, check your monit log it will tell you!
Kruu
Posts: 49
Joined: Tuesday 17 January 2017 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: check domoticz with monit and restart when check fails

Post by Kruu »

Yes, monit did it. Because domoticz was not running, but havent noticed that domoticz was not running in that period.

Is it possible that monit have some problems with new version of Domoticz?
Spoiler: show
[CEST Apr 5 12:11:01] error : 'domoticz' process is not running
[CEST Apr 5 12:11:01] info : 'domoticz' trying to restart
[CEST Apr 5 12:11:01] info : 'domoticz' start: '/etc/init.d/domoticz.sh start'
[CEST Apr 5 12:11:31] error : 'domoticz' failed to start (exit status 0) -- '/etc/init.d/domoticz.sh start': Starting domoticz.sh (via systemctl): domoticz.service.

[CEST Apr 5 12:16:31] error : 'domoticz' process is not running
[CEST Apr 5 12:16:31] info : 'domoticz' trying to restart
[CEST Apr 5 12:16:31] info : 'domoticz' start: '/etc/init.d/domoticz.sh start'
[CEST Apr 5 12:17:01] error : 'domoticz' failed to start (exit status 0) -- '/etc/init.d/domoticz.sh start': Starting domoticz.sh (via systemctl): domoticz.service.

[CEST Apr 5 12:22:02] error : 'domoticz' process is not running
[CEST Apr 5 12:22:02] info : 'domoticz' trying to restart
[CEST Apr 5 12:22:02] info : 'domoticz' start: '/etc/init.d/domoticz.sh start'
[CEST Apr 5 12:22:32] error : 'domoticz' failed to start (exit status 0) -- '/etc/init.d/domoticz.sh start': Starting domoticz.sh (via systemctl): domoticz.service.

[CEST Apr 5 12:27:32] error : 'domoticz' process is not running
[CEST Apr 5 12:27:32] info : 'domoticz' trying to restart
[CEST Apr 5 12:27:32] info : 'domoticz' start: '/etc/init.d/domoticz.sh start'
[CEST Apr 5 12:28:02] error : 'domoticz' failed to start (exit status 0) -- '/etc/init.d/domoticz.sh start': Starting domoticz.sh (via systemctl): domoticz.service.

[CEST Apr 5 12:33:02] error : 'domoticz' service restarted 5 times within 5 cycles(s) - exec
[CEST Apr 5 12:33:02] info : 'domoticz' exec: '/sbin/reboot'
[CEST Apr 5 12:33:02] error : 'domoticz' process is not running
[CEST Apr 5 12:33:02] info : 'domoticz' trying to restart
[CEST Apr 5 12:33:02] info : 'domoticz' start: '/etc/init.d/domoticz.sh start'
[CEST Apr 5 12:33:04] error : 'domoticz' failed to start (exit status -1) -- no output
[CEST Apr 5 12:33:05] info : Monit daemon with pid [479] stopped
[CEST Apr 5 12:33:05] info : 'raspberrypi' Monit 5.20.0 stopped
[CEST Apr 5 12:33:26] info : Starting Monit 5.20.0 daemon with http interface at [localhost]:2812
[CEST Apr 5 12:33:27] info : Monit start delay set to 300s
[CEST Apr 5 12:38:52] info : 'raspberrypi' Monit 5.20.0 started
[CEST Apr 5 13:05:44] error : HttpRequest: access denied -- client [127.0.0.1]: missing or invalid Authorization header
[CEST Apr 5 13:22:47] info : Monit daemon with pid [466] stopped
[CEST Apr 5 13:22:47] info : 'raspberrypi' Monit 5.20.0 stopped
[CEST Apr 5 13:22:58] info : Starting Monit 5.20.0 daemon with http interface at [localhost]:2812
[CEST Apr 5 13:22:58] info : Monit start delay set to 300s
[CEST Apr 5 13:27:56] info : Monit daemon with PID 477 awakened
[CEST Apr 5 13:27:58] info : 'raspberrypi' Monit 5.20.0 started
[CEST Apr 5 13:28:06] error : HttpRequest: access denied -- client [127.0.0.1]: missing or invalid Authorization header
[CEST Apr 5 13:28:52] info : Awakened by User defined signal 1
[CEST Apr 5 13:28:53] info : Monit daemon with pid [477] stopped
[CEST Apr 5 13:28:53] info : 'raspberrypi' Monit 5.20.0 stopped
[CEST Apr 5 13:30:45] info : Starting Monit 5.25.2 daemon with http interface at [localhost]:2812
[CEST Apr 5 13:30:45] info : Monit start delay set to 300s
[CEST Apr 5 13:31:12] info : Monit daemon with PID 2719 awakened
[CEST Apr 5 13:31:26] info : Monit daemon with PID 2719 awakened
[CEST Apr 5 13:31:28] info : Monit daemon with PID 2719 awakened
[CEST Apr 5 13:35:42] info : Monit daemon with PID 2719 awakened
[CEST Apr 5 13:35:45] info : 'raspberrypi' Monit 5.25.2 started
[CEST Apr 5 13:36:13] info : Awakened by User defined signal 1
[CEST Apr 5 13:36:14] info : Monit daemon with pid [2719] stopped
[CEST Apr 5 13:36:14] info : 'raspberrypi' Monit 5.25.2 stopped
[CEST Apr 5 13:36:25] info : Starting Monit 5.25.2 daemon with http interface at [localhost]:2812
[CEST Apr 5 13:36:26] info : Monit start delay set to 300s
[CEST Apr 5 13:40:24] info : Monit daemon with PID 480 awakened
[CEST Apr 5 13:41:26] info : 'raspberrypi' Monit 5.25.2 started
[CEST Apr 5 13:46:26] info : Awakened by User defined signal 1
goblin
Posts: 37
Joined: Sunday 23 July 2017 14:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Haarlemmermeer
Contact:

Re: check domoticz with monit and restart when check fails

Post by goblin »

hello all,
one way or another but Domoticz main crashes after prox 10 hours since i have been struggling with master/slave RPI.
I cannot find the reason so installed Monit for help.
But the webpage shows domoticz not connected. I have checked the setting in security trusted network and 127.0.0.1 is present.
any idea



(2 x RPI and a boatload of ESPeasy)
Attachments
monit.png
monit.png (150.7 KiB) Viewed 437 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest