Systemd Service Keeps Failing, how can I have it start if status is failed?

So I followed this youtube video on setting up RTL-433 service on a Ubuntu server. Problem is, it seems to keep failing after a while. Sometimes doing a systemctl start service doesn't work and I will have to reboot the system and then it will work. It will work for a while and later in the day it will suddenly stop. Sometimes I can do a systemctl start, but sometimes not.

Anyone know how I can have this service constantly up and running, and restart if it fails?

10 points · 12 comments · view on lemmy.world

12 Comments

z2k_@beehaw.org · 6 pts · 3y (6 replies)

To have it automatically restart on failure, you can add the following to your systemd unit:

[Service]
Restart=on-failure
RestartSec=5s

See this blog post for more information.

But to find the root cause of why it's failing, you can run systemctl status <service> when it fails to get the most recent logs and hopefully an error as to why it failed.

falchy@sopuli.xyz · 5 pts · 3y (5 replies)

Still relatively beginner, but wouldn't 'journalctl -u nameofservice.service' also give you in depth logs over a longer period of time?

z2k_@beehaw.org · 1 pts · 3y

Yes, you can get the full log with journalctl.

redawl@sh.itjust.works · 1 pts · 3y (3 replies)

Adding to this, journalctl -fu service will jump to the bottom of the log and effectively tail -F the log so any new output will be appended to your terminal

falchy@sopuli.xyz · 2 pts · 3y (1 reply)

Well that's way easier than my utilization of less or watch or tail that Ive been doing.

redawl@sh.itjust.works · 1 pts · 3y

Yeah it's pretty slick

nick_99@sh.itjust.works · 2 pts · 3y

I second journalctl -f -u SERVICE_NAME.service it's great and just works well. The .service isn't required, but it's a good habit to get into since systemd also has mounts and timers.

llii@feddit.de · 1 pts · 3y

I also would recommend to find out why the service crashes.

You can try to increase the verbosity of rtl-433 with the arguments -v, -vv, -vvv and -vvvv. With every „v“ you get more information on what the program does.

Maybe you can get a hint why it crashes.

Edit: For this it’s best to run rtl-443 directly in a terminal without the service so that you can directly see the output.

nixfreak@sopuli.xyz · 1 pts · 3y

journal -xu, what do you get?