User Tools

Site Tools


unix:virtualization:virtlib:winvirtuals

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
unix:virtualization:virtlib:winvirtuals [2023/05/04 21:53] rodolicounix:virtualization:virtlib:winvirtuals [2023/05/04 22:23] (current) rodolico
Line 33: Line 33:
  
 Now, running <code bash>virsh shutdown domname</code> should properly shut down the domain. Now, running <code bash>virsh shutdown domname</code> should properly shut down the domain.
 +
 +===== virtual will not reboot =====
 +
 +I have found that some (not all) Windows virtuals will not restart/reboot, either from within the running virtual, or from the virsh command line. Instead, they shut down.
 +
 +Since this causes many issues, we wrote a Perl script as a work around. The script simply checks to see if virtuals are up and, if not, starts them (with the virsh start command). In our case, we decided that this would occur either when doing maintenance on the machine, or overnight when the virtual decides to reboot itself, so a 10 minute, maximum, downtime was acceptable.
 +
 +<code perl checkVirtuals>
 +#! /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;
 +</code>
 +
 +Every time this script is run, it will check each of the virtuals it is monitoring to see if it is up. The first time it finds one that is not up, it will create a flag file in /tmp, named //**virtualname**.down//.
 +
 +When it finds it is down the second time, it will start it back up.
 +
 +The following cron file, stored in /etc/cron.d (Devuan/Debian) will run the script every 5 minutes. The minimum down time will be 5 minutes, 1 second, and the maximum downtime will be 10 minutes.
 +
 +<code crontab checkVirtuals.cron>
 +# Check status of virtuals on this machine and, restart any if down.
 +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 +# following may be changed to send failure reports to a different e-mail
 +# account
 +MAILTO=root
 + 
 +# check running virtuals every 5 minutes
 +
 +# m  h dom mon dow   user    command
 +*/5 *  *        root    perl /opt/scripts/virtuals/checkVirtuals
 + 
 +# EOF
 +</code>
 +
 +Save this file to /etc/cron.d/checkVirtuals (no .cron after it). Edit the */5 to determine how many minutes to do the check, and edit the command to point to wherever you put the checkVirtuals Perl script.
  
 ===== Links ===== ===== Links =====
   * https://access.redhat.com/solutions/732773   * https://access.redhat.com/solutions/732773
   * https://github.com/virt-manager/virt-manager/issues/271   * https://github.com/virt-manager/virt-manager/issues/271
unix/virtualization/virtlib/winvirtuals.1683255218.txt.gz · Last modified: 2023/05/04 21:53 by rodolico