#! /usr/bin/env perl use strict; use warnings; # list of virtuals which should be turned on if they # are found to be down. This is the same as that returned # by virsh list my @servers = ( 'win1', 'win2', 'win3' ); # command to start a virtual my $virsh = '/usr/bin/virsh start '; # get a list of running virtuals and put them into # $output my $output = `virsh list`; # check each virtual we are monitoring foreach my $server ( @servers ) { if ( $output =~ m/$server/ ) { # the virtual is running # remove the flag file unlink "/tmp/$server.down" if -e "/tmp/$server.down"; } else { # virtual is not running if ( -e "/tmp/$server.down" ) { # it was down on the previous pass print "$server has been down for a while, starting back up\n"; # so bring it back up `$virsh $server`; # and remove the flag file unlink "/tmp/$server.down"; } else { # just went down # create a flag file so the next pass will start it back up `touch /tmp/$server.down`; } } } 1;