Hi!
Is there any way to monitor a linux service and if in case it is stopped to start the same?
Hi!
Is there any way to monitor a linux service and if in case it is stopped to start the same?
for instance to see node if node red service is status:
systemctl is-active nodered.service
To start/stop/restart
sudo service nodered start/stop/restart
What hardware/OS are you running? If it is a pi and you have updated using the bash <(curl script then it will automatically restart if it stops, unless it continuously crashes in which case it will give up after a few goes. The script that controls this is /lib/systemd/system/nodered.service
What I want to monitor is the service of another application (HA - Home Assistant).
The service is stopping halfway unexpectedly. I wanted to monitor this service if it were to stop the red node would start it.
The Home Assistant and the Red Node are running on the same Raspberry Pi.
The raspberry pi does not turn off, only the Home Assistant service it stops. The NR continues to run normally.
with the commands I posted you, u can inject a timestamp every x seconds and run an exec node with this command and monitor the output and if is stopped then trigger another exec node to start it, however maybe will be good idea to check why service stops to solve the issue…
regards
I have already made several changes in the Home Assistant to try to identify why it is entering stop mode but could not identify the reason.
In parallel I am seeing this possibility.
Do you have HA writing to MQTT? If so then subscribe to the Last Will And Testament message which will be sent if HA crashes.
Yes, I already have the mqtt set up.
Then it would be more or less a watchdog, I send the command and wait for the Home Assistant to respond?
No, the LWT will send you a message if HA disconnects unexpectedly (but not if it does a clean shutdown).
Otherwise then yes, use a watchdog method. Subscribe to something that HA publishes regularly (add that to the HA setup if there isn't already something) and if it stops coming then HA has stopped
The MQTT Broker, NR and Home Assistant is in same machine.
Will this work?
sure… is how normally ppl have it
I think you should find out why HA keeps on stopping.
The OS also has tools available to monitor and restart daemons.
I already did everything and could not identify the problem.
I declined the size of log files, and database went one time without stopping. Now it sometimes reboots.
You may want to discuss this on the Home Assistant forum as it isn’t related to Node-RED and they maybe able to help you identify why HA is restarting.
Right.
But I will try to look at this second option to monitor and start the service if it is stopped.
I’ll try here but I still do not understand what the LWT deployment would look like.
Using NR or MQTT to monitor a failing process is just a band-aid over your real problem, As Nick said, head over to the HA forum for support.
Failing that, google what systemd can do to restart failed daemons.
Another thing,
I have the HA component installed in the NR and it is already working here.
I saw an interesting thing that in the HA node is appearing disconnected.
Would not it be possible to get this status and make a comparison and soon after starting the service?
dedy I explained you already one way to monitor the status of the service and start it up again upon disconnection,
However as other people told you I think your are focusing on the incorrect path…
Try t see whatever log that HA gives you or some help to solve the issue with HA, one main test to be done is to make a clean install with latest versions and see what happens,
If I understood well is a rasberry what makes easy to backup the micro sd card and recover your image at any moment, but this is an exercise that maybe you should do if you can not troubleshoot HA further.
If you have a puncture on a wheel on your car, solution is not try to be blowing air all the time on it to keep car running…
Check also how is your system running in terms of HD space, ram, processor,temperature
etc…
Regards
It’s all right.
Thank you and sorry.