VectorLinux
December 21, 2014, 01:55:40 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: How can I make an init script that requires network?  (Read 9138 times)
pierce.jason
Packager
Vectorite
****
Posts: 250



« on: October 14, 2011, 05:00:54 pm »

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
Logged

pierce.jason
Email: $(echo -e "moc\x2eliamg\x40nosaj.ecreip" | rev)
bigpaws
Vectorian
****
Posts: 1862


« Reply #1 on: October 16, 2011, 01:24:31 pm »

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.

HTH

Bigpaws
Logged
M0E-lnx
Administrator
Vectorian
*****
Posts: 3195



« Reply #2 on: October 16, 2011, 06:27:27 pm »

You could test to see if there is an active NIC with an IP address
Code:
ifconfig |grep addr:|awk {'print $2'}|grep -v 127.0.0.1 | cut -f 2 -d :
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
Logged

pierce.jason
Packager
Vectorite
****
Posts: 250



« Reply #3 on: October 16, 2011, 07:17:40 pm »

Great ideas guys, but detecting network is the easy part Wink

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

pierce.jason
Email: $(echo -e "moc\x2eliamg\x40nosaj.ecreip" | rev)
bigpaws
Vectorian
****
Posts: 1862


« Reply #4 on: October 16, 2011, 08:59:49 pm »

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

Bigpaws
Logged
M0E-lnx
Administrator
Vectorian
*****
Posts: 3195



« Reply #5 on: October 17, 2011, 03:22:42 am »

Yrah call it from rc.local and add a "&" to its exec line.  That would throw it to the background and let the boot process continue.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!