---
title: Systemd Service
description: "Run Mudabbir as a systemd service on Linux for automatic startup, restart on failure, and clean shutdown. Includes a complete unit file with security hardening and journal logging configuration."
section: Deployment
ogType: article
keywords: ["systemd", "linux service", "auto-start", "daemon", "unit file"]
tags: ["deployment", "systemd", "linux"]
---

# Systemd Service

Run Mudabbir as a background service on Linux with systemd for automatic startup and restart.

## Service File

Create `/etc/systemd/system/mudabbir.service`:

```ini
[Unit]
Description=Mudabbir AI Agent
After=network.target

[Service]
Type=simple
User=mudabbir
Group=mudabbir
WorkingDirectory=/home/mudabbir
ExecStart=/usr/local/bin/mudabbir
Restart=on-failure
RestartSec=10

# Environment
EnvironmentFile=/etc/mudabbir/env

# Security hardening
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=read-only
ReadWritePaths=/home/mudabbir/.mudabbir
PrivateTmp=yes

[Install]
WantedBy=multi-user.target
```

## Environment File

Create `/etc/mudabbir/env`:

```bash
MUDABBIR_ANTHROPIC_API_KEY=sk-ant-your-key
MUDABBIR_WEB_HOST=127.0.0.1
MUDABBIR_WEB_PORT=8888
MUDABBIR_AGENT_BACKEND=claude_agent_sdk
MUDABBIR_TOOL_PROFILE=coding
```

Set permissions:

```bash
sudo chmod 600 /etc/mudabbir/env
sudo chown mudabbir:mudabbir /etc/mudabbir/env
```

## Setup

```bash
# Create dedicated user
sudo useradd -m -s /bin/bash mudabbir

# Install Mudabbir
sudo -u mudabbir pip install --user mudabbir[recommended]

# Create config directory
sudo mkdir -p /etc/mudabbir
sudo chown mudabbir:mudabbir /etc/mudabbir

# Enable and start service
sudo systemctl daemon-reload
sudo systemctl enable mudabbir
sudo systemctl start mudabbir
```

## Managing the Service

```bash
# Start
sudo systemctl start mudabbir

# Stop
sudo systemctl stop mudabbir

# Restart
sudo systemctl restart mudabbir

# Check status
sudo systemctl status mudabbir

# View logs
sudo journalctl -u mudabbir -f

# View recent logs
sudo journalctl -u mudabbir --since "1 hour ago"
```

## Log Rotation

Systemd handles log rotation via journald. For the audit log, add a logrotate config:

```
/home/mudabbir/.mudabbir/audit.jsonl {
    weekly
    rotate 12
    compress
    missingok
    notifempty
    copytruncate
}
```

## Auto-Updates

Create a timer for periodic updates:

```ini
# /etc/systemd/system/mudabbir-update.timer
[Unit]
Description=Update Mudabbir weekly

[Timer]
OnCalendar=weekly
Persistent=true

[Install]
WantedBy=timers.target
```

```ini
# /etc/systemd/system/mudabbir-update.service
[Unit]
Description=Update Mudabbir

[Service]
Type=oneshot
User=mudabbir
ExecStart=/usr/local/bin/pip install --upgrade mudabbir[recommended]
ExecStartPost=/bin/systemctl restart mudabbir
```
