Add system shutdown subcommand

This commit is contained in:
2022-05-13 23:43:35 +02:00
parent 7b1565e6a4
commit 2d078228c9
5 changed files with 299 additions and 84 deletions

View File

@@ -23,3 +23,17 @@ func (s *Server) SystemReboot(ctx context.Context, system *portal.SystemRebootRe
return &portal.SystemRebootResponse{State: portal.State_CHANGED, Message: "Rebooting"}, nil
}
func (s *Server) SystemShutdown(ctx context.Context, system *portal.SystemShutdownRequest) (*portal.SystemShutdownResponse, error) {
fields := log.Fields{
"context": "system",
"command": "shutdown",
}
log := log.WithFields(fields)
log.Debug("Received system shutdown request")
syscall.Sync()
go syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF)
return &portal.SystemShutdownResponse{State: portal.State_CHANGED, Message: "Shutting down"}, nil
}