systemd
Running Snippbot under systemd ensures it starts automatically on boot and restarts on failure.
Create the service file
Section titled “Create the service file”-
Create the unit file
Terminal window sudo nano /etc/systemd/system/snippbot.service -
Paste the configuration
/etc/systemd/system/snippbot.service [Unit]Description=Snippbot AI Agent DaemonAfter=network.targetWants=network-online.target[Service]Type=simpleUser=snippbotGroup=snippbotWorkingDirectory=/opt/snippbotExecStart=/opt/snippbot/.venv/bin/snippbot start --host 127.0.0.1 --port 18781ExecStop=/opt/snippbot/.venv/bin/snippbot stopRestart=on-failureRestartSec=5StandardOutput=journalStandardError=journalSyslogIdentifier=snippbot# EnvironmentEnvironment="ANTHROPIC_API_KEY=sk-ant-your-key"Environment="SNIPPBOT_LOG_LEVEL=info"# Or load from an environment file:# EnvironmentFile=/etc/snippbot/env# Security hardeningNoNewPrivileges=truePrivateTmp=trueProtectSystem=strictReadWritePaths=/home/snippbot/.snippbot /opt/snippbot[Install]WantedBy=multi-user.target -
Reload systemd and enable
Terminal window sudo systemctl daemon-reloadsudo systemctl enable snippbotsudo systemctl start snippbot -
Verify it’s running
Terminal window sudo systemctl status snippbotcurl http://localhost:18781/health
Using an environment file
Section titled “Using an environment file”Instead of embedding secrets in the unit file, use an environment file:
ANTHROPIC_API_KEY=sk-ant-your-keyOPENAI_API_KEY=sk-your-openai-keySNIPPBOT_PORT=18781SNIPPBOT_LOG_LEVEL=infoSet permissions and reference it:
sudo chmod 600 /etc/snippbot/envsudo chown root:root /etc/snippbot/envIn the unit file:
EnvironmentFile=/etc/snippbot/envCommands
Section titled “Commands”sudo systemctl start snippbot # Startsudo systemctl stop snippbot # Stopsudo systemctl restart snippbot # Restartsudo systemctl status snippbot # Statussudo systemctl enable snippbot # Enable at bootsudo systemctl disable snippbot # Disable at bootView logs
Section titled “View logs”journalctl -u snippbot -f # Follow live logsjournalctl -u snippbot --since todayjournalctl -u snippbot -n 100 # Last 100 linesCreate a dedicated user
Section titled “Create a dedicated user”For security, run Snippbot as a dedicated non-root user:
sudo useradd -r -s /bin/false -d /home/snippbot snippbotsudo mkdir -p /home/snippbot/.snippbotsudo chown -R snippbot:snippbot /home/snippbot/.snippbot