Skip to content

Commit

Permalink
Merge pull request #28 from gangaram-tii/pr__system_suspend
Browse files Browse the repository at this point in the history
system suspend command
  • Loading branch information
mbssrc authored Nov 8, 2024
2 parents aacb694 + b6afee3 commit f48fa34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 52 deletions.
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

0 comments on commit f48fa34

Please sign in to comment.