Upstart event when network connectivity to a specific server is available?

0

Is there a way in upstart to code an event to start when network connectivity to a specific machine becomes available? Something based on a ping result would work in my case. The task being started will crash if networking dies, so respawn can start it easily enough, but if the network connection isn't available when it starts it will hang and upstart won't catch it (it's an ffmpeg instance streaming from the local ffserver to another ffserver if that helps highlight the use case).

CoryG

Posted 2013-03-17T07:52:23.427

Reputation: 304

Answers

1

If you know the IP address of the machine you can confirm it's the 'right' machine by confirming the MAC address with something like:

arp -an 192.168.1.123

You will likely need to ping it first so that arp can find it.

Here's a script I'm using that does the same thing:

#!/bin/bash

ip=192.168.1.123 
mac=00:aa:bb:cc:dd:ee


if ping -c 1 -t 1 ${ip} > /dev/null && arp -an ${ip} | grep ${mac}; then
    echo "${ip} has the expected mac addy." 

    # Mount my nfs share (requires sudo, but whatever)
    mount -t nfs -o proto=tcp,port=2049 ${ip}:/ /mnt 
else
    echo "This isn't the network I'm looking for."   
fi

4umfreak

Posted 2013-03-17T07:52:23.427

Reputation: 11