fix: pass relay-url and relay-token to auto-restart services

The server reads relay config from CLI flags, not config.json.
Auto-restart services (systemd on Linux, launchd on macOS, Registry
Run key on Windows) were launching the server without relay args,
so the tunnel never connected.

Now all three platforms pass --relay-url and --relay-token to the
server binary in their auto-restart configuration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jim800121chen 2026-03-25 15:24:14 +08:00
parent 3c3bc6cbec
commit b7e6da4c05
4 changed files with 48 additions and 8 deletions

View File

@ -347,7 +347,7 @@ func (inst *Installer) stepAutoRestart(config InstallConfig) error {
Message: "Registering auto-restart service...",
Percent: 96,
})
return installAutoRestart(config.InstallDir)
return installAutoRestart(config)
}
// extractFile copies a single file from the embedded payload to disk.

View File

@ -107,7 +107,8 @@ func removeQuarantine(installDir string) {
exec.Command("xattr", "-dr", "com.apple.quarantine", binPath).Run()
}
func installAutoRestart(installDir string) error {
func installAutoRestart(config InstallConfig) error {
installDir := config.InstallDir
home, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("cannot determine home directory: %w", err)
@ -122,6 +123,24 @@ func installAutoRestart(installDir string) error {
binPath := filepath.Join(installDir, "edge-ai-server")
// Build ProgramArguments with relay args if configured
progArgs := []string{
` <string>` + binPath + `</string>`,
` <string>--tray</string>`,
}
if config.RelayURL != "" {
progArgs = append(progArgs,
` <string>--relay-url</string>`,
` <string>`+config.RelayURL+`</string>`,
)
}
if config.RelayToken != "" {
progArgs = append(progArgs,
` <string>--relay-token</string>`,
` <string>`+config.RelayToken+`</string>`,
)
}
plist := strings.Join([]string{
`<?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">`,
@ -131,8 +150,7 @@ func installAutoRestart(installDir string) error {
` <string>` + launchdLabel + `</string>`,
` <key>ProgramArguments</key>`,
` <array>`,
` <string>` + binPath + `</string>`,
` <string>--tray</string>`,
strings.Join(progArgs, "\n"),
` </array>`,
` <key>EnvironmentVariables</key>`,
` <dict>`,

View File

@ -63,7 +63,8 @@ func removeQuarantine(installDir string) {
// No-op on Linux
}
func installAutoRestart(installDir string) error {
func installAutoRestart(config InstallConfig) error {
installDir := config.InstallDir
home, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("cannot determine home directory: %w", err)
@ -78,6 +79,15 @@ func installAutoRestart(installDir string) error {
binPath := filepath.Join(installDir, "edge-ai-server")
// Build ExecStart with relay args if configured
execStart := binPath
if config.RelayURL != "" {
execStart += " --relay-url " + config.RelayURL
}
if config.RelayToken != "" {
execStart += " --relay-token " + config.RelayToken
}
service := strings.Join([]string{
"[Unit]",
"Description=Edge AI Platform Server",
@ -85,7 +95,7 @@ func installAutoRestart(installDir string) error {
"",
"[Service]",
"Type=simple",
"ExecStart=" + binPath,
"ExecStart=" + execStart,
"WorkingDirectory=" + installDir,
"Restart=on-failure",
"RestartSec=5",

View File

@ -205,9 +205,21 @@ func removeQuarantine(installDir string) {
// No-op on Windows
}
func installAutoRestart(installDir string) error {
func installAutoRestart(config InstallConfig) error {
installDir := config.InstallDir
binPath := filepath.Join(installDir, "edge-ai-server.exe")
// Build command with relay args if configured
regValue := fmt.Sprintf(`"%s" --gui`, binPath)
startArgs := []string{"--gui"}
if config.RelayURL != "" {
regValue += fmt.Sprintf(` --relay-url "%s"`, config.RelayURL)
startArgs = append(startArgs, "--relay-url", config.RelayURL)
}
if config.RelayToken != "" {
regValue += fmt.Sprintf(` --relay-token "%s"`, config.RelayToken)
startArgs = append(startArgs, "--relay-token", config.RelayToken)
}
// Use Registry Run key for auto-start (no admin required, works on all Windows locales)
cmd := exec.Command("reg", "add",
@ -225,7 +237,7 @@ func installAutoRestart(installDir string) error {
exec.Command("schtasks", "/Delete", "/TN", "EdgeAIPlatformServer", "/F").Run()
// Start the server immediately
startCmd := exec.Command(binPath, "--gui")
startCmd := exec.Command(binPath, startArgs...)
startCmd.Dir = installDir
startCmd.Start()