dunst-project / dunst

Lightweight and customizable notification daemon
https://dunst-project.org
Other
4.65k stars 343 forks source link

Dunst service doesn't start with systemd but it starts by hand on ArchLinux + I3WM #1028

Closed madipietro closed 2 years ago

madipietro commented 2 years ago

Issue description

Hello Folks, I'm looking for some help since I have dunst installed on ArchLinux with I3wm and suddenly it stopped working via Systemd while I can make it work by hand.

pkill dunst; dunst : This works.

/usr/bin/dunst: This works.

systemctl --user restart dunst.service: This works.

Installation info

Minimal dunstrc ```ini [global] ### Display ### #layer = overlay fullscreen = pushback # Which monitor should the notifications be displayed on. monitor = 0 # Display notification on focused monitor. Possible modes are: # mouse: follow mouse pointer # keyboard: follow window with keyboard focus # none: don't follow anything # # "keyboard" needs a window manager that exports the # _NET_ACTIVE_WINDOW property. # This should be the case for almost all modern window managers. # # If this option is set to mouse or keyboard, the monitor option # will be ignored. follow = mouse # The geometry of the window: # [{width}]x{height}[+/-{x}+/-{y}] # The geometry of the message window. # The height is measured in number of notifications everything else # in pixels. If the width is omitted but the height is given # ("-geometry x2"), the message window expands over the whole screen # (dmenu-like). If width is 0, the window expands to the longest # message displayed. A positive x is measured from the left, a # negative from the right side of the screen. Y is measured from # the top and down respectively. # The width can be negative. In this case the actual width is the # screen width minus the width defined in within the geometry option. geometry = "0x4-25-10" # Show how many messages are currently hidden (because of geometry). indicate_hidden = yes # Shrink window if it's smaller than the width. Will be ignored if # width is 0. shrink = no # The transparency of the window. Range: [0; 100]. # This option will only work if a compositing window manager is # present (e.g. xcompmgr, compiz, etc.). transparency = 0 # The height of the entire notification. If the height is smaller # than the font height and padding combined, it will be raised # to the font height and padding. notification_height = 0 # Draw a line of "separator_height" pixel height between two # notifications. # Set to 0 to disable. separator_height = 1 # Padding between text and separator. padding = 8 # Horizontal padding. horizontal_padding = 10 # Defines width in pixels of frame around the notification window. # Set to 0 to disable. frame_width = 0 # Defines color of the frame around the notification window. frame_color = "#282a36" # Define a color for the separator. # possible values are: # * auto: dunst tries to find a color fitting to the background; # * foreground: use the same color as the foreground; # * frame: use the same color as the frame; # * anything else will be interpreted as a X color. separator_color = frame # Sort messages by urgency. sort = yes # Don't remove messages, if the user is idle (no mouse or keyboard input) # for longer than idle_threshold seconds. # Set to 0 to disable. # A client can set the 'transient' hint to bypass this. See the rules # section for how to disable this if necessary idle_threshold = 120 ### Text ### font = Monospace 14: # The spacing between lines. If the height is smaller than the # font height, it will get raised to the font height. line_height = 0 # Possible values are: # full: Allow a small subset of html markup in notifications: # bold # italic # strikethrough # underline # # For a complete reference see # . # # strip: This setting is provided for compatibility with some broken # clients that send markup even though it's not enabled on the # server. Dunst will try to strip the markup but the parsing is # simplistic so using this option outside of matching rules for # specific applications *IS GREATLY DISCOURAGED*. # # no: Disable markup parsing, incoming notifications will be treated as # plain text. Dunst will not advertise that it has the body-markup # capability if this is set as a global setting. # # It's important to note that markup inside the format option will be parsed # regardless of what this is set to. markup = full # The format of the message. Possible variables are: # %a appname # %s summary # %b body # %i iconname (including its path) # %I iconname (without its path) # %p progress value if set ([ 0%] to [100%]) or nothing # %n progress value if set without any extra characters # %% Literal % # Markup is allowed format = "%s %p\n%b" # Alignment of message text. # Possible values are "left", "center" and "right". alignment = left # Vertical alignment of message text and icon. # Possible values are "top", "center" and "bottom". vertical_alignment = center # Show age of message if message is older than show_age_threshold # seconds. # Set to -1 to disable. show_age_threshold = 60 # Split notifications into multiple lines if they don't fit into # geometry. word_wrap = yes # When word_wrap is set to no, specify where to make an ellipsis in long lines. # Possible values are "start", "middle" and "end". ellipsize = middle # Ignore newlines '\n' in notifications. ignore_newline = no # Stack together notifications with the same content stack_duplicates = true # Hide the count of stacked notifications with the same content hide_duplicate_count = false # Display indicators for URLs (U) and actions (A). show_indicators = yes ### Icons ### # Align icons left/right/off icon_position = left # Scale small icons up to this size, set to 0 to disable. Helpful # for e.g. small files or high-dpi screens. In case of conflict, # max_icon_size takes precedence over this. min_icon_size = 0 # Scale larger icons down to this size, set to 0 to disable max_icon_size = 128 # Paths to default icons. icon_path = /usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/ ### History ### # Should a notification popped up from history be sticky or timeout # as if it would normally do. sticky_history = no # Maximum amount of notifications kept in history history_length = 20 ### Misc/Advanced ### # dmenu path. dmenu = /usr/bin/dmenu -p dunst: # Browser for opening urls in context menu. browser = /usr/bin/firefox -new-tab # Always run rule-defined scripts, even if the notification is suppressed always_run_script = true # Define the title of the windows spawned by dunst title = Dunst # Define the class of the windows spawned by dunst class = Dunst # Print a notification on startup. # This is mainly for error detection, since dbus (re-)starts dunst # automatically after a crash. startup_notification = false # Manage dunst's desire for talking # Can be one of the following values: # crit: Critical features. Dunst aborts # warn: Only non-fatal warnings # mesg: Important Messages # info: all unimportant stuff # debug: all less than unimportant stuff verbosity = mesg # Define the corner radius of the notification window # in pixel size. If the radius is 0, you have no rounded # corners. # The radius will be automatically lowered if it exceeds half of the # notification height to avoid clipping text and/or icons. corner_radius = 0 # Ignore the dbus closeNotification message. # Useful to enforce the timeout set by dunst configuration. Without this # parameter, an application may close the notification sent before the # user defined timeout. ignore_dbusclose = false ### Legacy # Use the Xinerama extension instead of RandR for multi-monitor support. # This setting is provided for compatibility with older nVidia drivers that # do not support RandR and using it on systems that support RandR is highly # discouraged. # # By enabling this setting dunst will not be able to detect when a monitor # is connected or disconnected which might break follow mode if the screen # layout changes. force_xinerama = false ### mouse # Defines list of actions for each mouse event # Possible values are: # * none: Don't do anything. # * do_action: If the notification has exactly one action, or one is marked as default, # invoke it. If there are multiple and no default, open the context menu. # * close_current: Close current notification. # * close_all: Close all notifications. # These values can be strung together for each mouse event, and # will be executed in sequence. mouse_left_click = close_current mouse_middle_click = do_action, close_current mouse_right_click = close_all # Experimental features that may or may not work correctly. Do not expect them # to have a consistent behaviour across releases. [experimental] # Calculate the dpi to use on a per-monitor basis. # If this setting is enabled the Xft.dpi value will be ignored and instead # dunst will attempt to calculate an appropriate dpi value for each monitor # using the resolution and physical size. This might be useful in setups # where there are multiple screens with very different dpi values. per_monitor_dpi = false [shortcuts] # Shortcuts are specified as [modifier+][modifier+]...key # Available modifiers are "ctrl", "mod1" (the alt-key), "mod2", # "mod3" and "mod4" (windows-key). # Xev might be helpful to find names for keys. # Close notification. close = ctrl+space # Close all notifications. close_all = ctrl+shift+space # Redisplay last message(s). # On the US keyboard layout "grave" is normally above TAB and left # of "1". Make sure this key actually exists on your keyboard layout, # e.g. check output of 'xmodmap -pke' history = ctrl+grave # Context menu. context = ctrl+shift+period [urgency_low] # IMPORTANT: colors have to be defined in quotation marks. # Otherwise the "#" and following would be interpreted as a comment. background = "#282a36" foreground = "#6272a4" timeout = 10 # Icon for notifications with low urgency, uncomment to enable #icon = /path/to/icon [urgency_normal] background = "#282a36" foreground = "#bd93f9" timeout = 10 # Icon for notifications with normal urgency, uncomment to enable [urgency_critical] background = "#ff5555" foreground = "#f8f8f2" timeout = 0 # Icon for notifications with critical urgency, uncomment to enable #icon = /path/to/icon [tidal-hifi] appname = tidal-hifi background = "#282a36" foreground = "#6272a4" urgency = low fullscreen = pushback ```

