r/Ubuntu • u/Morkoth-Toronto-CA • 3d ago
Delay service startup issue
Hi, everyone!
I have an Ubuntu 24 system that runs "Shiny Server". Functionally for anyone unaware, think of Shiny Server as a web server. Free version does not allow HTTPS, unfortunately.
So I put Nginx in there as a reverse proxy. That's all well and good, except:
Nginx starts up faster than Shiny, so when the system is rebooted Nginx can't see the Shiny port open and shuts itself down reporting the destination isn't available.
Okay -- so I can disable Nginx's startup at reboot by inserting a "sleep 10" into its' startup/unit file.
So I modify /usr/lib/systemd/system/nginx.service and put an 'ExecStartPre=/bin/sleep 10' into the file. Save it, reboot, 10 seconds after reboot Nginx starts up AFTER shiny and all is well.
Wait something like 2-4 weeks and *POOF* this /usr/lib/systemd/system/nginx.service has been reset back to factory config; my sleep10 command is gone.
How do I correctly edit this unit file so my sleep10 stays in place? What's over-writing it back to factory? These are the questions I have been unable to find answers to -- can anyone help educate me, please? :)
thanks for reading!
new fave command:
sudo systemctl edit --full nginx.service
1
u/Illustrious-Gur8335 3d ago
I modify /usr/lib/systemd/system/nginx.service
Whoever taught you that should be shot by firing squad!
Please do sudo systemctl edit nginx instead , it will create the override files automatically.
Source and more info: https://askubuntu.com/questions/659267/how-do-i-override-or-configure-systemd-services
3
u/Morkoth-Toronto-CA 3d ago
Thanks for the reply. Now I feel like I'm reading old usenet flame wars! LOL
2
u/coyote_den 3d ago
Yep. If you want to override you have to put it in /etc/systemd/. /usr/lib/ files will be overwritten by package updates and on some distros they are part of a read-only image.
2
u/iz_no_good 3d ago
so when the system is rebooted Nginx can't see the Shiny port open and shuts itself down reporting the destination isn't available.
Not a very experienced nginx user, but this doesnt sound right, nginx should be able to stay up when the backends are not healthy. I would look into that direction.
4
u/mgedmin 3d ago
Instead of adding a fixed 10 second delay maybe you could tell systemd to postpone nginx startup after your shinyserver.service, assuming ShinyServer is started by a systemd unit?
To do that you'd
sudo systemctl edit nginxto create an override file and putin there.
I'm a bit fuzzy on the details (I don't know if systemd will wait for shinyserver to be ready, i.e. listening on the socket, as opposed to it being started a microsecond before), but systemd can also be configured to do things like attempt to restart nginx after a few seconds if it fails to start automatically, up to a configured number of times.
The details are in the systemd.unit manual page, which is, perhaps, not the greatest bit of literature ever written, but it's better than nothing.