mirror of
https://github.com/R0m1k3/Loki.git
synced 2026-10-11 17:26:57 +02:00
- module github.com/R0m1k3/Loki, cmd/loki, internal/loki (package loki) - LOKI_HOME, LOKI_MODEL_DIRS, LOKI_SERVICE, LOKI_DL_CONNS ; /etc/loki ; units loki-engine / loki-ui ; binaire et aide CLI - updateRepo pointe sur R0m1k3/Loki (l'auto-update ne tirera plus les binaires AJEAN amont) Conservé à l'identique : le domaine ajean.link (service de tunnel amont), les littéraux de migration 0.7.x (migrate_07.go), RELEASE_NOTES.md et LICENSE (historique et licence de l'amont). go build/vet/test : verts.
77 lines
2.6 KiB
Go
77 lines
2.6 KiB
Go
//go:build darwin
|
|
|
|
package loki
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
)
|
|
|
|
// sys_install_darwin.go — la part launchd de l'installation. Le parcours commun
|
|
// (dossiers, lien du binaire, /etc/default, chown) vit dans sys_install_unix.go.
|
|
//
|
|
// ⚠️ NON TESTÉ sur un vrai Mac. Le support macOS a été ajouté parce que le code
|
|
// systemd tournait par erreur et échouait sur « systemctl: command not found ».
|
|
// Implémentation prudente, à valider sur une machine Apple.
|
|
|
|
// launchdPlistTemplate — champs : Label, binaire, argument, UserName,
|
|
// WorkingDirectory, LOKI_HOME, StandardOutPath, StandardErrorPath.
|
|
// KeepAlive/SuccessfulExit=false ≈ Restart=on-failure ; RunAtLoad relance au
|
|
// boot une fois chargé avec `-w`.
|
|
const launchdPlistTemplate = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key><string>%s</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>%s</string>
|
|
<string>%s</string>
|
|
</array>
|
|
<key>UserName</key><string>%s</string>
|
|
<key>WorkingDirectory</key><string>%s</string>
|
|
<key>EnvironmentVariables</key>
|
|
<dict><key>LOKI_HOME</key><string>%s</string></dict>
|
|
<key>RunAtLoad</key><true/>
|
|
<key>KeepAlive</key>
|
|
<dict><key>SuccessfulExit</key><false/></dict>
|
|
<key>StandardOutPath</key><string>%s</string>
|
|
<key>StandardErrorPath</key><string>%s</string>
|
|
</dict>
|
|
</plist>
|
|
`
|
|
|
|
// unitArgs associe chaque service à la sous-commande qu'il exécute.
|
|
func unitArgs() map[string]string {
|
|
return map[string]string{serviceName(): "serve", uiUnitName: "web"}
|
|
}
|
|
|
|
func installServices(targetUser, lokiHome string) error {
|
|
exe := installedExePath()
|
|
for name, arg := range unitArgs() {
|
|
logPath := filepath.Join(lokiHome, name+".log")
|
|
plist := fmt.Sprintf(launchdPlistTemplate,
|
|
launchdLabel(name), exe, arg, targetUser, lokiHome, lokiHome, logPath, logPath)
|
|
path := launchdPlistPath(name)
|
|
if err := os.WriteFile(path, []byte(plist), 0o644); err != nil {
|
|
return err
|
|
}
|
|
fmt.Printf(" %s %s\n", green("✓"), path)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// uninstallServices décharge et efface les deux daemons. L'interface passe
|
|
// AVANT le moteur : elle sait le redémarrer, l'ordre inverse pourrait le
|
|
// relancer sous nos pieds.
|
|
func uninstallServices() {
|
|
for _, name := range []string{uiUnitName, serviceName()} {
|
|
_ = exec.Command("launchctl", "unload", "-w", launchdPlistPath(name)).Run()
|
|
if err := os.Remove(launchdPlistPath(name)); err == nil {
|
|
fmt.Printf(" %s %s\n", green("✓"), launchdPlistPath(name))
|
|
}
|
|
}
|
|
}
|