-   Linux - Software (
-   -   Delay startup for service until network is established (

incognito3604 09-28-2016 09:25 AM

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?


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.

goumba 09-28-2016 10:14 AM

Which release of Debian?

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.

edmonstone 09-28-2016 12:03 PM

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.

I hope this helps.

incognito3604 09-28-2016 04:16 PM

Hi everyone,

and thank you very much for you contributions.

@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.

edmonstone 09-28-2016 06:05 PM

Hi incognito3604,

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?

All times are GMT -5. The time now is 03:41 PM.