I have this files on my OS.

/usr/lib/systemd/user/dunst.service
/usr/share/licenses/dunst
/usr/share/man/man5/dunst.5.gz
/usr/share/man/man1/dunst.1.gz
/usr/share/man/man1/dunstctl.1.gz
/usr/share/dbus-1/services/org.knopwob.dunst.service
/usr/bin/dunst
/usr/bin/dunstctl
/usr/bin/dunstify
/var/cache/pacman/pkg/dunst-1.6.1-2-x86_64.pkg.tar.zst.sig
/var/cache/pacman/pkg/dunst-1.6.1-2-x86_64.pkg.tar.zst
/var/lib/pacman/local/dunst-1.6.1-2
/home/myuser/dunst_issue
/home/myuser/.config/dunst
/home/myuser/.config/dunst/dunstrc
/home/myuser/.config/systemd/user/dunst.service
/etc/dunst
/etc/dunst/dunstrc

And

/usr/share/dbus-1/services/org.knopwob.dunst.service:

[root@Tesla ~]# cat /usr/share/dbus-1/services/org.knopwob.dunst.service
[D-BUS Service]
Name=org.freedesktop.Notifications
Exec=/usr/bin/dunst
SystemdService=dunst.service

/usr/lib/systemd/user/dunst.service:

