fix: 自启动
This commit is contained in:
71
README.md
71
README.md
@@ -198,4 +198,75 @@ python3 monitor_sender.py --ip 10.0.0.5 --port 9000
|
||||
| `main_monitor.py` | FastAPI server — hosts the web GUI and relays data to browsers |
|
||||
| `monitor_sender.py` | ROS 2 node — collects robot data and streams it to the server |
|
||||
| `README.md` | This file |
|
||||
| `scripts/start_monitor_sender.sh` | Bootstrap script for hotspot connect, environment setup, and sender launch |
|
||||
| `deploy/xmonitor.env.example` | Template for `/etc/xmonitor/xmonitor.env` |
|
||||
| `deploy/xmonitor-sender.service` | `systemd` service template for robot-side autostart |
|
||||
|
||||
---
|
||||
|
||||
## Robot Sender Autostart (Ubuntu + systemd)
|
||||
|
||||
For field deployment on the robot controller, this repo now includes:
|
||||
|
||||
- `scripts/start_monitor_sender.sh`
|
||||
- `deploy/xmonitor.env.example`
|
||||
- `deploy/xmonitor-sender.service`
|
||||
|
||||
The design stays intentionally small:
|
||||
|
||||
- the startup script keeps trying to join your phone hotspot with `nmcli`
|
||||
- it waits until the PC hotspot IP is reachable
|
||||
- it sources the ROS setup and `.venv`
|
||||
- it launches `python3 monitor_sender.py --ip <server-ip> --port <port>`
|
||||
- `systemd` restarts the process after crashes, while logs go to both `journalctl` and `~/xMonitor/logs/`
|
||||
|
||||
### Install on the Ubuntu robot device
|
||||
|
||||
Assuming the repo is deployed at `/home/ubuntu/xMonitor`:
|
||||
|
||||
```bash
|
||||
cd /home/ubuntu/xMonitor
|
||||
|
||||
sudo install -d -m 700 /etc/xmonitor
|
||||
sudo cp deploy/xmonitor.env.example /etc/xmonitor/xmonitor.env
|
||||
sudo chmod 600 /etc/xmonitor/xmonitor.env
|
||||
sudoedit /etc/xmonitor/xmonitor.env
|
||||
|
||||
chmod +x scripts/start_monitor_sender.sh
|
||||
sudo cp deploy/xmonitor-sender.service /etc/systemd/system/xmonitor-sender.service
|
||||
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now xmonitor-sender.service
|
||||
```
|
||||
|
||||
If you deploy the repo somewhere other than `/home/ubuntu/xMonitor`, update these together:
|
||||
|
||||
- `User=` in `deploy/xmonitor-sender.service`
|
||||
- `WorkingDirectory=` in `deploy/xmonitor-sender.service`
|
||||
- `ExecStart=` in `deploy/xmonitor-sender.service`
|
||||
- `APP_DIR=` and `RUN_USER=` in `/etc/xmonitor/xmonitor.env`
|
||||
|
||||
### Runtime checks
|
||||
|
||||
```bash
|
||||
# Run the bootstrap script manually for troubleshooting
|
||||
bash /home/ubuntu/xMonitor/scripts/start_monitor_sender.sh
|
||||
|
||||
# Service state
|
||||
systemctl status xmonitor-sender.service
|
||||
|
||||
# Live logs from systemd
|
||||
journalctl -u xmonitor-sender.service -f
|
||||
|
||||
# Per-run log files
|
||||
ls /home/ubuntu/xMonitor/logs
|
||||
```
|
||||
|
||||
### Behavior
|
||||
|
||||
- Hotspot connect retry: every 5 seconds until the target SSID is connected
|
||||
- Server reachability retry: every 5 seconds until `SERVER_IP` answers `ping`
|
||||
- Python process crash: `systemd` restarts after 5 seconds
|
||||
- WebSocket drop after startup: handled by `monitor_sender.py`, which already retries every 3 seconds
|
||||
- Per-run log files are pruned automatically; default retention is the latest 20 files via `LOG_RETENTION_COUNT`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user