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

system suspend command #28

Merged
merged 1 commit into from
Nov 8, 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
43 changes: 0 additions & 43 deletions nixos/tests/admin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ in
addr = addrs.adminvm;
port = "9001";
tls = mkTls "admin-vm";
services = [
"display-suspend.service"
"display-resume.service"
];
};
};
hostvm = {
Expand Down Expand Up @@ -98,12 +94,6 @@ in
snakeOilPrivateKey
snakeOilPublicKey
;
NotifyDisplaySuspend = pkgs.writeShellScript "NotifyDisplaySuspend" ''
echo 'Service notification: Dummy display suspend service started successfully.'
'';
NotifyDisplayResume = pkgs.writeShellScript "NotifyDisplayResume" ''
echo 'Service notification: Dummy display resume service started successfully.'
'';
in
{
imports = [ self.nixosModules.sysvm ];
Expand All @@ -118,26 +108,6 @@ in
};
};

systemd.services.display-suspend = {
enable = true;
description = "Dummy display suspend service";
serviceConfig = {
Type = "oneshot";
ExecStart = "${NotifyDisplaySuspend}";
RemainAfterExit = true;
};
};

systemd.services.display-resume = {
enable = true;
description = "Dummy display resume service";
serviceConfig = {
Type = "oneshot";
ExecStart = "${NotifyDisplayResume}";
RemainAfterExit = true;
};
};

services.getty.autologinUser = "ghaf";
# End of users

Expand Down Expand Up @@ -189,8 +159,6 @@ in
"reboot.target"
"sleep.target"
"suspend.target"
"display-suspend.service"
"display-resume.service"
];
};

Expand Down Expand Up @@ -383,17 +351,6 @@ in
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 chromium-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 chromium-vm clearexit"))

with subtest("suspend system"):
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} suspend"))
time.sleep(10) # Give few seconds to application to spin up
guivm.wait_for_unit("display-suspend.service")

with subtest("wakeup system"):
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} wakeup"))
time.sleep(10) # Give few seconds to application to spin up
guivm.wait_for_unit("display-resume.service")

'';
};
};
Expand Down
14 changes: 5 additions & 9 deletions src/admin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,15 @@ impl pb::admin_service_server::AdminService for AdminService {
})
.await
}

async fn suspend(
&self,
request: tonic::Request<Empty>,
) -> std::result::Result<tonic::Response<Empty>, tonic::Status> {
escalate(request, |_| async {
self.inner
.start_unit_on_vm("gui", "display-suspend.service")
.await?;
.send_system_command(String::from("suspend.target"))
.await;
Ok(Empty {})
})
.await
Expand All @@ -490,13 +491,8 @@ impl pb::admin_service_server::AdminService for AdminService {
&self,
request: tonic::Request<Empty>,
) -> std::result::Result<tonic::Response<Empty>, tonic::Status> {
escalate(request, |_| async {
self.inner
.start_unit_on_vm("gui", "display-resume.service")
.await?;
Ok(Empty {})
})
.await
println!("Not supported");
Err(Status::unimplemented("Not supported"))
}

async fn query_list(
Expand Down