Page 1 of 1

[Solved] Reboot or Shutdown Raspberry safely closes Domoticz?

Posted: Wednesday 12 June 2019 15:58
by McJohn
We are confused by different posts about how to safely shutdown the Domotics database.
This post says:

https://www.domoticz.com/forum/viewtopic.php?t=21895
Siewert308SW wrote: Saturday 27 January 2018 13:57 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.
But in another post stays;

https://www.domoticz.com/forum/viewtopi ... 11&t=13736
Egregius wrote: Monday 17 October 2016 16:11

Code: Select all

http://192.168.2.10:8084/json.htm?type=command&param=system_shutdown 
should do it as that is the url that the www gui calls.
So, what's the difference between a sudo reboot (or shutdown) or by example a reboot with an ssh session (or reboot in the GUI of the Raspberry) for Domotics?
Is it always so that a reboot or shutdown into the Raspberry not safely closes the Domotics database?

Thanks in advance for the explanation.

Re: Reboot or Shutdown Raspberry safely closes Domoticz?

Posted: Wednesday 12 June 2019 16:49
by EddyG
Normally Domoticz is started as a service under control of systemd.
When you issue a command like "sudo reboot" then system will close all open files and reboot.
It does a kind of "sudo systemctl stop <service>" for all services, which issues a TERM signal to the running services.
So no harm will be done, I did it thousands of times.

Re: Reboot or Shutdown Raspberry safely closes Domoticz?

Posted: Wednesday 12 June 2019 16:59
by McJohn
Thank you very much for the quick response and the tranquillized words!

Then this post don't give the right information:
Siewert308SW wrote: ↑Saturday 27 January 2018 14:57
First of all a reboot like you do/want aint good.
"sudo reboot" doesn't take care of Domoticz which needs a proper shutdown.

Re: Reboot or Shutdown Raspberry safely closes Domoticz?

Posted: Wednesday 12 June 2019 17:11
by EddyG
No, it does not. Like I wrote, I did it thousands of times and never run into trouble.
Read https://en.wikipedia.org/wiki/Systemd and all the links in it and you will be an expert on this subject. ;)
Or https://www.linux.com/learn/understandi ... ng-systemd
A command like "systemd-analyze blame" analyse the startup of different services.

Re: Reboot or Shutdown Raspberry safely closes Domoticz?

Posted: Wednesday 12 June 2019 20:46
by McJohn
Thank you very much for all the information! :)

OK, what I understood is that systemd "kills" all the running services at a reboot or shutdown?

Isn't it be a nicer way to place a file into the directory /lib/systemd/system-shutdown with a script with the command:
'sudo service domoticz.sh stop" ?

Re: Reboot or Shutdown Raspberry safely closes Domoticz?

Posted: Saturday 15 June 2019 9:35
by EddyG
No, you cannot just put a script in /lib/systemd/system-shutdown.
Systemd is the proper way to control boot, reboot and shutdown if it is installed.
Services are getting a proper SIGTERM signal instead of the SIGKILL signal and are allowed to close files in the right way.
It's close to what the old "sudo service domoticz.sh stop" would do.
B.t.w. the old "sudo service" is transfered to "sudo systemctl", which is used to control systemd services.

Re: Reboot or Shutdown Raspberry safely closes Domoticz?

Posted: Sunday 16 June 2019 11:54
by McJohn
Thanks for the clear explanation. Case closed and everything is working well.
(For a Raspberry without a screen, we put a bash script with espeak command, into the /lib/systemd/system-shutdown directory
it says "Shutdown the system" trough the speaker, so, we know the Raspberry is on halt :D )