Skip to content

systemd

Running Snippbot under systemd ensures it starts automatically on boot and restarts on failure.

  1. Create the unit file

    Terminal window
    sudo nano /etc/systemd/system/snippbot.service
  2. Paste the configuration

    /etc/systemd/system/snippbot.service
    [Unit]
    Description=Snippbot AI Agent Daemon
    After=network.target
    Wants=network-online.target
    [Service]
    Type=simple
    User=snippbot
    Group=snippbot
    WorkingDirectory=/opt/snippbot
    ExecStart=/opt/snippbot/.venv/bin/snippbot start --host 127.0.0.1 --port 18781
    ExecStop=/opt/snippbot/.venv/bin/snippbot stop
    Restart=on-failure
    RestartSec=5
    StandardOutput=journal
    StandardError=journal
    SyslogIdentifier=snippbot
    # Environment
    Environment="ANTHROPIC_API_KEY=sk-ant-your-key"
    Environment="SNIPPBOT_LOG_LEVEL=info"
    # Or load from an environment file:
    # EnvironmentFile=/etc/snippbot/env
    # Security hardening
    NoNewPrivileges=true
    PrivateTmp=true
    ProtectSystem=strict
    ReadWritePaths=/home/snippbot/.snippbot /opt/snippbot
    [Install]
    WantedBy=multi-user.target
  3. Reload systemd and enable

    Terminal window
    sudo systemctl daemon-reload
    sudo systemctl enable snippbot
    sudo systemctl start snippbot
  4. Verify it’s running

    Terminal window
    sudo systemctl status snippbot
    curl http://localhost:18781/health

Instead of embedding secrets in the unit file, use an environment file:

/etc/snippbot/env
ANTHROPIC_API_KEY=sk-ant-your-key
OPENAI_API_KEY=sk-your-openai-key
SNIPPBOT_PORT=18781
SNIPPBOT_LOG_LEVEL=info

Set permissions and reference it:

Terminal window
sudo chmod 600 /etc/snippbot/env
sudo chown root:root /etc/snippbot/env

In the unit file:

EnvironmentFile=/etc/snippbot/env
Terminal window
sudo systemctl start snippbot # Start
sudo systemctl stop snippbot # Stop
sudo systemctl restart snippbot # Restart
sudo systemctl status snippbot # Status
sudo systemctl enable snippbot # Enable at boot
sudo systemctl disable snippbot # Disable at boot
Terminal window
journalctl -u snippbot -f # Follow live logs
journalctl -u snippbot --since today
journalctl -u snippbot -n 100 # Last 100 lines

For security, run Snippbot as a dedicated non-root user:

Terminal window
sudo useradd -r -s /bin/false -d /home/snippbot snippbot
sudo mkdir -p /home/snippbot/.snippbot
sudo chown -R snippbot:snippbot /home/snippbot/.snippbot