feat(daemon): enhance service management with start, stop, restart, and status commands for Windows
This commit is contained in:
parent
debf77005f
commit
37fcb9fad9
5 changed files with 479 additions and 17 deletions
|
|
@ -3,11 +3,13 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/torrentclaw/unarr/internal/agent"
|
||||
"github.com/torrentclaw/unarr/internal/config"
|
||||
)
|
||||
|
|
@ -38,3 +40,37 @@ func startReloadWatcher(rc *ReloadableConfig) {
|
|||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// sendReloadSignal sends SIGUSR1 to the running daemon process.
|
||||
func sendReloadSignal() error {
|
||||
state := agent.ReadState()
|
||||
if state == nil {
|
||||
return fmt.Errorf("daemon does not appear to be running (state file not found)")
|
||||
}
|
||||
p, err := os.FindProcess(state.PID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("find process %d: %w", state.PID, err)
|
||||
}
|
||||
if err := p.Signal(syscall.SIGUSR1); err != nil {
|
||||
return fmt.Errorf("send reload signal to PID %d: %w", state.PID, err)
|
||||
}
|
||||
fmt.Println()
|
||||
color.New(color.FgGreen).Printf(" ✓ Reload signal sent to daemon (PID %d)\n", state.PID)
|
||||
fmt.Println(" Config will be re-read shortly.")
|
||||
fmt.Println()
|
||||
return nil
|
||||
}
|
||||
|
||||
// killPID sends SIGTERM to the given PID for a graceful shutdown.
|
||||
func killPID(pid int) error {
|
||||
p, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("find process %d: %w", pid, err)
|
||||
}
|
||||
if err := p.Signal(syscall.SIGTERM); err != nil {
|
||||
return fmt.Errorf("stop daemon (PID %d): %w", pid, err)
|
||||
}
|
||||
color.New(color.FgGreen).Printf(" ✓ Stop signal sent to daemon (PID %d)\n", pid)
|
||||
fmt.Println()
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue