Script to Detect and Restart a Stopped Service

Periodically I find that the feeder service has stopped. The log shows “Terminating on user request”. What may be causing this on a headless, unattended RPi 3? This just started happening around 4am and/or 4pm. There is nothing in crontab that runs at that time. I have automatic updates that run at midnight. Is there a script that can run frequently to detect a stopped service and restart it?

I have several that have been running for years.
This sounds like a power or interference problem. Are you using a quality power supply? Is the power in your area reliable? Any industrial areas near you that could have power hungry equipment?
Any hints in the logs?
Does the problem happen at exactly the same time?
What are your piaware and OS versions?
Which dongle are you using? Any USB extensions?

The RPi is using a Canakit power supply that is plugged into an APC BR1500G UPS along with 2 other RPi’s. The only log entry clue is “Terminating on user request”. The time varies. I’m in a residential area in a residential city of 120,000. There is no industry in the entire county. It is all residential or tourist services.

The RPi 3 B, 3 B+, 4 B setup:
Buster - Linux 4.19.75-v7l+ armv7l
Piaware 3.7.2
FlightAware Pro Stick Plus (blue)
No other USB devices
WiFi network connection

Other software running:
CUPS
RPiMonitor
Dump1090-FA wiedehopf extensions

It took me awhile (I’m a Linux noob) but I created a solution that actually works. I made a crontab entry that restarts a service if needed.

5-55/5 * * * * sudo systemctl is-active service-name | grep -q “inactive” && sudo systemctl start service-name

Instead of using a workaround for the symptom i would rather try to identify the root cause.
I have also a 3B with the blue FA stick and a certified Raspberry power supply.
Looking on your configuration it seem to be pretty similar to mine

As long as i do not shutdown the device, the service remain running and i am feeding more than only FA, current uptime is 34 days

You are talking about the piaware service?

The anomaly was mostly with fr24feed and adsbexchange. Piaware has been rock solid. There were no issues recorded in the log last night.

As long as their servers do not have issues like this morning :wink:

So adsbexchange should not be an issue in regards to the service stopping.

fr24feed on update via apt stops but doesn’t restart the service i believe.
Their automatic update script will probably restart the service unless the script fails in the middle.

I guess your crontab entry works :slight_smile:

I could use something like this today.
My piaware stopped when I had a short power outage that took out the internet connection - the laptop remained on battery, but somehow the piaware got messed up. I noticed only after an hour or so and restarted the service.