[root@Tesla ~]# cat /usr/lib/systemd/user/dunst.service
[Unit]
Description=Dunst notification daemon
Documentation=man:dunst(1)
PartOf=graphical-session.target

[Service]
Type=dbus
BusName=org.freedesktop.Notifications
ExecStart=/usr/bin/dunst

At system start:

systemctl --user status dunst.service                                                                                                                        ✔ 
○ dunst.service - Dunst notification daemon
     Loaded: loaded (/usr/lib/systemd/user/dunst.service; static)
     Active: inactive (dead)
       Docs: man:dunst(1)
journalctl --unit=dunst.service -n 200 --no-pager                                                                                                            ✔ 
Jan 29 10:14:02 Tesla systemd[1]: Starting Dunst notification daemon...
Jan 29 10:14:02 Tesla dunst[3900]: CRITICAL: Cannot open X11 display.
Jan 29 10:14:02 Tesla systemd[1]: dunst.service: Main process exited, code=exited, status=1/FAILURE
Jan 29 10:14:02 Tesla systemd[1]: dunst.service: Failed with result 'exit-code'.
Jan 29 10:14:02 Tesla systemd[1]: Failed to start Dunst notification daemon.
Jan 29 10:14:42 Tesla systemd[1]: Starting Dunst notification daemon...
Jan 29 10:14:42 Tesla dunst[3909]: CRITICAL: Cannot open X11 display.
Jan 29 10:14:42 Tesla systemd[1]: dunst.service: Main process exited, code=exited, status=1/FAILURE
Jan 29 10:14:42 Tesla systemd[1]: dunst.service: Failed with result 'exit-code'.
Jan 29 10:14:42 Tesla systemd[1]: Failed to start Dunst notification daemon.
Jan 29 10:15:10 Tesla systemd[1]: Starting Dunst notification daemon...
Jan 29 10:15:10 Tesla dunst[3948]: CRITICAL: Cannot open X11 display.
Jan 29 10:15:10 Tesla systemd[1]: dunst.service: Main process exited, code=exited, status=1/FAILURE
Jan 29 10:15:10 Tesla systemd[1]: dunst.service: Failed with result 'exit-code'.
Jan 29 10:15:10 Tesla systemd[1]: Failed to start Dunst notification daemon.

