You are not logged in.
Pages: 1
Topic closed
Hi,
I use systemd timers as cron replacement to display a low battery warning with dunst. Everything works fine, except that the dunst notification disappears almost imediately.
Any hints how it last longer than a millisecond?
Cheers and thanks
Offline
Can you post the .timer file you're using?
Offline
Sure, here you go:
# cat battery-warning.timer
[Unit]
Description=Battery Timer
[Timer]
OnCalendar=*:0/1
Persistent=true
Unit=battery-warning.service
[Install]
WantedBy=basic.target
Offline
And the service. Also, you probably don't need it to be persistent and it should have WantedBy=timers.target instead of basic.target.
Last edited by Stebalien (2014-05-31 00:35:11)
Steven [ web : git ]
GPG: 327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C
Do not email: honeypot@stebalien.com
Offline
Here's the service:
[Unit]
Description=Check battery and display warning
[Service]
User=xhr
Environment=DISPLAY=:0
Type=oneshot
ExecStartPre=
ExecStart=/home/x/bin/low-battery
And the script:
$ cat low-battery
#!/bin/bash
# From https://faq.i3wm.org/question/1730/warn … -very-low/
BATTINFO=`acpi -b`
if [[ `echo $BATTINFO | grep Discharging` && `echo $BATTINFO | cut -f 5 -d " "` < 00:15:00 ]] ; then
DISPLAY=:0.0 /usr/bin/notify-send -u critical -t 1000 "Low Battery" "$BATTINFO"
fi
Offline
When you run notify-send from a systemd service, it doesn't know about your dbus session bus (the DBUS_SESSION_BUS_ADDRESS environment variable isn't set). Basically, notify-send is forking a dbus instance, telling it to display a notification (which causes the dbus instance to start dunst), and then exiting. Unfortunately, when it exits, systemd helpfully cleans up any leftover children (the dbus instance and dnust).
The correct way to do this is to use a systemd user instance (https://wiki.archlinux.org/index.php/Systemd/User). Basically, just move those units over to the user instance and make sure to configure dbus correctly.
Also, in the future, please use code tags when pasting blocks of code.
Last edited by Stebalien (2014-05-31 18:09:46)
Steven [ web : git ]
GPG: 327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C
Do not email: honeypot@stebalien.com
Offline
I'd like to add that the proper way of doing this would be to listen for a dbus signal emitted for example by UPower. That'd avoid polling completely.
Offline
I'd like to add that the proper way of doing this would be to listen for a dbus signal emitted for example by UPower. That'd avoid polling completely.
UPower also polls (every 30s when discharging/120s otherwise). Regardless, this topic is over a year old, pease don't necrobump.
Steven [ web : git ]
GPG: 327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C
Do not email: honeypot@stebalien.com
Offline
Time to close this topic. If someone wishes to continue, please pick it up in a new thread and link back to this one.
Thanks.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Pages: 1
Topic closed