Hi, has anyone got a working solution for how to pause Syncthing when switching to a metered wifi on Linux? I think I could run something like systemd-metered-connection-dependency/check-metered-connection.sh at master · jdorel/systemd-metered-connection-dependency · GitHub in a loop and turn off/on syncthing based on the exit code but maybe someone has other, possibly better, solutions? (It would be neat if syncthing itself could check metered-status, like what Gnome Software does, though it’s understandable if devs don’t want to add the complexity.)
Current solution:
==> /usr/local/bin/syncthing-respect-wifi-metering <==
#!/usr/bin/bash
while true; do
if wifi-is-unmetered; then
systemctl start syncthing@me.service syncthing@other.service
else
systemctl stop syncthing@me.service syncthing@other.service
fi
sleep 5
done
==> /usr/local/bin/wifi-is-unmetered <==
#!/usr/bin/bash
metered_status=$(dbus-send --system --print-reply=literal \
--system --dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.NetworkManager string:Metered \
| grep -o '.$')
if [[ $metered_status =~ (1|3) ]]; then
[[ $1 = -v ]] && echo Current connection is metered >&2
exit 1
else
[[ $1 = -v ]] && echo Current connection is unmetered >&2
exit 0
fi
(I guess an alternative to stop/start would be to sudo -u other syncthingcli pause --all-dirs )
https://github.com/martchus/syncthingtray has this functionality.