For now I'm starting dunst from mi I3 config file, but I prefer this to work in a clean way with systemd as it used to do, what can I do in order to know what is happening here ?. Thanks in advance!.

snprajwal commented 2 years ago

I don't think you should be starting dunst in any way, it is automatically started by DBus upon a notification event

madipietro commented 2 years ago

I don't think you should be starting dunst in any way, it is automatically started by DBus upon a notification event

Thanks!, yeah I'm trying to figure it out, why it isn't starting automatically, what else can I try ?

snprajwal commented 2 years ago

You need to set your DISPLAY env var for dunst to be started by DBus. You have to set it manually because systemd does not inherit environment variables. Add these two lines to your i3 config

exec --no-startup-id systemctl --user import-environment DISPLAY XAUTHORITY
exec --no-startup-id dbus-update-activation-environment DISPLAY XAUTHORITY
madipietro commented 2 years ago

You need to set your DISPLAY env var for dunst to be started by DBus. You have to set it manually because systemd does not inherit environment variables. Add these two lines to your i3 config

exec --no-startup-id systemctl --user import-environment DISPLAY XAUTHORITY
exec --no-startup-id dbus-update-activation-environment DISPLAY XAUTHORITY

Thanks @snprajwal, the thing is I don't have that lines on my I3 config, and it was working it is really weird, also I noticed that the script /etc/X11/xinit/xinitrc.d/50-systemd-user.sh is doing that I think.

#!/bin/sh
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

systemctl --user import-environment DISPLAY XAUTHORITY

if command -v dbus-update-activation-environment >/dev/null 2>&1; then
    dbus-update-activation-environment DISPLAY XAUTHORITY
fi

Is this correct ?

snprajwal commented 2 years ago

As far as I know, Xorg does not source /etc/X11/xinit if it is started with startx. Using xinit has it's own weird behaviour (X11 is pretty damn broken, to be honest). For that reason, you need to manually run these commands, either in your .profile/.zprofile (depending on your shell) or in your i3 config file. I prefer doing it in the config because it keeps things cleaner.

Narrat commented 2 years ago

startx sources at least$HOME/.xinitrc. And in this file one could also place the lines regarding calling the stuff in /etc/X11/xinit/xinitrc.d/. Which should also do the trick if startx is used. Though that doesn't explain why it fails now for some reason. Some information can be found in the wiki

snprajwal commented 2 years ago

@Narrat

Though that doesn't explain why it fails now for some reason.

Jan 29 10:14:02 Tesla dunst[3900]: CRITICAL: Cannot open X11 display.

I think this line in the logs means that $DISPLAY is not set, causing it to fail

Narrat commented 2 years ago

That's right. But my sentence was more directed on the report, that it previously worked and now is failing. :) But it isn't a new behaviour of dunst to rely on the set DISPLAY var. So either @madipietro replaced some tool (like display manager), rewrote some config or magic was at work :D That's the point that left me wondering.

madipietro commented 2 years ago

As far as I know, Xorg does not source /etc/X11/xinit if it is started with startx. Using xinit has it's own weird behaviour (X11 is pretty damn broken, to be honest). For that reason, you need to manually run these commands, either in your .profile/.zprofile (depending on your shell) or in your i3 config file. I prefer doing it in the config because it keeps things cleaner.

