Monitoring and starting service

#1

Hi!

Is there any way to monitor a linux service and if in case it is stopped to start the same?

0 Likes

#2

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

0 Likes

#3

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

0 Likes

#4

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.

0 Likes

#5

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

0 Likes

#6

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.

0 Likes

#7

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.

0 Likes

#8

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?

0 Likes

#9

No, the LWT will send you a message if HA disconnects unexpectedly (but not if it does a clean shutdown).
https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament

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

0 Likes

#10

The MQTT Broker, NR and Home Assistant is in same machine.
Will this work?

0 Likes

#11

sure… is how normally ppl have it

0 Likes

#12

I think you should find out why HA keeps on stopping.

The OS also has tools available to monitor and restart daemons.

0 Likes

#13

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.

0 Likes

#14

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.

0 Likes

#15

Right.
But I will try to look at this second option to monitor and start the service if it is stopped.

0 Likes

#16

I’ll try here but I still do not understand what the LWT deployment would look like.

0 Likes

#17

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.

0 Likes

#18

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?

0 Likes

#19

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

0 Likes

#20

It’s all right.

Thank you and sorry.

0 Likes