mirror of
https://github.com/R0m1k3/Loki.git
synced 2026-10-17 04:10:04 +02:00
Socle du renommage jean -> AJEAN, sans aucun impact visible pour le parc installe. Trois briques : - module github.com/nathaninline/ajean, cmd/ajean, internal/ajean, package ajean. Purement interne. - AjeanHome() remplace JeanHome(). Les defauts deviennent %ProgramData%\ajean et /etc/ajean, avec migration du dossier existant au premier lancement. La migration est un os.Rename dans le dossier parent de l'ancien chemin : intra-volume, donc atomique et instantane meme avec des .gguf de plusieurs dizaines de Go. Si le rename echoue (handle ouvert sous Windows, droits, volume en lecture seule) on CONTINUE sur l'ancien chemin et on retentera : jamais de copie, jamais de suppression, le pire cas est "rien n'a bouge". $AJEAN_HOME et $JEAN_HOME restent tous deux honores, ainsi que /etc/default/ajean et /etc/default/jean : un chemin impose a la main est un ordre, on ne le migre pas. - l'auto-MAJ accepte desormais ajean-<os>-<arch> ET jean-<os>-<arch>, dans cet ordre. Indispensable dans les deux sens : les binaires deja installes ne connaissent que jean-*, et ce binaire-ci doit pouvoir s'installer depuis une release anterieure au renommage. Couvert par des tests, dont le repli quand un handle ouvert bloque le rename sous Windows.
84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
//go:build linux
|
|
|
|
package ajean
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"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()
|
|
}
|
|
|
|
// serviceIsActive reports whether the systemd unit is currently running.
|
|
func serviceIsActive() bool {
|
|
out, _ := exec.Command("systemctl", "is-active", serviceName()).Output()
|
|
return strings.TrimSpace(string(out)) == "active"
|
|
}
|
|
|
|
// serviceLogTail renvoie les n dernières lignes du journal du service (pour
|
|
// l'UI web). Linux : journalctl.
|
|
func serviceLogTail(n int) string {
|
|
out, err := exec.Command("journalctl", "-u", serviceName(), "-n", strconv.Itoa(n), "--no-pager").CombinedOutput()
|
|
if err != nil && len(out) == 0 {
|
|
return "journalctl indisponible : " + err.Error()
|
|
}
|
|
return string(out)
|
|
}
|