2

I have a script running on machine A that needs to trigger the reboot of machine B and then wait until machine B is fully back up. This actually needs to happen multiple times in succession, so keeping the wait time to a minimum is somewhat important. (It's an automated test of varying boot parameter values.)

These machines are running Linux, so I figure the basic approach should be to install a late-running (e.g. priority 99) init script on machine B that somehow sends a message to machine A. I plan to install the script using update-rc.d ${script_name} start 99 S .. However, where I'm stuck is how to send and wait for the message.

I figure there must be some sort of message queue or coordinator service that I can just script out of the box. For instance, Zookeeper should be capable, though how to script it is surprisingly non-obvious. I could write a little client/server program to do this (presumably using a TCP socket), but I was hoping for a simpler solution. The setup on machine B needs to be done entirely by the script on machine A, so steps like compiling or installing scripting language modules would ideally be avoided.

Thanks for any suggestions!

3 Answers 3

2

You could also make a simple network listener using netcat or socat that starts late and the other host repeatedly checks for. Another way to solve this would be to send an automatic "I'm Alive" message through mail from rc.local to the other machine and pick it up with a script from a .forward or .qmail file.

1
  • nc sounds like the best option so far. Set up a listener (with nc -l 1234) on machine A before reboot, and then have machine B send it a message (echo "I'm alive" | nc machine-A 1234) from an init script. Jul 6, 2011 at 22:49
2

Sounds like you want to look at the heartbeat daemon. That's exactly what it's made for: monitoring sets of peers.

1
  • Good suggestion. I agree that it seems like it should be the right tool, but like Zookeeper, it's not clear how to script this task with it. I could probably poll crm_mon in a loop, grep'ing for some up/down indicator, though I don't see its output documented anywhere. If I had a cluster I was already monitoring, I think this would be the right answer, but in this case, it seems like overkill. Jul 6, 2011 at 23:12
0

Couldn't you just ping periodically and then check ping's exit code?

If a ping is successful, the exit code should be 0:

$ ping -c 1 -t 1 1.2.3.4
...
$ echo $?
0

If unsuccessful, it'll be 2:

$ ping -c 1 -t 1 5.6.7.8
...
$ echo $?
2
3
  • 1
    I don't think so because it's important that various services (e.g. Apache httpd) are running before the script continues, not just network connectivity. That's what I meant by "fully back up". Sorry if I was too subtle about that. Jul 6, 2011 at 17:29
  • In that case, couldn't you just try to snag a static file from your webserver using curl/wget, and consider the server "up" when you get a HTTP 200?
    – MrTuttle
    Jul 6, 2011 at 19:57
  • httpd was just an example; there may be other services, and httpd might not be running. Of course, if I wrote out a file in the late-running init script (and deleted that file before reboot), I could detect that the server is up by polling http or ssh. However, I was hoping for something with a few less moving parts. Jul 6, 2011 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.