Support stop by guest shutdown.

This commit is contained in:
Michael Lipp 2023-06-05 15:16:32 +02:00
parent d99703510b
commit c166e35de0
2 changed files with 25 additions and 2 deletions

View file

@ -132,6 +132,8 @@ import org.jgrapes.util.events.WatchFile;
* }
*
* Running --> qemuPowerdown: Stop
* Running --> which2: ProcessExited[process qemu]
*
* terminated --> [*]
*
* @enduml
@ -356,7 +358,7 @@ public class Runner extends Component {
}
private boolean startProcess(CommandDefinition toStart) {
logger.fine(
logger.info(
() -> "Starting process: " + String.join(" ", toStart.command));
fire(new StartProcess(toStart.command)
.setAssociated(CommandDefinition.class, toStart));
@ -446,7 +448,14 @@ public class Runner extends Component {
*/
@Handler
public void onProcessExited(ProcessExited event, ProcessChannel channel) {
int i = 0;
channel.associated(CommandDefinition.class).ifPresent(procDef -> {
if (procDef.equals(qemuDefinition)
&& state.get() == State.RUNNING) {
fire(new Stop());
}
logger.info(() -> "Process " + procDef.name
+ " has exited with value " + event.exitValue());
});
}
/**

View file

@ -34,6 +34,11 @@ package org.jdrupes.vmoperator.runner.qemu;
private State state = State.INITIALIZING;
/**
* Instantiates a new state controller.
*
* @param runner the runner
*/
public StateController(Runner runner) {
this.runner = runner;
}
@ -47,6 +52,15 @@ package org.jdrupes.vmoperator.runner.qemu;
this.state = state;
}
/**
* Returns the state.
*
* @return the state
*/
public State get() {
return state;
}
@Override
public String toString() {
return "StateController [state=" + state + "]";