Files
second-brain/SYSTEMD-SETUP.md
2026-04-26 06:09:22 +02:00

155 lines
2.8 KiB
Markdown

# Auto-Start Obsidian with Systemd
Ensures Obsidian starts automatically on boot and stays running.
## Installation
### 1. Install Required Packages
```bash
sudo apt update
sudo apt install -y xvfb xvfb-run
```
### 2. Copy Service Files
```bash
sudo cp /workspace/second-brain/obsidian.service /etc/systemd/system/
sudo cp /workspace/second-brain/obsidian-mcp.service /etc/systemd/system/
```
### 3. Reload Systemd
```bash
sudo systemctl daemon-reload
```
### 4. Enable Services
```bash
# Enable Obsidian to start on boot
sudo systemctl enable obsidian.service
# Enable MCP server (optional, but recommended)
sudo systemctl enable obsidian-mcp.service
```
### 5. Start Services
```bash
# Start both services
sudo systemctl start obsidian.service
sudo systemctl start obsidian-mcp.service
# Check status
sudo systemctl status obsidian.service
sudo systemctl status obsidian-mcp.service
```
---
## Managing Services
### View Logs
```bash
# Real-time Obsidian logs
sudo journalctl -fu obsidian.service
# Real-time MCP server logs
sudo journalctl -fu obsidian-mcp.service
# Last 50 lines
sudo journalctl -n 50 -u obsidian.service
```
### Stop/Restart
```bash
sudo systemctl stop obsidian.service
sudo systemctl restart obsidian.service
sudo systemctl restart obsidian-mcp.service
```
### Check Auto-Start
```bash
# List enabled services
systemctl list-unit-files | grep obsidian
# Should show "enabled" for both
```
---
## Service Configuration
### obsidian.service
- **Type:** simple
- **User:** intense
- **Display:** Virtual Xvfb (:99)
- **Restart:** Always (if crashes, restarts in 15s)
- **Memory Limit:** 2GB
- **CPU Quota:** 80%
### obsidian-mcp.service
- **Depends on:** obsidian.service
- **Type:** simple
- **Restart:** Always
- **Memory Limit:** 512MB
- **Health Check:** Verifies API is reachable on startup
---
## Troubleshooting
### Obsidian won't start
```bash
sudo journalctl -u obsidian.service -n 50 --no-pager
```
### MCP server failing
```bash
# Make sure .env has valid API key
cat /workspace/second-brain/.env | grep OBSIDIAN_API_KEY
```
### Can't connect to Obsidian
```bash
# Check if Obsidian is running
ps aux | grep obsidian
# Check virtual display
ps aux | grep Xvfb
# Manual test
DISPLAY=:99 xdpyinfo
```
### Port already in use
```bash
# Check who's using port 27123
sudo lsof -i :27123
```
---
## Alternative: Supervisor
If systemd doesn't work, use supervisord:
```bash
sudo apt install supervisor
cat > /etc/supervisor/conf.d/obsidian.conf << 'EOF'
[program:obsidian]
command=/home/intense/.local/bin/obsidian --no-sandbox
user=intense
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/obsidian.log
environment=DISPLAY=:99
EOF
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start obsidian
```
---
Created: 2026-04-26