fix(shutdown): Fix shutdown command
This commit is contained in:
@@ -4,15 +4,33 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
|
||||
"git.secnex.io/secnex/masterlog"
|
||||
)
|
||||
|
||||
// Shutdown shuts down the system (Unix/Linux/macOS)
|
||||
func Shutdown() {
|
||||
// Try shutdown command first
|
||||
cmd := exec.Command("shutdown", "-h", "now")
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Fatalf("Failed to shutdown system: %v", err)
|
||||
masterlog.Error("Failed to shutdown system (trying with sudo)", map[string]interface{}{
|
||||
"error": err,
|
||||
})
|
||||
|
||||
// Try with sudo if the first attempt failed
|
||||
cmd = exec.Command("sudo", "shutdown", "-h", "now")
|
||||
if err := cmd.Run(); err != nil {
|
||||
masterlog.Error("Failed to shutdown system even with sudo", map[string]interface{}{
|
||||
"error": err,
|
||||
"note": "The application may need to be run with sudo privileges",
|
||||
})
|
||||
// Don't use log.Fatalf here, just log the error
|
||||
// The system might still shutdown or the user can manually shutdown
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
masterlog.Info("Shutdown command executed successfully")
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
|
||||
"git.secnex.io/secnex/masterlog"
|
||||
)
|
||||
|
||||
// Shutdown shuts down the system (Windows)
|
||||
@@ -13,6 +14,12 @@ func Shutdown() {
|
||||
cmd := exec.Command("shutdown", "/s", "/t", "0")
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Fatalf("Failed to shutdown system: %v", err)
|
||||
masterlog.Error("Failed to shutdown system", map[string]interface{}{
|
||||
"error": err,
|
||||
"note": "The application may need administrator privileges",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
masterlog.Info("Shutdown command executed successfully")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user