upower: Restart systemd files
authorStefan Huber <shuber@sthu.org>
Wed, 13 Jan 2021 14:35:56 +0000 (15:35 +0100)
committerStefan Huber <shuber@sthu.org>
Wed, 13 Jan 2021 14:35:56 +0000 (15:35 +0100)
upower/upower-bat-refresh [new file with mode: 0755]
upower/upower-bat-restart.service [new file with mode: 0644]
upower/upower-bat-restart.timer [new file with mode: 0644]

diff --git a/upower/upower-bat-refresh b/upower/upower-bat-refresh
new file mode 100755 (executable)
index 0000000..c92b53c
--- /dev/null
@@ -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 (file)
index 0000000..69dd29f
--- /dev/null
@@ -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 (file)
index 0000000..ef6f3fc
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=upower battery restart timer
+
+[Timer]
+OnBootSec=1m
+OnUnitActiveSec=3m
+Unit=upower-bat-restart.service
+
+[Install]
+WantedBy=timers.target