Last active
March 25, 2019 22:02
-
-
Save dsprenkels/d3a39cb504207e43cab3cfb8bfaa5b79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# csd-power-watchdog | |
# | |
# Description: check if csd-power is quiet and restart if it is | |
# Author: Daan Sprenkels <[email protected]> | |
# | |
# On my system, csd-power often locks up when closing the lid of my laptop | |
# when an external monitor is attached. This script is a watchdog to kick | |
# the csd-power daemon if it looks unresponsive. | |
# Every now and then minutes, csd-power reports the current battery level | |
# to the DBus. This script monitors the bus and restarts csd-power is it | |
# has been silent for more than 4 minutes. | |
systemd-cat -t csd-power-watchdog <<EOF | |
Starting csd-power-watchdog for user $(whoami)... | |
EOF | |
while true; do | |
# Listen for messages on the DBus | |
TEMPFILE="$(mktemp /tmp/csd-power-watchdog.XXXXXXXX.txt)" | |
dbus-monitor --session "type=signal,path=/org/cinnamon/SettingsDaemon/Power" >"$TEMPFILE" & | |
MONPID="$!" | |
sleep "245" # Wait a little more than 4 minutes | |
kill "$MONPID" | |
# We've listened for some time, check if csd-power has been active | |
grep --quiet -E '\bpath=/org/cinnamon/SettingsDaemon/Power\b' "$TEMPFILE" | |
if [ "$?" != 0 ]; then | |
systemd-cat -t csd-power-watchdog <<EOF | |
csd-power has been quiet for more than 4 minutes, restarting... | |
EOF | |
killall --quiet --user "$(whoami)" csd-power | |
sleep 1 # Allow for graceful exit of the process | |
killall --quiet --user "$(whoami)" -SIGKILL csd-power | |
/usr/lib/cinnamon-settings-daemon/csd-power & | |
disown | |
fi | |
rm "$TEMPFILE" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The bug does not seem to occur anymore. I am locally disabling this script.