scheduled reboot RPi with Domoticz 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

Post Reply
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

scheduled reboot RPi with Domoticz

Post by NetEye »

In my case the RPi does not work after e few days.
I tryed whatchdog without result.
Now I want to schedule a reboot within the RPi.
I want to do it by: sudo crontab -e
And put in a command: 0 0 * * * sudo reboot
Is this the right way to do?
I have no idea if it works and don't know how to test it.
Can anybody help me with this.
If I posted this in the wrong area, I will replace it.
Thanks
User avatar
Siewert308SW
Posts: 290
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: scheduled reboot RPi with Domoticz

Post by Siewert308SW »

First of all a reboot like you do/want aint good.
"sudo reboot" doesn't take care of Domoticz which needs a proper shutdown.
Meaning, you will hit a time that your database gets corrupt.
It will happen for sure that a read/write to the database is interrupted.
There are many ways like for example a simple bash called from cron.
And then stop domoticz service and afterwards then conduct a reboot.

As for your issue that Domoticz or Rpi aint running anymore after a few days.
Instead of sticking bandages like rebooting you really should look for why it aint running anymore.
Better said, find the culprit.
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: scheduled reboot RPi with Domoticz

Post by NetEye »

Thank you for your quick answer.
I looked over the reasen why its stalls.
I was also finding out for a more stable electric connection.
Nothing was found wrong.
So my last thought was a scheduled reboot.... wrong asbyou said.
Will there something be damager when I do so?
I realy don’t know why the RPi stops.
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: scheduled reboot RPi with Domoticz

Post by NetEye »

The RPi remains running after these days but the communication with ddns or local stops.
I will then have to get whatch dog running in the right way.
I believe thats the only solution after reading your answer.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: scheduled reboot RPi with Domoticz

Post by Egregius »

You should first determine why the Pi stops, or what part of the Pi stops.
Then use a script to monitor that service/port/connection and first try to restart that service.
If that fails you could have the script stop services and reboot.

What do you mean exactly with "the communication with ddns or local stops"?
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: scheduled reboot RPi with Domoticz

Post by NetEye »

I can not enter Domoticz local or from home via DDNS.
The only way to enter it again is a hard reset (power plug in and out), thats why I thought about a scheduled reboot.
After a reboot my project still runs with all of the history so I find no harm in a fixed reboot.
I don’t know how that monitoring works.
Maybe watchdog is an idea?
I looked it over and know hoe to start it but is there a way to start it automaticly after a reboot by a sudo in a start up file?
User avatar
Siewert308SW
Posts: 290
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: scheduled reboot RPi with Domoticz

Post by Siewert308SW »

NetEye wrote: Sunday 28 January 2018 9:25 I can not enter Domoticz local or from home via DDNS.
The only way to enter it again is a hard reset (power plug in and out), thats why I thought about a scheduled reboot.
After a reboot my project still runs with all of the history so I find no harm in a fixed reboot.
I don’t know how that monitoring works.
Maybe watchdog is an idea?
I looked it over and know hoe to start it but is there a way to start it automaticly after a reboot by a sudo in a start up file?
As mentioned earlier.
If data is being written to the database and you do a hard reboot then the change of a corrupt database is high.
But if you do think it would harm, then be my guest but do me a favor, make regular backups.

As for your service dying, Is your RPI connect via wifi or utp?
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: scheduled reboot RPi with Domoticz

Post by NetEye »

After a few hard resets by plug in and out the RPi has to be re-installed and I hope with a software reset not? Maybe I think wrong??
My RPi is connected bij utp rj45 connector cable to my router
User avatar
Siewert308SW
Posts: 290
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: scheduled reboot RPi with Domoticz

Post by Siewert308SW »

NetEye wrote: Sunday 28 January 2018 9:44 After a few hard resets by plug in and out the RPi has to be re-installed and I hope with a software reset not? Maybe I think wrong??
My RPi is connected bij utp rj45 connector cable to my router
Again, Domoticz needs a gentle reboot.
Hard reboot like "sudo reboot" doesn't shutdown Domoticz.

You need for example:
- sudo service domoticz.sh stop
- sudo reboot

As for your connection.
If it was WiFi then high likely it was the WiFi to be pointed as culprit.
I don't have experience with the specific setup as you run it.
So can't give any propper comment on that or point a sollution.
But i think you should look why the service is stopped.
Look into the logs a find a hunch why.
Also if it's a service then maybe better to write a simple bash script to watch the service and if its failen then restart service instead of rebooting.
But main thing is, find the cause as sticking bandages isn't the sollution.

Code: Select all

service=`sudo service <your_service> status | grep Active | awk '{print $3}'`

if [[ $service != "(running)" ]]
    then
                echo 'Service is not running. trying to restart the service...'
                sudo service <your_service> restart
elif [[ $service == "(running)" ]] 
	then
                echo 'Service is running...'
fi
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: scheduled reboot RPi with Domoticz

Post by NetEye »

