Because we now support startup priorities, and start/stop order must include containers
});
}
-sub vm_stopall {
- my ($storecfg, $timeout) = @_;
-
- $timeout = 3*60 if !$timeout;
-
- my $cleanuphash = {};
-
- my $vzlist = vzlist();
- my $count = 0;
- foreach my $vmid (keys %$vzlist) {
- next if !$vzlist->{$vmid}->{pid};
- $count++;
- $cleanuphash->{$vmid} = 1;
- }
-
- return if !$count;
-
- my $msg = "Stopping Qemu Server - sending shutdown requests to all VMs\n";
- syslog('info', $msg);
- warn $msg;
-
- foreach my $vmid (keys %$vzlist) {
- next if !$vzlist->{$vmid}->{pid};
- eval { vm_monitor_command($vmid, "system_powerdown"); };
- warn $@ if $@;
- }
-
- my $wt = 5;
- my $maxtries = int(($timeout + $wt -1)/$wt);
- my $try = 0;
- while (($try < $maxtries) && $count) {
- $try++;
- sleep $wt;
-
- $vzlist = vzlist();
- $count = 0;
- foreach my $vmid (keys %$vzlist) {
- next if !$vzlist->{$vmid}->{pid};
- $count++;
- }
- last if !$count;
- }
-
- if ($count) {
-
- foreach my $vmid (keys %$vzlist) {
- next if !$vzlist->{$vmid}->{pid};
-
- warn "VM $vmid still running - sending stop now\n";
- eval { vm_monitor_command($vmid, "quit"); };
- warn $@ if $@;
- }
-
- $timeout = 30;
- $maxtries = int(($timeout + $wt -1)/$wt);
- $try = 0;
- while (($try < $maxtries) && $count) {
- $try++;
- sleep $wt;
-
- $vzlist = vzlist();
- $count = 0;
- foreach my $vmid (keys %$vzlist) {
- next if !$vzlist->{$vmid}->{pid};
- $count++;
- }
- last if !$count;
- }
-
- if ($count) {
-
- foreach my $vmid (keys %$vzlist) {
- next if !$vzlist->{$vmid}->{pid};
-
- warn "VM $vmid still running - terminating now with SIGTERM\n";
- kill 15, $vzlist->{$vmid}->{pid};
- }
- sleep 1;
- }
-
- # this is called by system shotdown scripts, so remaining
- # processes gets killed anyways (no need to send kill -9 here)
- }
-
- $vzlist = vzlist();
- foreach my $vmid (keys %$cleanuphash) {
- next if $vzlist->{$vmid}->{pid};
- eval {
- my $conf = load_config($vmid);
- vm_stop_cleanup($storecfg, $vmid, $conf);
- };
- warn $@ if $@;
- }
-
- $msg = "Qemu Server stopped\n";
- syslog('info', $msg);
- print $msg;
-}
-
# pci helpers
sub file_write {
qemu-server (2.0-39) unstable; urgency=low
* new startup option to define startup order.
+
+ * do not start VMs with /etc/init.d/qemu-server. This is now
+ done with /etc/init.d/pve-manager
+
+ * qm: removed startall/stopall commands
-- Proxmox Support Team <support@proxmox.com> Thu, 19 Apr 2012 14:26:04 +0200
mkdir -p /var/run/qemu-server
mkdir -p /var/lock/qemu-server
- $PROG startall
;;
stop)
- $PROG stopall
+ # nothing to do, because we are no real daemon
;;
force-reload)
;;
return undef;
}});
-__PACKAGE__->register_method ({
- name => 'startall',
- path => 'startall',
- method => 'POST',
- description => "Start all virtual machines (when onboot=1).",
- parameters => {
- additionalProperties => 0,
- properties => {},
- },
- returns => { type => 'null'},
- code => sub {
- my ($param) = @_;
-
- # wait up to 10 seconds for quorum
- for (my $i = 10; $i >= 0; $i--) {
- last if PVE::Cluster::check_cfs_quorum($i != 0 ? 1 : 0);
- sleep(1);
- }
-
- my $vzlist = PVE::QemuServer::vzlist();
- my $storecfg = PVE::Storage::config();
-
- my $cc = PVE::Cluster::cfs_read_file('cluster.conf');
-
- my $count = 0;
- foreach my $vmid (keys %$vzlist) {
- next if $vzlist->{$vmid}->{pid}; # already running
-
- my $conf;
- eval { $conf = PVE::QemuServer::load_config($vmid); };
- if (my $err = $@) {
- warn $err;
- next;
- }
-
- next if !($conf && $conf->{onboot});
-
- # skip ha managed VMs (started by rgmanager)
- next if PVE::Cluster::cluster_conf_lookup_pvevm($cc, 0, $vmid, 1);
-
- sleep(2) if $count != 0; # reduce load
- $count++;
-
- PVE::Cluster::check_cfs_quorum(); # abort when we loose quorum
-
- eval {
- print STDERR "Starting Qemu VM $vmid\n";
- PVE::QemuServer::vm_start($storecfg, $vmid);
- };
- warn $@ if $@;
- }
-
- return undef;
- }});
-
-__PACKAGE__->register_method ({
- name => 'stopall',
- path => 'stopall',
- method => 'POST',
- description => "Stop all virtual machines.",
- parameters => {
- additionalProperties => 0,
- properties => {
- timeout => {
- description => "Timeout in seconds. Default is to wait 3 minutes.",
- type => 'integer',
- minimum => 1,
- optional => 1,
- }
- },
- },
- returns => { type => 'null'},
- code => sub {
- my ($param) = @_;
-
- my $timeout = $param->{timeout};
-
- my $storecfg = PVE::Storage::config();
-
- PVE::QemuServer::vm_stopall($storecfg, $timeout);
-
- return undef;
- }});
-
__PACKAGE__->register_method ({
name => 'wait',
path => 'wait',
monitor => [ __PACKAGE__, 'monitor', ['vmid']],
- startall => [ __PACKAGE__, 'startall', []],
-
- stopall => [ __PACKAGE__, 'stopall', []],
-
mtunnel => [ __PACKAGE__, 'mtunnel', []],
};