Cooking up the Treats > Help Wanted-Developers

How can I make an init script that requires network?

(1/2) > >>

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?

Thanks  for any pointers,
Jason Pierce

First  you could use wait or sleep for a period of time until the
network would normally be up and running.

Second you could make a script using expect.

Third make a script using ping then exec the script.

Fourth would be use a test of ifconfig and then run or
drop the script.



You could test to see if there is an active NIC with an IP address

--- Code: ---ifconfig |grep addr:|awk {'print $2'}|grep -v | cut -f 2 -d :
--- End code ---
You can run this in a loop for 10 seconds or so and break after you get a hit of give up after the allotted time

Great ideas guys, but detecting network is the easy part ;)

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.
Think something along these lines would be a good option to do the trick with backgrounding the function called in start) case?

You could also move your script to /etc/rc.d/rc.local. That is where my network
scripts are started which is after dhcp.



[0] Message Index

[#] Next page

Go to full version