Correction Windows

This commit is contained in:
nathaninline authored and GitHub committed 2026-06-09 09:35:07 +02:00
1 parent a40c50c400
commit ca0a315260
14 files changed
+973 -87

No files matched your search

+9 -56
View File
@@ -6,68 +6,19 @@ import (
"os/exec"
"strconv"
"strings"
"time"
)
// serviceAction wraps `systemctl <action> <svc>` with passwordless sudo where
// it makes sense, and prints a follow-up status check after start/restart.
func serviceAction(action string) error {
svc := serviceName()
needsRoot := action == "start" || action == "stop" || action == "restart" || action == "enable" || action == "disable"
args := []string{}
bin := "systemctl"
if needsRoot && os.Geteuid() != 0 {
bin = "sudo"
args = append(args, "-n", "systemctl")
}
args = append(args, action, svc)
cmd := exec.Command(bin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
switch action {
case "start", "restart":
return checkStarted(svc)
case "stop":
fmt.Println(green("[ok]") + " arrêté")
case "enable":
fmt.Println(green("[ok]") + " démarrage auto activé")
case "disable":
fmt.Println(green("[ok]") + " démarrage auto désactivé")
}
return nil
}
func checkStarted(svc string) error {
time.Sleep(2 * time.Second)
out, _ := exec.Command("systemctl", "is-active", svc).Output()
state := strings.TrimSpace(string(out))
if state == "active" || state == "activating" {
fmt.Printf("%s %s: %s\n", green("[ok]"), svc, state)
return nil
}
fmt.Printf("%s %s: %s — derniers logs :\n", red("[ERREUR]"), svc, state)
fmt.Println("------------------------------------------------")
logs, _ := exec.Command("journalctl", "-u", svc, "-n", "20", "--no-pager").Output()
fmt.Print(string(logs))
fmt.Println("------------------------------------------------")
fmt.Printf("→ jean logs pour plus de détails\n→ jean edit pour corriger config.env\n")
return fmt.Errorf("service %s non démarré", svc)
}
func serviceLogs() error {
cmd := exec.Command("journalctl", "-u", serviceName(), "-n", "80", "-f")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// service.go holds the platform-neutral pieces of service management. The
// actual start/stop/restart/status/logs implementation is platform-specific:
// - service_unix.go → systemd (systemctl/journalctl)
// - service_windows.go → PID-file background process supervisor
//
// editConfig and showVram live here because they work the same everywhere.
func editConfig() error {
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "nano"
editor = defaultEditor()
}
cmd := exec.Command(editor, confPath())
cmd.Stdin = os.Stdin
@@ -81,6 +32,8 @@ func editConfig() error {
}
// showVram parses `nvidia-smi --query-gpu=...` and renders a colored bar.
// nvidia-smi is available on both Linux and Windows when an NVIDIA driver is
// installed, so this is platform-neutral.
func showVram() error {
out, err := exec.Command("nvidia-smi",
"--query-gpu=name,memory.used,memory.total,utilization.gpu,temperature.gpu",