首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用通知时冻结-从systemd服务发送

使用通知时冻结-从systemd服务发送
EN

Ask Ubuntu用户
提问于 2019-12-13 03:59:59
回答 1查看 1.1K关注 0票数 1

我有以下Python脚本:

代码语言:javascript
复制
# /path/to/__main.py__

[..]

subprocess.call("DISPLAY=:0 dbus-launch /usr/bin/notify-send -i dialog-information \'foo\' \'bar\'", shell=True)

[..]

以及以下.service文件:

代码语言:javascript
复制
# /etc/systemd/system/notification.service

[Unit]
Description=Notification service

[Service]

# Run permission service
ExecStart=/usr/bin/python3 /path/to/__main__.py

# keep process after user logs off
RemainAfterExit=false

[Install]
WantedBy=default.target

当我在我的终端上打电话给/usr/bin/python3 /path/to/__main__.py时,弹出就会出现,没有冻结或其他任何东西。

然而,当我调用sudo systemctl restart notification.service时,系统(UI)冻结了20多个(在UI中不可能交互),然后弹出。

问题是:Why只在通过systemd服务调用脚本时才会出现此问题吗?

进一步的产出(可能有助于调查)

这是sudo systemctl status notification.service的输出:

代码语言:javascript
复制
user@host:~$ sudo systemctl status notification.service 
● notification.service - Notification service
   Loaded: loaded (/etc/systemd/system/notification.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-12-13 11:54:37 +08; 1h 41min ago
  Process: 18420 ExecStartPre=/bin/bash -c test $(/usr/bin/id -u) -eq 0 (code=exited, status=0/SUCCESS)
 Main PID: 18433 (python3)
    Tasks: 25 (limit: 4915)
   CGroup: /system.slicenotification.service
           ├─18433 /usr/bin/python3 /path/to/__main__.py
           ├─18583 /usr/bin/dbus-daemon --syslog --fork --print-pid 5 --print-address 7 --session
           ├─18588 /usr/lib/x86_64-linux-gnu/notify-osd
           ├─18715 /usr/lib/gvfs/gvfsd
           ├─18822 /usr/bin/dbus-daemon --syslog --fork --print-pid 5 --print-address 7 --session
           ├─18827 /usr/lib/x86_64-linux-gnu/notify-osd
           ├─18990 /usr/lib/gvfs/gvfsd
           ├─19055 /usr/bin/dbus-daemon --syslog --fork --print-pid 5 --print-address 7 --session
           ├─19059 /usr/lib/x86_64-linux-gnu/notify-osd
           └─19222 /usr/lib/gvfs/gvfsd

Dec 13 11:55:34 host notify-osd[18827]: dnd_is_screensaver_active(): Got error "The name org.gnome.ScreenSaver was not provided by any .service files"
Dec 13 11:55:34 host notify-osd[18827]: dnd_is_idle_inhibited(): got error "The name org.gnome.SessionManager was not provided by any .service files"
Dec 13 11:55:43 host dbus-daemon[19055]: [session uid=0 pid=19053] AppArmor D-Bus mediation is enabled
Dec 13 11:55:43 host dbus-daemon[19055]: [session uid=0 pid=19053] Activating service name='org.freedesktop.Notifications' requested by ':1.0' (uid=0 pid=19001 comm="/usr/bin/notify-send -i dialog-information UpdateR" label="unconfined")
Dec 13 11:56:01 host dbus-daemon[19055]: [session uid=0 pid=19053] Activating service name='org.gtk.vfs.Daemon' requested by ':1.1' (uid=0 pid=19059 comm="/usr/lib/x86_64-linux-gnu/notify-osd " label="unconfined")
Dec 13 11:56:01 host dbus-daemon[19055]: [session uid=0 pid=19053] Successfully activated service 'org.gtk.vfs.Daemon'
Dec 13 11:56:01 host org.gtk.vfs.Daemon[19055]: fuse: bad mount point `/root/.gvfs': Transport endpoint is not connected
Dec 13 11:56:01 host dbus-daemon[19055]: [session uid=0 pid=19053] Successfully activated service 'org.freedesktop.Notifications'
Dec 13 11:56:01 host notify-osd[19059]: dnd_is_screensaver_active(): Got error "The name org.gnome.ScreenSaver was not provided by any .service files"
Dec 13 11:56:01 host notify-osd[19059]: dnd_is_idle_inhibited(): got error "The name org.gnome.SessionManager was not provided by any .service files"
lines 1-28/28 (END)
EN

回答 1

Ask Ubuntu用户

发布于 2019-12-13 16:18:09

好的,下面是我在用root的crontab运行脚本时修复这个问题所做的事情。我还在学习python,所以您需要根据需要转换这些信息。

首先,我在我的.bashrc中添加了根的xhost权限:

代码语言:javascript
复制
xhost + SI:localuser:root > /dev/null

其次,我在root的crontab中添加了以下变量:

代码语言:javascript
复制
DISPLAY=":0.0"
XAUTHORITY="/home/me/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1000"
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

第三,我以我的身份运行了每个通知-发送,如下所示:

代码语言:javascript
复制
su me -c '/usr/bin/notify-send "Weekly backup started - $(date +%Y-%m-%d) @ $(date +%H:%M:%S)"'
票数 1
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1195803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档