From b65a9ad8ed7a20111564281573d746709158e41e Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Wed, 13 Jan 2021 15:35:56 +0100 Subject: [PATCH] upower: Restart systemd files --- upower/upower-bat-refresh | 50 +++++++++++++++++++++++++++++++ upower/upower-bat-restart.service | 6 ++++ upower/upower-bat-restart.timer | 10 +++++++ 3 files changed, 66 insertions(+) create mode 100755 upower/upower-bat-refresh create mode 100644 upower/upower-bat-restart.service create mode 100644 upower/upower-bat-restart.timer diff --git a/upower/upower-bat-refresh b/upower/upower-bat-refresh new file mode 100755 index 0000000..c92b53c --- /dev/null +++ b/upower/upower-bat-refresh @@ -0,0 +1,50 @@ +#!/bin/sh + +usage() +{ +cat << EOF +Usage: + $0 [OPTIONS] + $0 -h + +Refresh battery information provided by upower. + +OPTIONS: + -h Show this help. + -r Restart upower service +EOF +} + + +restartdaemon=0 + +while getopts "rRhnq8HSxc:s:t:T:uL" OPTION +do + case $OPTION in + h) + usage + exit + ;; + r) + restartdaemon=1 + ;; + *) + usage >&2 + exit 1 + ;; + esac +done +shift $(($OPTIND - 1)) + + + +if [ "${restartdaemon}" -gt 0 ]; then + systemctl restart upower +else + for bat in BAT0 BAT1; do + busctl call --system \ + org.freedesktop.UPower \ + /org/freedesktop/UPower/devices/battery_${bat} \ + org.freedesktop.UPower.Device Refresh + done +fi diff --git a/upower/upower-bat-restart.service b/upower/upower-bat-restart.service new file mode 100644 index 0000000..69dd29f --- /dev/null +++ b/upower/upower-bat-restart.service @@ -0,0 +1,6 @@ +[Unit] +Description=upower battery restart service + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/upower-bat-refresh -r diff --git a/upower/upower-bat-restart.timer b/upower/upower-bat-restart.timer new file mode 100644 index 0000000..ef6f3fc --- /dev/null +++ b/upower/upower-bat-restart.timer @@ -0,0 +1,10 @@ +[Unit] +Description=upower battery restart timer + +[Timer] +OnBootSec=1m +OnUnitActiveSec=3m +Unit=upower-bat-restart.service + +[Install] +WantedBy=timers.target -- 2.39.5