kolinger / rd-usb

Web GUI for RuiDeng/Riden USB testers (UM34C, UM24C, UM25C, TC66C)
GNU General Public License v3.0
223 stars 29 forks source link

Example service? #30

Closed Bluscream closed 2 years ago

Bluscream commented 2 years ago

Since the readme states ``

i would like to create a service that ensures proper operation after a reboot;

[Service]
ExecStart=python3 /srv/usbmeter/rd-usb/web.py --daemon --prefix /usb/ # Start daemon
Restart=on-success
RestartSec=1m
User=www-data

[Install]
WantedBy=multi-user.target

[Unit]
Description=USB Meter Monitoring Webserver
After=network.target

this is what i have to far but sadly it does not seem to be able to start everything; especially the bluetooth connection and serial binding. Could you provide some help with this?

kolinger commented 2 years ago

You need to create another service for rfcomm since it needs to be run as root.

For example /etc/systemd/system/rfcomm0.service could look like:

[Unit]
Description=rfcomm0
After=bluetooth.target

[Service]
Type=oneshot
ExecStart=/usr/bin/rfcomm bind 0 BLUETOOTH_ADDRESS_HERE
ExecStart=/usr/bin/chown YOUR_USER: /dev/rfcomm0
ExecStop=/usr/bin/rfcomm release 0
RemainAfterExit=yes
Restart=no

[Install]
WantedBy=multi-user.target

And of course systemctl enable rfcomm0.service

Bluscream commented 2 years ago

Thanks a lot :) This worked for me:

[Unit]
Description=rfcomm0
After=bluetooth.target

[Service]
Type=oneshot
User=root
ExecStart=/usr/bin/rfcomm bind 0 00:16:A6:00:1C:E3
ExecStart=/usr/bin/chown root:dialout /dev/rfcomm0
ExecStop=/usr/bin/rfcomm release 0
RemainAfterExit=yes
Restart=no

[Install]
WantedBy=multi-user.target