Execute systemd services if current connection is not metered.
Install `unmetered-connection.service` in `/usr/local/lib/systemd/system`.
Install `check-metered-connection.sh` in `/usr/local/bin`.
Execute `systemctl daemon-reload`
/!\ If you want it to be available to your users:
Install `unmetered-connection.service` in `/usr/local/lib/systemd/user`.
Execute `systemctl --user daemon-reload`
Add the following to any unit you do not want to execute on a metered connection
[Unit]
Requires=unmetered-connection.service
After=unmetered-connection.service
See exemple.service
for an exemple usage.
Network Manager might not guess the metered connection status. If so, use the following to mark a connection as metered:
$ nmcli con modify <connection-name> connection.metered yes
- When you add the
unmetered-connection.service
dependency to your service withRequires
andAfter
, on activation, your service will startunmetered-connection.service
. unmetered-connection.service
will execute thecheck-metered-connection.sh
bash script.check-metered-connection.sh
then uses DBUS and NetworkManager to check on the current connection status. It returns 0 for an unmetered connection and 1 for a metered connection.- If the script returns zero,
unmetered-connection.service
will fail, preventing execution of your service.
Support other connection managers
Display better logs
Package it (AUR)
Manage multiple connections
Disable metered verification through a service
Directly hook DBUS to systemd service
Use systemd target to start/stop services ?