I'm currently building an infrastructure management tool that provisions bare metal and VM's etc. We have a worker VM that runs commands(via ansible) on the remote nodes over SSH.
One of the steps requires the rebooting of nodes to apply some configurations. The worker process has to run more commands on the nodes after the reboot is complete(must be done synchronously).
My question is, how can I check to see whether the reboot has completed?
I could add a sleep timer(to wait until the reboot completes), but I feel like that is a bad solution for a number of reasons.
Another option is to try to SSH to the remote node, from my worker process, every 5 seconds or so, if it fails, keep trying again until I get a successful connection.
Is there another way of doing this?
As you mentioned that you are running commands via ansible, here is what I use for reboots in a playbook (I'm managing Ubuntu 14/16.04 machines):
Update
Ansible 2.7 now has a reboot module, so you don't need to create commands on your own. The playbook from above would translate into this:
If you want to check status of hosts, time when they was rebooted and many many other parameters then you should use monitoring software like Zabbix, Nagios and etc.
Reboot time may be checked by
uptime
system parameter. It shows time since last boot. You can get it by commanduptime
on Linux/UNIX host or by SNMP protocol remotely when snmpd service is running on the host: