You are not logged in.

#1 2014-05-30 18:09:04

thufirhawat
Member
Registered: 2013-06-22
Posts: 14

Notifications with systemd timer disappear to fast

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

#2 2014-05-30 18:46:35

SolarBoyMatt
Member
Registered: 2012-01-07
Posts: 263

Re: Notifications with systemd timer disappear to fast

Can you post the .timer file you're using?

Offline

#3 2014-05-30 21:01:43

thufirhawat
Member
Registered: 2013-06-22
Posts: 14

Re: Notifications with systemd timer disappear to fast

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

#4 2014-05-31 00:33:27

Stebalien
Member
Registered: 2010-04-27
Posts: 1,237
Website

Re: Notifications with systemd timer disappear to fast

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

#5 2014-05-31 17:28:53

thufirhawat
Member
Registered: 2013-06-22
Posts: 14

Re: Notifications with systemd timer disappear to fast

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

#6 2014-05-31 18:08:01

Stebalien
Member
Registered: 2010-04-27
Posts: 1,237
Website

Re: Notifications with systemd timer disappear to fast

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

#7 2015-07-15 13:51:34

jrk
Member
From: Nämberch
Registered: 2012-10-16
Posts: 37

Re: Notifications with systemd timer disappear to fast

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

#8 2015-07-15 14:04:51

Stebalien
Member
Registered: 2010-04-27
Posts: 1,237
Website

Re: Notifications with systemd timer disappear to fast

jrk wrote:

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

#9 2015-07-15 14:13:19

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,804

Re: Notifications with systemd timer disappear to fast

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

Board footer

Powered by FluxBB