I once found a script (I don't remember where all I have is my bash_history).
This is not the solution, it's a workaround.
I know it's not exactly what you asked for but it may be useful.
It uses the microphone to detect silence.
This is my script:
rec -t raw /dev/null rate 32k silence 1 0.1 4% 1 1.0 15%;
- The 1.0 represents the silence time (1 second) change it to something longer to make sure it's not a music pause.
- The 15% represents the silence threshold use smaller values for quiet places, higher values for noisy places.
- clementine -t is the command I use to toggle my music player state aka clementine, change this with the command you use to restart openFM.
- sleep 1: make a small delay to give things some time.
You can read more here: http://linux.die.net/man/1/rec and here: End sox recording once silence is detected
You can also just play making pings to a host you know that will always be online until it fails, then keep trying more pings until it works again. at this point you know the connection was gone but is back again so you should restart openFM.
This can be done with 2 loops inside a third one.
while ping -c 1 126.96.36.199; # do we have connection?
# the connection seems to be gone...
until ping -c 1 188.8.131.52; # do we have connection?
# the connection seems to be back again...
# restart here your service
Note the -c 1 means make only one ping (then we call it again). It doesn't have to be google's DNS who you ping to, change the sleep times as you like.