startx sources at least$HOME/.xinitrc. And in this file one could also place the lines regarding calling the stuff in /etc/X11/xinit/xinitrc.d/. Which should also do the trick if startx is used. Though that doesn't explain why it fails now for some reason. Some information can be found in the wiki

I'm starting I3 using SDDM, not startX :(

That's right. But my sentence was more directed on the report, that it previously worked and now is failing. :) But it isn't a new behaviour of dunst to rely on the set DISPLAY var. So either @madipietro replaced some tool (like display manager), rewrote some config or magic was at work :D That's the point that left me wondering.

Yeah! that's why I'm looking for some help to see what can I debug in order to make this work again.

Narrat commented 2 years ago

Sadly, I don't know much about SDDM. Can you somewhat pinpoint the time when it stopped working? The pacman.log may then help to narrow down the selection of updated packages which may have caused this. (Hopefully you update rather frequently :D) Or did you tweak some configs? The script /etc/X11/xinit/xinitrc.d/50-systemd-user.sh does what you think, but it needs to be sourced/executed by something. Or implemented otherwise. But dunno what SDDM does in that regard.

Nevertheless, the option mentioned by @snprajwal to add the respective lines to your i3 config should make it work again if it cannot be deduced what happened.

madipietro commented 2 years ago

Sadly, I don't know much about SDDM. Can you somewhat pinpoint the time when it stopped working? The pacman.log may then help to narrow down the selection of updated packages which may have caused this. (Hopefully you update rather frequently :D) Or did you tweak some configs? The script /etc/X11/xinit/xinitrc.d/50-systemd-user.sh does what you think, but it needs to be sourced/executed by something. Or implemented otherwise. But dunno what SDDM does in that regard.

Nevertheless, the option mentioned by @snprajwal to add the respective lines to your i3 config should make it work again if it cannot be deduced what happened.

Thanks @Narrat I tried that but still doesn´t work ( so weird )

On my .config/i3/config

exec --no-startup-id systemctl --user import-environment DISPLAY XAUTHORITY
exec --no-startup-id dbus-update-activation-environment DISPLAY XAUTHORITY

Only way to make it work for now on my I3 config.

exec_always --no-startup-id "/usr/bin/dunst"

or

exec_always --no-startup-id "/usr/bin/systemctl --user restart dunst.service"

I think I will leave it on the I3 config for now, because it works.

fwsmit commented 2 years ago

I think what's happening here is that dunst is started too early. I don't know how graphical-session.target is started for you, but it should only be started after you X session has started.

exec --no-startup-id systemctl --user import-environment DISPLAY XAUTHORITY
exec --no-startup-id dbus-update-activation-environment DISPLAY XAUTHORITY

I don't think you need this. As said earlier, it's already configured in another place.

exec_always --no-startup-id "/usr/bin/dunst"

This is the easiest solution. I would change exec_always into exec, though, since you cannot start a second dunst instance when one is already running. Alternatively, you can leave this line out of your config and dunst should be auto-started on the first notification.

I'll close this issue, as it seems that it works for you now.

madipietro commented 2 years ago

I think what's happening here is that dunst is started too early. I don't know how graphical-session.target is started for you, but it should only be started after you X session has started.

exec --no-startup-id systemctl --user import-environment DISPLAY XAUTHORITY
exec --no-startup-id dbus-update-activation-environment DISPLAY XAUTHORITY

I don't think you need this. As said earlier, it's already configured in another place.

exec_always --no-startup-id "/usr/bin/dunst"

This is the easiest solution. I would change exec_always into exec, though, since you cannot start a second dunst instance when one is already running. Alternatively, you can leave this line out of your config and dunst should be auto-started on the first notification.

I'll close this issue, as it seems that it works for you now.

HI @fwsmit I have a simple setup using sddm for starting I3 if I list my units I have this

