You are not logged in.

#1 2019-02-09 08:41:14

apollo22
Member
Registered: 2018-04-13
Posts: 34

Systemd service on metered connection

Hi,

I've been searching for a way to prevent some systemd timers from running if my connection was metered. Finally got to a working solution, it currently use NetworkManager:

test.service

[Unit]
Description=Test service for the metered connection
Requires=unmetered-connection.service
After=unmetered-connection.service

[Service]
Type=oneshot
ExecStart=echo test

unmetered-connection.service

[Unit]
Description=Check if the current connection is metered

[Service]
Type=oneshot
ExecStart=check-metered-connection.sh

check-metered-connection.sh

#! /usr/bin/bash

metered_status=$(qdbus --system org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Metered)

if [[ $metered_status =~ (1|3) ]]; then
  echo Current connection is metered
  exit 1
else 
  exit 0
fi

I will certainly make a package out of it (this should finally make me learn that smile ).

Do you have any idea of how to make the logs more explicit ? Or do you have any other suggestions ?

EDIT: Just created a repo for this, if you have any suggestions: https://github.com/jdorel/systemd-meter … dependency

EDIT2: Removed the target file, I  misunderstood the usage of it ...

Last edited by apollo22 (2019-03-03 10:00:26)

Offline

Board footer

Powered by FluxBB