AuthorTopic: How can I make an init script that requires network? (Read 16523 times)

I created a startup script today for a network daemon that acts in client mode. The daemon must connect to an external server via the network. If the network isn't present when the daemon starts, then it is gameover for the daemon.

I created the symlink in rc4.d to be numerically positioned right after sshd. I figured by the point that sshd starts up then I'd probably have network connection. IIRC sshd was S51 so I made my new script at S55.

Looking in the logfiles it appears that I get DHCP several lines after my S51 and S55 init scripts are executed.

I couldn't trace down where dhcpcd is started up.

What should I do inorder to ensure my S55 rc4.d init script starts after dhcp is started?

The concept I'm having a hard time wrapping my head around is how to efficiently wait/loop while waiting on dhcp. The scripts under rc#.d/ are blocking, so system startup would completely halt while my daemon's init script loops and waits for internet.

It seems that bash has the ability to define a function, and then run it in the background while the defining script exits. In this case I could define a do_it() type function for the start) case to call, and I could background that function such as "do_it&" to allow the init script to exit.

I worked up a 'lil tester script for this backgrounded functions idea, and it seems to work spot on. Only thing is I can not get my stop) case to run a "killall do_it". This last thing would only be relevant during the short time during system startup where I am waiting for DHCP to respond.

http://pastebin.com/0wCEEfKtThink something along these lines would be a good option to do the trick with backgrounding the function called in start) case?