Delay startup for service until network is established
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Delay startup for service until network is established
Hello everyone,
can DebIan during booting wait for another server in the Network before starting certain services?
Background:
I have a few servers in our home. A file server running DebIan and some Mini-Servers (Raspberry Pis running Raspbian) fulfilling various tasks from music streaming to TV Recording. The Mini-Server need the file-server to function properly.
If the servers have to restart together (e.g. after a power outage) the Mini-Servers boot a lot quicker than the file server. Correspondingly the Mini-Servers fail to mount the samba shares on the fileserver using the Mini-Servers fstab. This causes hickups for the services on the Mini-Servers.
I have tried some dirty workarounds which work by stopping the services after booting, looping until the server is found and then starting the services again.
This works mostly fine if I don't forget to add any service to this list and they don't cause too much chaos in the few seconds they are alive without the server.
I have looked into messing with the scripts in /etc/rc3.d but this is unreliable.
I would love to have a clean solution. Thank you everyone for your time and energy.
I remember reading way back that this was one of the use examples of why systemD was sucking up every functionality under the sun. If you're using Jessie or newer, you may want to look into that. It may require you modifying the service file itself. I'm sorry I can't help you more, but if no one else can help, I hope I at least pointed you in the right direction.
I have done enough of this to be dangerous, but I'll try to get you going on the system and services.
First is that the listings under /etc/rc*.d are indicators of how those services are started on each run level. The actual scripts are found in /etc/init.d.
Second, look into the update-rc.d command. This is the command used to install/uninstall services.
Third, be careful, you can really hose up your system if you do something really wrong. Read through examples on the net and get a good feel for what is going on. You should be fine if you are reasonably careful.
What you want to do is get the networking service to start before your servers. There are headers (LSB headers) in the scripts in /etc/init.d that indicate what if any services should start, already be started, etc. These sections are small and begin with ### BEGIN INIT INFO and end with ### END INIT INFO so they are easy to find. These are used in conjunction with the update-rc.d command to give the system a clue as to how and when things should start.
I don't think there are any rules that say services must start one after the other so you may have to play with which run level your servers start on. Also the LSB numbers you see prepended to the listings under /etc/rcX.d have an impact on the order of things within a run level, but again, there are no guarantees that things will start in 1,2,3 fashion. You may get 1,2 start and 2 isn't fully up, then 3 starts, etc.
@goumba: I am running Raspbian 8 Jessie on the server in Mini-Servers. But I am testing these Solutions on a virtualized x64 Version of Debian 8.6
@edmonstone: Thank you very much for the advice with the /etc/init.d folders. I have made a few tests and my impression is that
1) within one runlevel, the services are all started seemingly at once
2) wait and sleep commands in scripts are ignored
3) scripts in /etc/init.d mess up changing runlevels.
It's also not enough to start the services in the right order. The startup process has to wait at a certain point for a condition is fulfilled.
If my fileserver is up I can restart the mini-servers without problems. If I start everything at once my fileserver is to slow in booting, which causes the hickups in the mini-servers.
Yes, and the LSBInit headers can't always fix these start dependencies. Even different run levels sometimes don't do it either. I have added to scripts so that they wait for an ip address to be assigned, a proc file to be created, etc. Maybe you can find a solution by modifying the mini-server start scripts?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.