Thought I would share my system.d setup.   I've been running weewx for 
years now, but I recently extended my USB with a USB extended 40ft away 
from where it was.
Since then, once in a great while, the USB driver would fail and take weewx 
down with it. Then I had to reboot it the server (if remote) or 
unplug/replug the USB cable.

I did some investigating on self healing, and system.d can actually heal it 
when it happens using OnFailure.  It starts another system.d that runs one 
time, fixes it, and then starts weewx.

The hex for "usb_modeswitch -v 0x10c4 -p 0xea60" can be found when you do 
lsusb.  Using the hex, it will find it even if it changes ttys0/1/2.

Here is my Config. Enjoy!

-Mark


# cat /usr/lib/systemd/system/weewx.service
# systemd service configuration file for WeeWX

[Unit]
Description=WeeWX
Documentation=https://weewx.com/docs
Requires=time-sync.target
After=time-sync.target
Wants=network-online.target
After=network-online.target
OnFailure=weewx-resetusb.service

[Service]
ExecStart=weewxd /etc/weewx/weewx.conf
Restart=on-failure
StandardOutput=null
StandardError=journal+console
RuntimeDirectory=weewx
RuntimeDirectoryMode=775
User=weewx
Group=weewx

[Install]
WantedBy=multi-user.target
-------------------------------------------------------
# cat /usr/lib/systemd/system/weewx-resetusb.service
# systemd service configuration file for WeeWX

[Unit]
Description=WeeWX reset USB

[Service]
Type=oneshot
ExecStart=/usr/local/bin/restart-vue-usb.sh

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

# cat /usr/local/bin/restart-vue-usb.sh
#!/bin/sh
/usr/sbin/usb_modeswitch -v 0x10c4 -p 0xea60 --reset-usb
echo "system.d restarted weewx USB." | s-nail -s "Restarted USB" -r 
[email protected] [email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/weewx-user/2bba5bb5-0d45-48e0-8355-b0e868a9c471n%40googlegroups.com.

Reply via email to