140 lines
2.7 KiB
Markdown
140 lines
2.7 KiB
Markdown
# Alternative: Run without Docker
|
|
|
|
If you prefer to run directly on PiKVM without Docker, follow these steps:
|
|
|
|
## Installation
|
|
|
|
### 1. Install Dependencies
|
|
|
|
```bash
|
|
sudo apt-get update
|
|
sudo apt-get install -y python3 python3-pip python3-gpiozero python3-pip iputils-ping
|
|
```
|
|
|
|
### 2. Install Python Packages
|
|
|
|
```bash
|
|
pip3 install --user ping3==4.0.1 gpiozero==2.0.1 RPi.GPIO==0.7.0
|
|
```
|
|
|
|
### 3. Copy Files
|
|
|
|
```bash
|
|
sudo mkdir -p /opt/pikvm-monitor
|
|
sudo cp monitor.py /opt/pikvm-monitor/
|
|
sudo chown pikvm:pikvm /opt/pikvm-monitor/monitor.py
|
|
sudo chmod +x /opt/pikvm-monitor/monitor.py
|
|
```
|
|
|
|
## Option A: Run as systemd Service
|
|
|
|
### 1. Create systemd service file
|
|
|
|
```bash
|
|
sudo tee /etc/systemd/system/pikvm-monitor.service << EOF
|
|
[Unit]
|
|
Description=PiKVM Auto-Restart Monitor
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=pikvm
|
|
WorkingDirectory=/opt/pikvm-monitor
|
|
ExecStart=/usr/bin/python3 /opt/pikvm-monitor/monitor.py
|
|
Restart=always
|
|
RestartSec=10
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
# GPIO requires this
|
|
ExecStartPost=/bin/sh -c 'echo pikvm | sudo -S usermod -a -G gpio,spi pikvm'
|
|
|
|
# Environment variables
|
|
Environment="HOST_IP=192.168.1.10"
|
|
Environment="GATEWAY_IP=192.168.1.1"
|
|
Environment="POWER_BUTTON_GPIO=17"
|
|
Environment="PING_INTERVAL=180"
|
|
Environment="DOWNTIME_THRESHOLD=15"
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
```
|
|
|
|
### 2. Enable and Start
|
|
|
|
```bash
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable pikvm-monitor
|
|
sudo systemctl start pikvm-monitor
|
|
```
|
|
|
|
### 3. Check Status
|
|
|
|
```bash
|
|
sudo systemctl status pikvm-monitor
|
|
sudo journalctl -u pikvm-monitor -f
|
|
```
|
|
|
|
## Option B: Run in Screen/Tmux
|
|
|
|
```bash
|
|
screen -S pikvm-monitor python3 /opt/pikvm-monitor/monitor.py
|
|
```
|
|
|
|
## Option C: Cron-based Task
|
|
|
|
For lightweight monitoring, you could create a simple cron check, but systemd service is recommended for continuous monitoring.
|
|
|
|
## GPIO Permissions
|
|
|
|
Make sure the `pikvm` user has GPIO access:
|
|
|
|
```bash
|
|
sudo usermod -a -G gpio pikvm
|
|
sudo usermod -a -G spi pikvm
|
|
```
|
|
|
|
Then log out and log back in.
|
|
|
|
## Logs
|
|
|
|
Logs go to `/var/log/pikvm-monitor.log`:
|
|
|
|
```bash
|
|
tail -f /var/log/pikvm-monitor.log
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Permission denied on GPIO
|
|
|
|
```bash
|
|
sudo usermod -a -G gpio pikvm
|
|
# Log out and back in
|
|
```
|
|
|
|
### Module not found
|
|
|
|
```bash
|
|
pip3 install --user ping3 gpiozero RPi.GPIO
|
|
```
|
|
|
|
### Test GPIO locally
|
|
|
|
```bash
|
|
python3 -c "from gpiozero import Button; print('GPIO OK')"
|
|
```
|
|
|
|
## Docker vs Native
|
|
|
|
| | Docker | Native |
|
|
|---|--------|--------|
|
|
| Isolation | ✓ | ✗ |
|
|
| Portability | ✓ | ✗ |
|
|
| Resource use | Higher | Lower |
|
|
| Setup time | Faster | More steps |
|
|
| Debugging | docker logs | journalctl |
|
|
| Recommended | ✓ | Used if Docker unavailable |
|