Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix restart crashed applications #15

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ pub struct UnitStatus {

impl UnitStatus {
pub fn is_running(&self) -> bool {
self.active_state == "active"
self.active_state == "active" && self.load_state == "loaded" && self.sub_state == "running"
}
pub fn is_exitted(&self) -> bool {
self.active_state == "inactive"
&& self.load_state == "not-found"
&& self.sub_state == "dead"
}
}

Expand Down
26 changes: 21 additions & 5 deletions nixos/tests/admin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ in
admin = adminSettings;
tls = mkTls "chromium-vm";
applications = lib.mkForce (
builtins.toJSON { "foot" = "/run/current-system/sw/bin/run-waypipe ${pkgs.foot}/bin/foot"; }
builtins.toJSON {
"foot" = "/run/current-system/sw/bin/run-waypipe ${pkgs.foot}/bin/foot";
"clearexit" = "/run/current-system/sw/bin/sleep 5";
}
);
};
};
Expand Down Expand Up @@ -288,10 +291,23 @@ in
swaymsg("exec ssh -R /tmp/vsock:/tmp/vsock -f -N ${addrs.appvm}")
time.sleep(5) # Give ssh some time to setup remote socket

#swaymsg("exec run-waypipe foot")
print(hostvm.succeed("${cli} --addr ${nodes.adminvm.config.givc.admin.addr} --port ${nodes.adminvm.config.givc.admin.port} --cacert ${nodes.hostvm.givc.host.tls.caCertPath} --cert ${nodes.hostvm.givc.host.tls.certPath} --key ${nodes.hostvm.givc.host.tls.keyPath} ${if tls then "" else "--notls"} --name ${nodes.adminvm.config.givc.admin.name} start foot"))
time.sleep(10) # Give few seconds to application to spin up
wait_for_window("ghaf@appvm")
with subtest("Clean run"):
print(hostvm.succeed("${cli} --addr ${nodes.adminvm.config.givc.admin.addr} --port ${nodes.adminvm.config.givc.admin.port} --cacert ${nodes.hostvm.givc.host.tls.caCertPath} --cert ${nodes.hostvm.givc.host.tls.certPath} --key ${nodes.hostvm.givc.host.tls.keyPath} ${if tls then "" else "--notls"} --name ${nodes.adminvm.config.givc.admin.name} start foot"))
time.sleep(10) # Give few seconds to application to spin up
wait_for_window("ghaf@appvm")

with subtest("crash and restart"):
# Crash application
appvm.succeed("pkill foot")
time.sleep(10)
# .. then ask to restart
print(hostvm.succeed("${cli} --addr ${nodes.adminvm.config.givc.admin.addr} --port ${nodes.adminvm.config.givc.admin.port} --cacert ${nodes.hostvm.givc.host.tls.caCertPath} --cert ${nodes.hostvm.givc.host.tls.certPath} --key ${nodes.hostvm.givc.host.tls.keyPath} ${if tls then "" else "--notls"} --name ${nodes.adminvm.config.givc.admin.name} start foot"))
wait_for_window("ghaf@appvm")

with subtest("clear exit and restart"):
print(hostvm.succeed("${cli} --addr ${nodes.adminvm.config.givc.admin.addr} --port ${nodes.adminvm.config.givc.admin.port} --cacert ${nodes.hostvm.givc.host.tls.caCertPath} --cert ${nodes.hostvm.givc.host.tls.certPath} --key ${nodes.hostvm.givc.host.tls.keyPath} ${if tls then "" else "--notls"} --name ${nodes.adminvm.config.givc.admin.name} start --vm foot-vm clearexit"))
time.sleep(20) # Give few seconds to application to spin up, exit, then start it again
print(hostvm.succeed("${cli} --addr ${nodes.adminvm.config.givc.admin.addr} --port ${nodes.adminvm.config.givc.admin.port} --cacert ${nodes.hostvm.givc.host.tls.caCertPath} --cert ${nodes.hostvm.givc.host.tls.certPath} --key ${nodes.hostvm.givc.host.tls.keyPath} ${if tls then "" else "--notls"} --name ${nodes.adminvm.config.givc.admin.name} start --vm foot-vm clearexit"))
'';
};
};
Expand Down
10 changes: 4 additions & 6 deletions src/admin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ impl AdminServiceImpl {
pub async fn handle_error(&self, entry: RegistryEntry) -> anyhow::Result<()> {
match (entry.r#type.vm, entry.r#type.service) {
(VmType::AppVM, ServiceType::App) => {
self.registry.deregister(&entry.name)?;
if entry.status.is_exitted() {
self.registry.deregister(&entry.name)?;
}
Ok(())
}
(VmType::AppVM, ServiceType::Mgr) | (VmType::SysVM, ServiceType::Mgr) => {
Expand All @@ -184,11 +186,7 @@ impl AdminServiceImpl {
debug!("Monitoring {}...", &entry.name);
match self.get_remote_status(&entry).await {
Err(err) => {
error!(
"could not get status of unit {}: {}",
entry.name.clone(),
err
);
error!("could not get status of unit {}: {}", &entry.name, err);
self.handle_error(entry)
.await
.with_context(|| "during handle error")?
Expand Down