Thanks for the helpfull advise.
I think for now those bash and checkups is to big for me.
For now I wil run watchdog as : https://www.raspberrypi.org/forums/view ... p?t=147501
on my domoticz version 4834.
After that I will look for the reason why all fails.
Thanks for your advise
I will forget the scheduled reboot
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: scheduled reboot RPi with Domoticz

Post by DanM »

I restart my system nightly - I call the json to restart Domoticz (/json.htm?type=command&param=system_reboot). I assume Domoticz own reboot command exits cleanly (although I must confess I dont know for sure).
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: scheduled reboot RPi with Domoticz

Post by Egregius »

I would suggest using the script provided in http://www.domoticz.com/forum/viewtopic ... 80#p137092
If the web gui isn't available you can't call the reboot command of domoticz.
User avatar
elythomaslumber
Posts: 56
Joined: Friday 12 July 2013 13:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Solingen; Germany
Contact:

Re: scheduled reboot RPi with Domoticz

Post by elythomaslumber »

I´m running Domoticz on an very old RP since 2012 on Release 1.18 and yesterday updated to 3.8.
But all the years I had only a few sudden stopps from Domoticz. So 99% of all time it runs like a charme.

Therefore I would try to find the reason. Here are some ideas where to find a possible problem:
- I´m using a power supply which is 500mA above the proposed type
- I use only Class 10 SD cards; maybe using a different card supplier would help
- did you expand the file system? http://geek-university.com/raspberry-pi ... ilesystem/
- I'm monitoring the board devices like CPU load (normally 3-6% on my RP) and Memory usage (RAM)
- once a day I clean up the RAM via Cronjob calling this script:

Code: Select all

#!/bin/bash

free -m
sync
sudo echo 3 > /proc/sys/vm/drop_caches
free -m
Once a week on Sunday exactly 06.26 in the morning my CPU usage goes on over 90% for a very short time; dont know why but it seems that something is cleaning up something

Hope that helps a bit or give you fresh ideas...
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: scheduled reboot RPi with Domoticz

Post by EddyG »

Siewert308SW wrote: Sunday 28 January 2018 10:07
NetEye wrote: Sunday 28 January 2018 9:44 After a few hard resets by plug in and out the RPi has to be re-installed and I hope with a software reset not? Maybe I think wrong??
My RPi is connected bij utp rj45 connector cable to my router
Again, Domoticz needs a gentle reboot.
Hard reboot like "sudo reboot" doesn't shutdown Domoticz.
Are you sure? reboot is the same as shutdown -r
In modern Linux distro's the shutdown issues an init 1 or init 6 and send all processes (except init, which gets killed) the SIGTERM.
But I might be wrong.
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: scheduled reboot RPi with Domoticz

Post by NetEye »

I desided to listen to you all and not use the option of reboot or shutdown -r.
I overlooked all about watch dog and I successfully have it running and also have it automatically start up after a restart.
Only one problem accused after: sudo systemctl status watchdog -l
It contains a message: "cannot open /dev/watchdog (errno = 16 = 'Device or resource busy')" at one of the row.
See the picture for details.
So I can see watchdog is running and also starts after a restart.
Can anyone help me to solve this.
Looking on Google did not give me the solution.
I will also publish this problem in a new topic in this forum to reach more people.
regards
Attachments
Schermafbeelding 2018-01-28 om 18.59.06.png
Schermafbeelding 2018-01-28 om 18.59.06.png (302.9 KiB) Viewed 6282 times
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: scheduled reboot RPi with Domoticz

Post by EddyG »

Is "/dev/watchdog" present? If you do "ls -al /dev/watchdog" it should look like:

Code: Select all

crw------- 1 root root 10, 130 Jan 14 11:28 /dev/watchdog
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: scheduled reboot RPi with Domoticz

Post by NetEye »

Dear Eddy,
Thanks for your fast reaction...super
When I typ " sudo nano /dev/watchdog" it says it is a device file which is empty (see both pictures 1 and 2).
Do I have to put: crw------- 1 root root 10, 130 Jan 14 11:28 /dev/watchdog in that empty file?
Or do I have to do something with: ls -al /dev/watchdog
Or do something with both?
regards
Attachments
1.png
1.png (99.34 KiB) Viewed 6226 times
2.png
2.png (49.46 KiB) Viewed 6228 times
extremeaudio
Posts: 47
Joined: Tuesday 24 November 2020 17:57
Target OS: Linux
Domoticz version:
Contact:

Re: scheduled reboot RPi with Domoticz

Post by extremeaudio »

I am also toying with the idea off rebooting my domoticz server once in a while along with some shellies.

The domoticz web UI reboot command is

http://127.0.0.1:8082/json.htm?type=com ... tem_reboot

I assume this must be doing a graceful reboot unlike sudo reboot?

Along with the domoticz server, I want to issue reboot to a couple other shelly devices also, some which misbehave after some time randomly and correct when rebooted. Their reboot commands are a simple "http://192.168.1.100/reboot" type.

How can I put all of these commands into one bunch so that 1 domoticz switch reboots all of them?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest