feature implementation: gateway daemon commands#737
Closed
vvr3ddy wants to merge 4 commits intosipeed:mainfrom
Closed
feature implementation: gateway daemon commands#737vvr3ddy wants to merge 4 commits intosipeed:mainfrom
vvr3ddy wants to merge 4 commits intosipeed:mainfrom
Conversation
Add start, stop, restart, and status commands for running the gateway as a background daemon with automatic crash recovery. This allows the gateway to run without occupying a terminal, making it suitable for production deployments on resource-constrained hardware like Raspberry Pi. Features: - Daemon mode with PID file management - Auto-restart with exponential backoff (3 attempts, 5-min window) - File logging with automatic rotation (100MB, 3 backups) - Status tracking (PID, uptime, restart count) - Graceful shutdown with SIGTERM handling New commands: - picoclaw gateway start # Start as daemon - picoclaw gateway stop # Stop daemon - picoclaw gateway restart # Restart with auto-recovery - picoclaw gateway status # Show daemon status Architecture: - New pkg/daemon package following existing service patterns - Atomic state persistence (temp file + rename) - Thread-safe operations with mutex protection - Cross-platform support (Linux, macOS, ARM64, x86_64)
The Write() method was using os.Getpid() which writes the parent's PID instead of the spawned child process PID. Added WritePID() method to explicitly write a specific PID and added process verification after spawn.
The Restart() method was acquiring a lock then calling Stop() which tried to acquire the same lock, causing a deadlock. Fixed by creating stopLocked() method that assumes lock is already held, and having Restart() call stopLocked() directly.
The Restart() method was calling startInternal() which waits for the gateway to exit. This is wrong for manual restart commands. Fixed by: - Creating startLocked() that starts and returns immediately - Having Restart() call startLocked() for immediate return - Adding RunWithAutoRestart() for crash monitoring with retry Now manual 'picoclaw gateway restart' works as expected: stops the gateway, starts it, and returns immediately.
Open
bf8fac0 to
072c4f9
Compare
|
Suggestion, in the context of a fully featured linux host.
|
Collaborator
|
Thanks for your contribution! With #429 merged in, this may need a big change. :( |
Author
|
I will reference this in a new PR then :) |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add start, stop, restart, and status commands for running the gateway as a background daemon with automatic crash recovery.
This allows the gateway to run without occupying a terminal, making it suitable for production deployments on resource-constrained hardware like Raspberry Pi.
Features:
New commands:
Architecture:
📝 Description
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
📚 Technical Context (Skip for Docs)
🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
Logs Here
☑️ Checklist