feat(daemon): add --foreground flag for systemd/supervisord integration
Adds --foreground flag to 'bd daemon --start' that runs the daemon in foreground instead of forking to background. This enables management by process supervisors like systemd, supervisord, or similar tools. Usage: bd daemon --start --foreground Closes #438 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -33,7 +33,8 @@ The daemon will:
|
|||||||
- Auto-import when remote changes detected
|
- Auto-import when remote changes detected
|
||||||
|
|
||||||
Common operations:
|
Common operations:
|
||||||
bd daemon --start Start the daemon
|
bd daemon --start Start the daemon (background)
|
||||||
|
bd daemon --start --foreground Start in foreground (for systemd/supervisord)
|
||||||
bd daemon --stop Stop a running daemon
|
bd daemon --stop Stop a running daemon
|
||||||
bd daemon --status Check if daemon is running
|
bd daemon --status Check if daemon is running
|
||||||
bd daemon --health Check daemon health and metrics
|
bd daemon --health Check daemon health and metrics
|
||||||
@@ -50,6 +51,7 @@ Run 'bd daemon' with no flags to see available options.`,
|
|||||||
autoPush, _ := cmd.Flags().GetBool("auto-push")
|
autoPush, _ := cmd.Flags().GetBool("auto-push")
|
||||||
localMode, _ := cmd.Flags().GetBool("local")
|
localMode, _ := cmd.Flags().GetBool("local")
|
||||||
logFile, _ := cmd.Flags().GetString("log")
|
logFile, _ := cmd.Flags().GetString("log")
|
||||||
|
foreground, _ := cmd.Flags().GetBool("foreground")
|
||||||
|
|
||||||
// If no operation flags provided, show help
|
// If no operation flags provided, show help
|
||||||
if !start && !stop && !status && !health && !metrics {
|
if !start && !stop && !status && !health && !metrics {
|
||||||
@@ -209,7 +211,7 @@ Run 'bd daemon' with no flags to see available options.`,
|
|||||||
fmt.Printf("Logging to: %s\n", logFile)
|
fmt.Printf("Logging to: %s\n", logFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
startDaemon(interval, autoCommit, autoPush, localMode, logFile, pidFile)
|
startDaemon(interval, autoCommit, autoPush, localMode, foreground, logFile, pidFile)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,6 +226,7 @@ func init() {
|
|||||||
daemonCmd.Flags().Bool("health", false, "Check daemon health and metrics")
|
daemonCmd.Flags().Bool("health", false, "Check daemon health and metrics")
|
||||||
daemonCmd.Flags().Bool("metrics", false, "Show detailed daemon metrics")
|
daemonCmd.Flags().Bool("metrics", false, "Show detailed daemon metrics")
|
||||||
daemonCmd.Flags().String("log", "", "Log file path (default: .beads/daemon.log)")
|
daemonCmd.Flags().String("log", "", "Log file path (default: .beads/daemon.log)")
|
||||||
|
daemonCmd.Flags().Bool("foreground", false, "Run in foreground (don't daemonize)")
|
||||||
daemonCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output JSON format")
|
daemonCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output JSON format")
|
||||||
rootCmd.AddCommand(daemonCmd)
|
rootCmd.AddCommand(daemonCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,15 +275,16 @@ func stopDaemon(pidFile string) {
|
|||||||
fmt.Println("Daemon killed")
|
fmt.Println("Daemon killed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// startDaemon starts the daemon in background
|
// startDaemon starts the daemon (in foreground if requested, otherwise background)
|
||||||
func startDaemon(interval time.Duration, autoCommit, autoPush, localMode bool, logFile, pidFile string) {
|
func startDaemon(interval time.Duration, autoCommit, autoPush, localMode, foreground bool, logFile, pidFile string) {
|
||||||
logPath, err := getLogFilePath(logFile)
|
logPath, err := getLogFilePath(logFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if os.Getenv("BD_DAEMON_FOREGROUND") == "1" {
|
// Run in foreground if --foreground flag set or if we're the forked child process
|
||||||
|
if foreground || os.Getenv("BD_DAEMON_FOREGROUND") == "1" {
|
||||||
runDaemonLoop(interval, autoCommit, autoPush, localMode, logPath, pidFile)
|
runDaemonLoop(interval, autoCommit, autoPush, localMode, logPath, pidFile)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user