feat: system service management (gyandoot service install|remove|status)

- Create systemd + launchd service templates in resources/
- Add gyandoot-core/src/service.rs module with full lifecycle
  - systemd: user service, daemon-reload, enable, start, stop, disable
  - launchd: macOS plist, load/unload, start/stop (launchctl)
- Add 'gyandoot service install|remove|status' CLI subcommand
- Update setup wizard: prompts 'Install system service? [y/N]'
- Update install.sh: prompts user for service install after binary
- Browser auto-starts at runtime (browser_manager), no separate service needed
- Camoufox installed via npm, auto-started by GyanDoot agent loop
This commit is contained in:
2026-06-11 23:23:49 +05:30
parent f2d612bd28
commit b2650a569c
8 changed files with 615 additions and 83 deletions

View File

@@ -79,90 +79,12 @@ install_camofox_browser() {
fi
}
setup_camofox_service() {
local os
os=$(detect_os)
info "Setting up camofox-browser to auto-start..."
case "$os" in
linux)
local service_file="/etc/systemd/system/camofox-browser.service"
if [ ! -f "$service_file" ]; then
cat > /tmp/camofox-browser.service << 'SYSTEMD'
[Unit]
Description=Camofox Browser — Anti-detection browser for AI agents
After=network.target
[Service]
Type=simple
ExecStart=npx camoufox-browser start --port 9377
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
SYSTEMD
sudo mv /tmp/camofox-browser.service "$service_file"
sudo systemctl daemon-reload
sudo systemctl enable camofox-browser
sudo systemctl start camofox-browser
ok "Camoufox auto-start service installed and started"
else
sudo systemctl start camofox-browser 2>/dev/null || true
ok "Camoufox service already exists"
fi
;;
darwin)
# macOS: create a launchd plist for auto-start
local plist="$HOME/Library/LaunchAgents/com.camoufox.browser.plist"
if [ ! -f "$plist" ]; then
mkdir -p "$HOME/Library/LaunchAgents"
local home_dir="$HOME"
cat > "$plist" << LAUNCHD
<?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">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.camoufox.browser</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/npx</string>
<string>camoufox-browser</string>
<string>start</string>
<string>--port</string>
<string>9377</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>${home_dir}/.gyandoot/camoufox.log</string>
<key>StandardErrorPath</key>
<string>${home_dir}/.gyandoot/camoufox.log</string>
</dict>
</plist>
LAUNCHD
launchctl load "$plist"
ok "Camoufox auto-start configured (launchd)"
else
launchctl load "$plist" 2>/dev/null || true
ok "Camoufox launchd plist already exists"
fi
;;
esac
ok "Camofox-browser auto-start setup complete"
}
build_release() {
local root_dir
root_dir="$(cd "$(dirname "$0")" && pwd)"
info "Building GyanDoot v2.0 in release mode..."
cd "$root_dir"
if [ ! -f "$root_dir/Cargo.toml" ]; then
# Fallback: find Cargo.toml in parent chain (in case script is in sub-dir)
local probe
probe="$(pwd)"
while [ "$probe" != "/" ]; do
@@ -210,6 +132,7 @@ print_post_install() {
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " gyandoot --help Show all commands"
echo " gyandoot init Create config"
echo " gyandoot setup Interactive setup wizard"
echo " gyandoot run Start interactive agent"
echo ""
echo " Browser Tools (anti-detection browsing):"
@@ -217,13 +140,28 @@ print_post_install() {
echo " gyandoot browser search <query>"
echo " gyandoot browser browse <url>"
echo ""
echo " Start camofox-browser:"
echo " sudo systemctl start camofox-browser"
echo " # Or manually: cd ~/camofox-browser && npm start"
echo " Service Management:"
echo " gyandoot service install Auto-start on boot"
echo " gyandoot service remove Remove system service"
echo " gyandoot service status Check service status"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
}
prompt_service_install() {
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Optional: Auto-start GyanDoot on Boot?"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " GyanDoot can run as a system service and"
echo " start automatically when your computer boots."
echo " This keeps the gateway server running in the background."
echo ""
echo " (You can also do this later with: gyandoot service install)"
echo ""
read -r -p " Install system service? [y/N]: " response
}
main() {
local os arch
os=$(detect_os)
@@ -237,8 +175,17 @@ main() {
build_release
install_binary
# Optional: don't fail if service setup doesn't work
setup_camofox_service 2>/dev/null || warn "Could not setup camofox service (manual start works)"
# Optional: install GyanDoot system service (auto-start on boot)
prompt_service_install
case "$response" in
[yY]|[yY][eE][sS])
info "Installing GyanDoot system service..."
gyandoot service install 2>&1 || warn "Service install failed (run 'gyandoot service install' later)"
;;
*)
info "Skipping service install (use 'gyandoot service install' later)"
;;
esac
print_post_install
}