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 --> qemuPowerdown: Stop
* Running --> which2: ProcessExited[process qemu]
*
* terminated --> [*] * terminated --> [*]
* *
* @enduml * @enduml
@ -356,7 +358,7 @@ public class Runner extends Component {
} }
private boolean startProcess(CommandDefinition toStart) { private boolean startProcess(CommandDefinition toStart) {
logger.fine( logger.info(
() -> "Starting process: " + String.join(" ", toStart.command)); () -> "Starting process: " + String.join(" ", toStart.command));
fire(new StartProcess(toStart.command) fire(new StartProcess(toStart.command)
.setAssociated(CommandDefinition.class, toStart)); .setAssociated(CommandDefinition.class, toStart));
@ -446,7 +448,14 @@ public class Runner extends Component {
*/ */
@Handler @Handler
public void onProcessExited(ProcessExited event, ProcessChannel channel) { 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; private State state = State.INITIALIZING;
/**
* Instantiates a new state controller.
*
* @param runner the runner
*/
public StateController(Runner runner) { public StateController(Runner runner) {
this.runner = runner; this.runner = runner;
} }
@ -47,6 +52,15 @@ package org.jdrupes.vmoperator.runner.qemu;
this.state = state; this.state = state;
} }
/**
* Returns the state.
*
* @return the state
*/
public State get() {
return state;
}
@Override @Override
public String toString() { public String toString() {
return "StateController [state=" + state + "]"; return "StateController [state=" + state + "]";