Merge branch 'fix/runner-poweroff'
This commit is contained in:
commit
72e1b8a580
1 changed files with 30 additions and 24 deletions
|
|
@ -139,8 +139,9 @@ public class QemuMonitor extends QemuConnector {
|
||||||
@SuppressWarnings({ "PMD.AvoidSynchronizedStatement",
|
@SuppressWarnings({ "PMD.AvoidSynchronizedStatement",
|
||||||
"PMD.AvoidDuplicateLiterals" })
|
"PMD.AvoidDuplicateLiterals" })
|
||||||
public void onClosed(Closed<?> event, SocketIOChannel channel) {
|
public void onClosed(Closed<?> event, SocketIOChannel channel) {
|
||||||
logger.finer(() -> "Closing QMP socket.");
|
|
||||||
super.onClosed(event, channel);
|
super.onClosed(event, channel);
|
||||||
|
logger.finer(() -> "QMP socket closed.");
|
||||||
|
monitorReady = false;
|
||||||
channel.associated(this, getClass()).ifPresent(qm -> {
|
channel.associated(this, getClass()).ifPresent(qm -> {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (powerdownTimer != null) {
|
if (powerdownTimer != null) {
|
||||||
|
|
@ -199,28 +200,31 @@ public class QemuMonitor extends QemuConnector {
|
||||||
@Handler(priority = 100)
|
@Handler(priority = 100)
|
||||||
@SuppressWarnings("PMD.AvoidSynchronizedStatement")
|
@SuppressWarnings("PMD.AvoidSynchronizedStatement")
|
||||||
public void onStop(Stop event) {
|
public void onStop(Stop event) {
|
||||||
if (qemuChannel() != null) {
|
if (!monitorReady) {
|
||||||
// We have a connection to Qemu, attempt ACPI shutdown.
|
logger.fine(() -> "No QMP connection,"
|
||||||
event.suspendHandling();
|
+ " cannot send powerdown command");
|
||||||
suspendedStop = event;
|
return;
|
||||||
|
|
||||||
// Attempt powerdown command. If not confirmed, assume
|
|
||||||
// "hanging" qemu process.
|
|
||||||
powerdownTimer = Components.schedule(t -> {
|
|
||||||
// Powerdown not confirmed
|
|
||||||
logger.fine(() -> "QMP powerdown command has not effect.");
|
|
||||||
synchronized (this) {
|
|
||||||
powerdownTimer = null;
|
|
||||||
if (suspendedStop != null) {
|
|
||||||
suspendedStop.resumeHandling();
|
|
||||||
suspendedStop = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, Duration.ofSeconds(1));
|
|
||||||
logger.fine(() -> "Attempting QMP powerdown.");
|
|
||||||
powerdownStartedAt = Instant.now();
|
|
||||||
fire(new MonitorCommand(new QmpPowerdown()));
|
|
||||||
}
|
}
|
||||||
|
// We have a connection to Qemu, attempt ACPI shutdown.
|
||||||
|
event.suspendHandling();
|
||||||
|
suspendedStop = event;
|
||||||
|
|
||||||
|
// Attempt powerdown command. If not confirmed, assume
|
||||||
|
// "hanging" qemu process.
|
||||||
|
powerdownTimer = Components.schedule(t -> {
|
||||||
|
// Powerdown not confirmed
|
||||||
|
logger.fine(() -> "QMP powerdown command not confirmed");
|
||||||
|
synchronized (this) {
|
||||||
|
powerdownTimer = null;
|
||||||
|
if (suspendedStop != null) {
|
||||||
|
suspendedStop.resumeHandling();
|
||||||
|
suspendedStop = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, Duration.ofSeconds(1));
|
||||||
|
logger.fine(() -> "Attempting QMP powerdown.");
|
||||||
|
powerdownStartedAt = Instant.now();
|
||||||
|
fire(new MonitorCommand(new QmpPowerdown()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -238,7 +242,9 @@ public class QemuMonitor extends QemuConnector {
|
||||||
}
|
}
|
||||||
|
|
||||||
// (Re-)schedule timer as fallback
|
// (Re-)schedule timer as fallback
|
||||||
logger.fine(() -> "QMP powerdown confirmed, waiting...");
|
var waitUntil = powerdownStartedAt.plusSeconds(powerdownTimeout);
|
||||||
|
logger.fine(() -> "QMP powerdown confirmed, waiting for"
|
||||||
|
+ " termination until " + waitUntil);
|
||||||
powerdownTimer = Components.schedule(t -> {
|
powerdownTimer = Components.schedule(t -> {
|
||||||
logger.fine(() -> "Powerdown timeout reached.");
|
logger.fine(() -> "Powerdown timeout reached.");
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
@ -247,7 +253,7 @@ public class QemuMonitor extends QemuConnector {
|
||||||
suspendedStop = null;
|
suspendedStop = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, powerdownStartedAt.plusSeconds(powerdownTimeout));
|
}, waitUntil);
|
||||||
powerdownConfirmed = true;
|
powerdownConfirmed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue