docs: improve CLI help, shell completion, and README
- Add command groups (Getting Started, Search, Downloads, Daemon, System)
- Add shell completion command (bash, zsh, fish, powershell)
- Add flag completions for --type, --quality, --sort, --lang, --genre,
--country, --method, --player
- Improve Long descriptions and Examples for all commands
- Split doctor disk check into platform-specific files (Unix/Windows)
- Validate infoHash length before truncating (prevent panic)
- Fix references to non-existent 'unarr daemon start' command
- Move stats command to System & Diagnostics group
- Rewrite README with complete documentation, correct config format
(toml not yaml), all commands, shell completion section
2026-03-28 21:36:27 +01:00
|
|
|
//go:build !windows
|
|
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
2026-04-10 19:18:13 +02:00
|
|
|
"fmt"
|
docs: improve CLI help, shell completion, and README
- Add command groups (Getting Started, Search, Downloads, Daemon, System)
- Add shell completion command (bash, zsh, fish, powershell)
- Add flag completions for --type, --quality, --sort, --lang, --genre,
--country, --method, --player
- Improve Long descriptions and Examples for all commands
- Split doctor disk check into platform-specific files (Unix/Windows)
- Validate infoHash length before truncating (prevent panic)
- Fix references to non-existent 'unarr daemon start' command
- Move stats command to System & Diagnostics group
- Rewrite README with complete documentation, correct config format
(toml not yaml), all commands, shell completion section
2026-03-28 21:36:27 +01:00
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"syscall"
|
|
|
|
|
|
2026-04-10 19:18:13 +02:00
|
|
|
"github.com/fatih/color"
|
2026-03-30 13:06:07 +02:00
|
|
|
"github.com/torrentclaw/unarr/internal/agent"
|
|
|
|
|
"github.com/torrentclaw/unarr/internal/config"
|
docs: improve CLI help, shell completion, and README
- Add command groups (Getting Started, Search, Downloads, Daemon, System)
- Add shell completion command (bash, zsh, fish, powershell)
- Add flag completions for --type, --quality, --sort, --lang, --genre,
--country, --method, --player
- Improve Long descriptions and Examples for all commands
- Split doctor disk check into platform-specific files (Unix/Windows)
- Validate infoHash length before truncating (prevent panic)
- Fix references to non-existent 'unarr daemon start' command
- Move stats command to System & Diagnostics group
- Rewrite README with complete documentation, correct config format
(toml not yaml), all commands, shell completion section
2026-03-28 21:36:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ReloadableConfig holds a reference to the daemon for hot-reload.
|
|
|
|
|
type ReloadableConfig struct {
|
|
|
|
|
Daemon *agent.Daemon
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// startReloadWatcher listens for SIGUSR1 and reloads config.
|
2026-04-08 18:50:59 +02:00
|
|
|
// With the sync-based architecture, intervals are fixed (3s watching, 60s idle).
|
|
|
|
|
// Hot-reload now mainly serves as a signal to re-read config for future settings.
|
docs: improve CLI help, shell completion, and README
- Add command groups (Getting Started, Search, Downloads, Daemon, System)
- Add shell completion command (bash, zsh, fish, powershell)
- Add flag completions for --type, --quality, --sort, --lang, --genre,
--country, --method, --player
- Improve Long descriptions and Examples for all commands
- Split doctor disk check into platform-specific files (Unix/Windows)
- Validate infoHash length before truncating (prevent panic)
- Fix references to non-existent 'unarr daemon start' command
- Move stats command to System & Diagnostics group
- Rewrite README with complete documentation, correct config format
(toml not yaml), all commands, shell completion section
2026-03-28 21:36:27 +01:00
|
|
|
func startReloadWatcher(rc *ReloadableConfig) {
|
|
|
|
|
sigCh := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(sigCh, syscall.SIGUSR1)
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
for range sigCh {
|
|
|
|
|
log.Println("Received SIGUSR1, reloading config...")
|
|
|
|
|
|
2026-04-08 18:50:59 +02:00
|
|
|
_, err := config.Load("")
|
docs: improve CLI help, shell completion, and README
- Add command groups (Getting Started, Search, Downloads, Daemon, System)
- Add shell completion command (bash, zsh, fish, powershell)
- Add flag completions for --type, --quality, --sort, --lang, --genre,
--country, --method, --player
- Improve Long descriptions and Examples for all commands
- Split doctor disk check into platform-specific files (Unix/Windows)
- Validate infoHash length before truncating (prevent panic)
- Fix references to non-existent 'unarr daemon start' command
- Move stats command to System & Diagnostics group
- Rewrite README with complete documentation, correct config format
(toml not yaml), all commands, shell completion section
2026-03-28 21:36:27 +01:00
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("Config reload failed: %v", err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println("Config reloaded successfully")
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
}
|
2026-04-10 19:18:13 +02:00
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
}
|