Auto reboot when domoticz chrashes?

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!
tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Auto reboot when domoticz chrashes?

Postby tjabas » Saturday 31 December 2016 0:16

Hi!

is there a way to get the raspberry to reboot itself when domoticz chrashes?
Domoticz crashes sometimes and all the events and timer will ofcourse not work.

so is there an easy way to monitor domoticz?

Egregius
Posts: 2150
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Auto reboot when domoticz chrashes?

Postby Egregius » Saturday 31 December 2016 0:36

Of course, a simple bash script can do:

Code: Select all

#!/bin/bash
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=devices&rid=1"`
STATUS=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS" == "OK" ] ; then
   exit
else
   sleep 5
   DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=devices&rid=1"`
   STATUS2=`echo $DOMOTICZ | jq -r '.status'`
   if [ "$STATUS2" == "OK" ] ; then
      exit
   else
      sleep 5
      DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=devices&rid=1"`
      STATUS3=`echo $DOMOTICZ | jq -r '.status'`
      if [ "$STATUS3" == "OK" ] ; then
         exit
      else
         curl -s --connect-timeout 2 --max-time 5 --data-urlencode "text=Domoticz Bad - Restarting" --data "silent=false" http://127.0.0.1/secure/telegram.php
         NOW=$(date +"%Y-%m-%d_%H%M%S")
         cp /volume1/appstore/domoticz/var/domoticz.log /volume1/files/temp/domoticz-$NOW.txt
         sudo /var/packages/domoticz/scripts/start-stop-status stop
         sleep 8
         sudo kill $(sudo netstat -anp | awk '/ LISTEN / {if($4 ~ ":8084$") { gsub("/.*","",$7); print $7; exit } }')
         sleep 8
         sudo /var/packages/domoticz/scripts/start-stop-status start
      fi
   fi
fi

Execute it by cron to run every minute.
Scripts ask domoticz the status of device idx 1.
If status = ok it exits.
If not 2 more tries are executed.
If all 3 fails domoticz is stopped, killed and restarted. Alter those command to suit your needs.

tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby tjabas » Saturday 31 December 2016 0:48

Thanks alot :)

but i have just started this raspberry pi thing and im not yet so good at this but could you please explain a little more how i install this script?

Do i need to istall cron as well?

Egregius
Posts: 2150
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Auto reboot when domoticz chrashes?

Postby Egregius » Saturday 31 December 2016 0:56

I think you should meet my best friend Mr. Google :P

Maybe hard to say it like that, but what if you just copy/paste without understanding what you're doing?
Isn't it better to learn how you must do it? Like Google 'execute bash script by cron'?

If you have a 'normal' linux you should have cron installed.
Check it by 'sudo service cron status'
Should return something with 'Active: active (running)' in it.

create the file with this command:
nano /home/pi/checkdomoticz.sh
paste the code in it
make the file executable:
chmod +x /home/pi/checkdomoticz.sh
add it to cron:
sudo crontab -e
* * * * * /home/pi/checkdomoticz.sh

tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby tjabas » Saturday 31 December 2016 0:59

ok, thanks alot, i will try this :)

tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby tjabas » Saturday 31 December 2016 1:06

Should this:"http://127.0.0.1:8084/ be replaced by the domoticz web adress and port? or should i just leave it like it is?

Egregius
Posts: 2150
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Auto reboot when domoticz chrashes?

Postby Egregius » Saturday 31 December 2016 1:08

You should/must run it on the same device so 127.0.0.1 is good. If you use another port, yes change the port.

tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby tjabas » Saturday 31 December 2016 1:11

ok, no domoticz is on the same device, i just use port 8080, the raspberry, so i have now copy, pasted it and im about to save the file now.
And then :sudo crontab -e
but what are the * * * * * below?
* * * * * /home/pi/checkdomoticz.sh

sorry for my stupid question , but im learning.

tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby tjabas » Saturday 31 December 2016 2:09

I really need to learn more about this linux programming, i installed the script, but i managed to get the whole pi do die, i had to install a old backup:)

But i will give it a try again.

Egregius
Posts: 2150
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Auto reboot when domoticz chrashes?

Postby Egregius » Saturday 31 December 2016 3:13

How can your pi die with this?
Did you change the commands to suit a pie? Those above are for syno.
* * * * *?
Minute hour day dayofmonth dayofweek I think. 5 stars just means every minute