systemctl list-units --type=target                                                                                                                           ✔ 
  UNIT                  LOAD   ACTIVE SUB    DESCRIPTION                       
  basic.target          loaded active active Basic System
  cryptsetup.target     loaded active active Local Encrypted Volumes
  getty.target          loaded active active Login Prompts
  graphical.target      loaded active active Graphical Interface
  integritysetup.target loaded active active Local Integrity Protected Volumes
  local-fs-pre.target   loaded active active Preparation for Local File Systems
  local-fs.target       loaded active active Local File Systems
  multi-user.target     loaded active active Multi-User System
  network.target        loaded active active Network
  paths.target          loaded active active Path Units
  remote-fs.target      loaded active active Remote File Systems
  slices.target         loaded active active Slice Units
  sockets.target        loaded active active Socket Units
  sound.target          loaded active active Sound Card
  swap.target           loaded active active Swaps
  sysinit.target        loaded active active System Initialization
  timers.target         loaded active active Timer Units
  veritysetup.target    loaded active active Local Verity Protected Volumes

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
18 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

I think what you said here make sense, but then I suppose that the dunst unit, need to have a dependence of the graphical target, Am I right ?

I'm using this for starting dunst on my I3 config file.

exec_always --no-startup-id "/usr/bin/systemctl --user restart dunst.service"

Maybe I can try to fix the systemd unit and to do a PR ?

Thanks!.

fwsmit commented 2 years ago

I think what you said here make sense, but then I suppose that the dunst unit, need to have a dependence of the graphical target, Am I right ?

No, graphical.target is started too early. I think if you want the systemd unit to work, you'll need to set up a graphical-session.target unit yourself and make sure it gets started after i3 has started. I'm not sure about the details, though, since I just let dunst be auto started upon a notification (this should work by default, unless you have another notification daemon installed, in which case dbus might start any of them).

I think the systemd unit is correct, no changes needed. The way I would recommend to start dunst is to just disable autostarting of the dunst service and let it be started by dbus upon the first notification. If for some reason you want to have multiple notification daemons installed, I would recommend putting exec dunst in your i3 config.

I guess that exec_always --no-startup-id "/usr/bin/systemctl --user restart dunst.service" would be nice if you want to reload the dunst config upon reloading the i3 config.

madipietro commented 2 years ago

I think what you said here make sense, but then I suppose that the dunst unit, need to have a dependence of the graphical target, Am I right ?

No, graphical.target is started too early. I think if you want the systemd unit to work, you'll need to set up a graphical-session.target unit yourself and make sure it gets started after i3 has started. I'm not sure about the details, though, since I just let dunst be auto started upon a notification (this should work by default, unless you have another notification daemon installed, in which case dbus might start any of them).

I think the systemd unit is correct, no changes needed. The way I would recommend to start dunst is to just disable autostarting of the dunst service and let it be started by dbus upon the first notification. If for some reason you want to have multiple notification daemons installed, I would recommend putting exec dunst in your i3 config.

I guess that exec_always --no-startup-id "/usr/bin/systemctl --user restart dunst.service" would be nice if you want to reload the dunst config upon reloading the i3 config.

I just have dunst, I have installed KDE but I'm not using it since I'm using I3 since a lot of time with dunst I don't have enabled the dunst.service since it's not needed I think

  ~ ❯ systemctl status dunst.service                                                                                                                           INT ↵ 
Unit dunst.service could not be found.

  ~ ❯ systemctl status --user dunst.service                                                                                                                      4 ↵ 
○ dunst.service - Dunst notification daemon
     Loaded: loaded (/usr/lib/systemd/user/dunst.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:dunst(1)

That's the state of the unit by default when my system starts.

And the logs are telling this

Feb 16 12:45:59 Tesla systemd[673]: Started Dunst notification daemon.
Feb 16 12:46:09 Tesla dunst[2234]: X connection to :0 broken (explicit kill or server shutdown).
Feb 16 12:46:09 Tesla systemd[673]: dunst.service: Main process exited, code=exited, status=1/FAILURE

I think that is not related to another notification daemon it's really weird. But of course using exec_always --no-startup-id "/usr/bin/systemctl --user restart dunst.service" on mi I3 config, dunst will work at the start of mi I3 and the unit will be on running state. Could be something else to debug ?