Egregius
Posts: 2150
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Auto reboot when domoticz chrashes?

Postby Egregius » Saturday 31 December 2016 3:37

Almost got it right:

Code: Select all

* * * * *  command to execute
 ┬ ┬ ┬ ┬ ┬
 │ │ │ │ │
 │ │ │ │ │
 │ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
 │ │ │ └────────── month (1 - 12)
 │ │ └─────────────── day of month (1 - 31)
 │ └──────────────────── hour (0 - 23)
 └───────────────────────── min (0 - 59)

manjh
Posts: 165
Joined: Saturday 27 February 2016 13:49
Target OS: Windows
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby manjh » Saturday 31 December 2016 10:43

Is there a way to do this on a Windows-10 server?
Hans

tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby tjabas » Saturday 31 December 2016 12:15

Egregius wrote:How can your pi die with this?
Did you change the commands to suit a pie? Those above are for syno.
* * * * *?
Minute hour day dayofmonth dayofweek I think. 5 stars just means every minute


Well, i really dont know what happened, i rebooted the pi several times and it was running for about 10 minutes every time, then it just stopped.
I must have done something wrong,im really new to this linux thing :) but im learning.

i didnt change anything in these * * * * *, i just copy/pasted and saved the whole line.

i will of course try this again, it seems like a really good way to get domoticz running without any hangups.

User avatar
sincze
Posts: 632
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.6833
Location: Netherlands
Contact:

Re: RE: Re: Auto reboot when domoticz chrashes?

Postby sincze » Saturday 31 December 2016 12:16

tjabas wrote:I really need to learn more about this linux programming, i installed the script, but i managed to get the whole pi do die, i had to install a old backup:)

But i will give it a try again.

If you want a visual interface as well maybe use 'monit' is can also monitor your 'ssh daemon'. Auto restart a process and send you a nice email.

Sent from my SM-G925F using Tapatalk
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby tjabas » Saturday 31 December 2016 12:18

yes i will look into that as well. thank you for the tip.

tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby tjabas » Sunday 01 January 2017 17:06

When i try to make the file executable, is it just to paste this: chmod +x /home/pi/checkdomoticz.sh

in the command line and press enter?

i have done this but nothing really happens.

User avatar
HansieNL
Posts: 290
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Auto reboot when domoticz chrashes?

Postby HansieNL » Sunday 01 January 2017 17:42

@tjabas : With chmod +x you set the file permission to executible. If you don't do that the file can't be run.
Domoticz on Raspberry Pi 2, Homey, Hue lights, Toon thermostat, Logitech Harmony Hub, Fibaro Wall Plug, Fibaro Push Buttons, LightWaveRF Mood Controller, Venz M9 running LibreELEC, Synology NAS

tjabas
Posts: 145
Joined: Sunday 11 December 2016 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Auto reboot when domoticz chrashes?

Postby tjabas » Sunday 01 January 2017 17:49

HansieNL wrote:@tjabas : With chmod +x you set the file permission to executible. If you don't do that the file can't be run.


ok, i understand that, all i need to do is to copy/paste the line in the commandline when using putty and then press enter?
Should i get some sort of notification when i press enter?

User avatar
HansieNL
Posts: 290
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Auto reboot when domoticz chrashes?

Postby HansieNL » Sunday 01 January 2017 23:53

"ls /home/pi/checkdomoticz.sh -l" should give you the answer.
Execute above command before and after chmod. Three - should be change to x.
Domoticz on Raspberry Pi 2, Homey, Hue lights, Toon thermostat, Logitech Harmony Hub, Fibaro Wall Plug, Fibaro Push Buttons, LightWaveRF Mood Controller, Venz M9 running LibreELEC, Synology NAS

User avatar
havnegata
Posts: 86
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi
Domoticz version: v3.6953
Location: Norway
Contact:

Re: Auto reboot when domoticz chrashes?

Postby havnegata » Saturday 07 January 2017 22:17

Egregius wrote:How can your pi die with this?
Did you change the commands to suit a pie? Those above are for syno.
* * * * *?
Minute hour day dayofmonth dayofweek I think. 5 stars just means every minute


I am reading this with great interest :-)
I don't fully understand what is happening line by line in the script, but I see a reference to some folders which don't exist in the Pie. Is it those folders we need to alter to suit the Pie or some other code?


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 4 guests