每次具有 SMART 功能的特定设备插入 USB 端口时,我都会在systemd
.conf文件中使用以下内容来运行图形对话框。zenity
这在使用显示服务器的 Xubuntu 中工作正常,但在WaylandX
服务器中对话框显示zenity
失败。
USER=myName
DISPLAY=:0.0
WAYLAND_DISPLAY=wayland-0
XAUTHORITY=/home/myName/.Xauthority
HOME=/home/myName
SHELL=/bin/bash
我尝试在 Ubuntu 23.10 中添加WAYLAND_DISPLAY=wayland-0
Wayland服务器的.confzenity
文件,但对话仍然无法显示。我还需要做什么?
我的setup-01的文件列表:
/bin/hdd_smart_dump_on_usb_trigger.sh
/etc/00_hdd_smart_dump_on_usb_trigger.conf
/etc/systemd/system/[email protected]
/etc/systemd/system/[email protected]/disable_manual_start.conf
/etc/systemd/system/[email protected]
/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh
/etc/udev/rules.d/99-hdd-smart-dump-on-usb-trigger.udev.rules
内容/etc/00_hdd_smart_dump_on_usb_trigger.conf
:
USER=myName
DISPLAY=:0.0
WAYLAND_DISPLAY=wayland-0
XAUTHORITY=/home/ajthapa/.Xauthority
HOME=/home/myName
SHELL=/bin/bash
内容:/etc/systemd/system/[email protected]
[Unit]
Description=HDD SMART Dump on USB Trigger - service unit for %I
Documentation=man:systemd.unit(5) man:systemd.exec(5) man:systemd.special(7) man:systemd.target(5)
ConditionPathExistsGlob=/sys/class/block/sd*
# RefuseManualStart=true
# RefuseManualStop=true
[Service]
EnvironmentFile=/etc/00_hdd_smart_dump_on_usb_trigger.conf
ExecStart=-/bin/bash -c '/bin/hdd_smart_dump_on_usb_trigger.sh -d %i -t "start_of_session"'
内容:/etc/systemd/system/[email protected]/disable_manual_start.conf
[Unit]
## Allow only to be started/stopped by device events; if manual start is needed
## you should instead call the script which this service calls.
RefuseManualStart=true
RefuseManualStop=true
内容:/etc/systemd/system/[email protected]
[Unit]
Description=HDD SMART Dump on USB Trigger - target unit for %I
Documentation=man:systemd.unit(5) man:systemd.target(5) man:systemd.special(7)
StopWhenUnneeded=yes
Requires=hdd_smart_dump_on_usb_trigger@%i.service
Before=hdd_smart_dump_on_usb_trigger@%i.service
BindsTo=%i.device
RefuseManualStart=true
RefuseManualStop=true
内容/etc/udev/rules.d/99-hdd-smart-dump-on-usb-trigger.udev.rules
:
SUBSYSTEM!="block", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
KERNEL!="sd*", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
ENV{DEVTYPE}!="disk", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
## Rules to match specific devices; start:
ATTRS{idProduct}=="2312", ATTRS{idVendor}=="0bc2", GOTO="label__enlisted_devices"
ATTRS{idProduct}=="5590", ATTRS{idVendor}=="0781", GOTO="label__enlisted_devices"
ATTRS{idProduct}!="2312|5590", ATTRS{idVendor}!="0bc2|0781", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
## Rules to match specific devices; end.
LABEL="label__enlisted_devices"
ACTION=="remove", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_for_action_remove"
ACTION!="add", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*", ENV{DEVTYPE}=="disk", ATTRS{idProduct}=="2312", ATTRS{idVendor}=="0bc2", TAG+="systemd", ENV{SYSTEMD_WANTS}+="hdd_smart_dump_on_usb_trigger@dev-%k.target", RUN+="/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh ==01== UDEV_ACTION==ADD #### ENVIRONMENT::::[[ DEVNAME=$env{DEVNAME} | DEVPATH=$env{DEVPATH} | ID_MODEL=$env{ID_MODEL} | ID_SERIAL=$env{ID_SERIAL} | ID_SERIAL_SHORT=$env{ID_SERIAL_SHORT} | ID_VENDOR=$env{ID_VENDOR} | TAGS=$env{TAGS} | ID_ATA=$env{ID_ATA} | ID_ATA_FEATURE_SET_SMART=$env{ID_ATA_FEATURE_SET_SMART} | ID_ATA_FEATURE_SET_SMART_ENABLED=$env{ID_ATA_FEATURE_SET_SMART_ENABLED} | ID_ATA_SATA=$env{ID_ATA_SATA} | ID_ATA_WRITE_CACHE=$env{ID_ATA_WRITE_CACHE} | ID_ATA_WRITE_CACHE_ENABLED=$env{ID_ATA_WRITE_CACHE_ENABLED} | ID_VENDOR_ID=$env{ID_VENDOR_ID} | ID_MODEL_ID=$env{ID_MODEL_ID} | ]] #### ATTRIBUTE::::[[ size=$attr{size} | KERNEL=%k | idProduct=$attr{idProduct} | idVendor=$attr{idVendor} | manufacturer=$attr{manufacturer} | product=$attr{product} | removable=$attr{removable} | bMaxPower=$attr{bMaxPower} | ]]", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*", ENV{DEVTYPE}=="disk", ATTRS{idProduct}=="5590", ATTRS{idVendor}=="0781", TAG+="systemd", ENV{SYSTEMD_WANTS}+="hdd_smart_dump_on_usb_trigger@dev-%k.target", RUN+="/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh ==01== UDEV_ACTION==ADD #### ENVIRONMENT::::[[ DEVNAME=$env{DEVNAME} | DEVPATH=$env{DEVPATH} | ID_MODEL=$env{ID_MODEL} | ID_SERIAL=$env{ID_SERIAL} | ID_SERIAL_SHORT=$env{ID_SERIAL_SHORT} | ID_VENDOR=$env{ID_VENDOR} | TAGS=$env{TAGS} | ID_ATA=$env{ID_ATA} | ID_ATA_FEATURE_SET_SMART=$env{ID_ATA_FEATURE_SET_SMART} | ID_ATA_FEATURE_SET_SMART_ENABLED=$env{ID_ATA_FEATURE_SET_SMART_ENABLED} | ID_ATA_SATA=$env{ID_ATA_SATA} | ID_ATA_WRITE_CACHE=$env{ID_ATA_WRITE_CACHE} | ID_ATA_WRITE_CACHE_ENABLED=$env{ID_ATA_WRITE_CACHE_ENABLED} | ID_VENDOR_ID=$env{ID_VENDOR_ID} | ID_MODEL_ID=$env{ID_MODEL_ID} | ]] #### ATTRIBUTE::::[[ size=$attr{size} | KERNEL=%k | idProduct=$attr{idProduct} | idVendor=$attr{idVendor} | manufacturer=$attr{manufacturer} | product=$attr{product} | removable=$attr{removable} | bMaxPower=$attr{bMaxPower} | ]]", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
LABEL="label__hdd_smart_dump_on_usb_trigger_rules_for_action_remove"
ACTION=="remove", SUBSYSTEM=="block", KERNEL=="sd*", ENV{DEVTYPE}=="disk", RUN+="/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh ==02== UDEV_ACTION==REMOVE #### ENVIRONMENT::::[[ DEVNAME=$env{DEVNAME} | ID_MODEL=$env{ID_MODEL} | ID_SERIAL=$env{ID_SERIAL} | ID_SERIAL_SHORT=$env{ID_SERIAL_SHORT} | ID_VENDOR=$env{ID_VENDOR} | TAGS=$env{TAGS} | ID_ATA=$env{ID_ATA} | ID_ATA_FEATURE_SET_SMART=$env{ID_ATA_FEATURE_SET_SMART} | ID_ATA_FEATURE_SET_SMART_ENABLED=$env{ID_ATA_FEATURE_SET_SMART_ENABLED} | ID_ATA_SATA=$env{ID_ATA_SATA} | ID_ATA_WRITE_CACHE=$env{ID_ATA_WRITE_CACHE} | ID_ATA_WRITE_CACHE_ENABLED=$env{ID_ATA_WRITE_CACHE_ENABLED} | ID_VENDOR_ID=$env{ID_VENDOR_ID} | ID_MODEL_ID=$env{ID_MODEL_ID} ]] #### ATTRIBUTE::::[[ size=$attr{size} | KERNEL=$kernel | idProduct=$attr{idProduct} | idVendor=$attr{idVendor} | manufacturer=$attr{manufacturer} | product=$attr{product} | model=$attr{model} | removable=$attr{removable} ]]"
LABEL="label__hdd_smart_dump_on_usb_trigger_rules_end"
包含/etc/udev/rules.d/99-hdd-smart-dump-on-usb-trigger.udev.rules
匹配特定设备集的规则,它在这些设备上执行,/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh
然后将一些属性写入/var/run/
目录中的文件。规则文件还会触发 systemd 单元文件,然后执行/bin/hdd_smart_dump_on_usb_trigger.sh
. 该脚本使用 zenity 允许用户将输出保存smartmontools
到选定的位置。
更新:
设置-02:
文件列表:
-rw-r--r-- 1 root root 3018 Feb 19 12:25 /etc/00_hdd_smart_dump_on_usb_trigger.conf
-rw-r--r-- 1 root root 2013 Feb 19 12:15 /etc/systemd/system/[email protected]
-rw-r--r-- 1 root root 196 Aug 8 2020 /etc/systemd/system/[email protected]/disable_manual_start.conf
-rw-r--r-- 1 root root 573 Feb 19 07:42 /etc/systemd/system/[email protected]
-rwxr-xr-x 1 root root 7562 Sep 5 2020 /etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh
-rw-r--r-- 1 root root 7710 Feb 19 13:29 /etc/udev/rules.d/99-hdd-smart-dump-on-usb-trigger.udev.rules
-rwxr-xr-x 1 root root 5032 Feb 19 13:18 /opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_display_with_zenity.sh
-rwxr-xr-x 1 root root 34594 Feb 19 11:58 /opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_on_usb_trigger.sh
-rw-r--r-- 1 myName myName 502 Feb 19 13:30 /home/myName/.config/systemd/user/[email protected]
通过此设置,udev 写入属性,然后由我的 systemd 系统单元读取,但我的 systemd 用户单元无法启动并在 zenity 对话中显示转储。我可以在 my 中使用相同的命令通过 SMART 转储启动 zenity。因此,问题可能出在我的 udev .rules 文件和/或我的 systemd 用户单元文件和/或其命名中。/home/myName/.config/systemd/user/[email protected]
内容:/home/myName/.config/systemd/user/[email protected]
[Unit]
Description=HDD SMART Dump Display Using Zenity Dialogue
Documentation=man:systemd.unit(5) man:systemd.exec(5) man:systemd.special(7) man:systemd.target(5)
Requires=hdd_smart_dump_on_usb_trigger@%i.service
After=hdd_smart_dump_on_usb_trigger@%i.service
ConditionPathExistsGlob=/sys/class/block/sd*
# RefuseManualStart=true
# RefuseManualStop=true
[Service]
Type=oneshot
ExecStart=-/bin/bash -c '/opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_display_with_zenity.sh --display-dialogue'
内容/etc/udev/rules.d/99-hdd-smart-dump-on-usb-trigger.udev.rules
:
SUBSYSTEM!="block", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
KERNEL!="sd*", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
ENV{DEVTYPE}!="disk", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
ATTRS{idProduct}=="2312", ATTRS{idVendor}=="0bc2", GOTO="label__enlisted_devices"
ATTRS{idProduct}=="5590", ATTRS{idVendor}=="0781", GOTO="label__enlisted_devices"
ATTRS{idProduct}!="2312|5590", ATTRS{idVendor}!="0bc2|0781", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
LABEL="label__enlisted_devices"
ACTION=="remove", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_for_action_remove"
ACTION!="add", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*", ENV{DEVTYPE}=="disk", ATTRS{idProduct}=="2312", ATTRS{idVendor}=="0bc2", TAG+="systemd", ENV{SYSTEMD_WANTS}+="hdd_smart_dump_on_usb_trigger@dev-%k.target", ENV{SYSTEMD_USER_WANTS}+="hdd_smart_dump_display_using_zenity@dev-%k.system", RUN+="/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh ==01== UDEV_ACTION==ADD #### ENVIRONMENT::::[[ DEVNAME=$env{DEVNAME} | DEVPATH=$env{DEVPATH} | ID_MODEL=$env{ID_MODEL} | ID_SERIAL=$env{ID_SERIAL} | ID_SERIAL_SHORT=$env{ID_SERIAL_SHORT} | ID_VENDOR=$env{ID_VENDOR} | TAGS=$env{TAGS} | ID_ATA=$env{ID_ATA} | ID_ATA_FEATURE_SET_SMART=$env{ID_ATA_FEATURE_SET_SMART} | ID_ATA_FEATURE_SET_SMART_ENABLED=$env{ID_ATA_FEATURE_SET_SMART_ENABLED} | ID_ATA_SATA=$env{ID_ATA_SATA} | ID_ATA_WRITE_CACHE=$env{ID_ATA_WRITE_CACHE} | ID_ATA_WRITE_CACHE_ENABLED=$env{ID_ATA_WRITE_CACHE_ENABLED} | ID_VENDOR_ID=$env{ID_VENDOR_ID} | ID_MODEL_ID=$env{ID_MODEL_ID} | ]] #### ATTRIBUTE::::[[ size=$attr{size} | KERNEL=%k | idProduct=$attr{idProduct} | idVendor=$attr{idVendor} | manufacturer=$attr{manufacturer} | product=$attr{product} | removable=$attr{removable} | bMaxPower=$attr{bMaxPower} | ]]", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*", ENV{DEVTYPE}=="disk", ATTRS{idProduct}=="5590", ATTRS{idVendor}=="0781", TAG+="systemd", ENV{SYSTEMD_WANTS}+="hdd_smart_dump_on_usb_trigger@dev-%k.target", ENV{SYSTEMD_USER_WANTS}+="hdd_smart_dump_display_using_zenity@dev-%k.system", RUN+="/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh ==01== UDEV_ACTION==ADD #### ENVIRONMENT::::[[ DEVNAME=$env{DEVNAME} | DEVPATH=$env{DEVPATH} | ID_MODEL=$env{ID_MODEL} | ID_SERIAL=$env{ID_SERIAL} | ID_SERIAL_SHORT=$env{ID_SERIAL_SHORT} | ID_VENDOR=$env{ID_VENDOR} | TAGS=$env{TAGS} | ID_ATA=$env{ID_ATA} | ID_ATA_FEATURE_SET_SMART=$env{ID_ATA_FEATURE_SET_SMART} | ID_ATA_FEATURE_SET_SMART_ENABLED=$env{ID_ATA_FEATURE_SET_SMART_ENABLED} | ID_ATA_SATA=$env{ID_ATA_SATA} | ID_ATA_WRITE_CACHE=$env{ID_ATA_WRITE_CACHE} | ID_ATA_WRITE_CACHE_ENABLED=$env{ID_ATA_WRITE_CACHE_ENABLED} | ID_VENDOR_ID=$env{ID_VENDOR_ID} | ID_MODEL_ID=$env{ID_MODEL_ID} | ]] #### ATTRIBUTE::::[[ size=$attr{size} | KERNEL=%k | idProduct=$attr{idProduct} | idVendor=$attr{idVendor} | manufacturer=$attr{manufacturer} | product=$attr{product} | removable=$attr{removable} | bMaxPower=$attr{bMaxPower} | ]]", GOTO="label__hdd_smart_dump_on_usb_trigger_rules_end"
LABEL="label__hdd_smart_dump_on_usb_trigger_rules_for_action_remove"
ACTION=="remove", SUBSYSTEM=="block", KERNEL=="sd*", ENV{DEVTYPE}=="disk", RUN+="/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh ==02== UDEV_ACTION==REMOVE #### ENVIRONMENT::::[[ DEVNAME=$env{DEVNAME} | ID_MODEL=$env{ID_MODEL} | ID_SERIAL=$env{ID_SERIAL} | ID_SERIAL_SHORT=$env{ID_SERIAL_SHORT} | ID_VENDOR=$env{ID_VENDOR} | TAGS=$env{TAGS} | ID_ATA=$env{ID_ATA} | ID_ATA_FEATURE_SET_SMART=$env{ID_ATA_FEATURE_SET_SMART} | ID_ATA_FEATURE_SET_SMART_ENABLED=$env{ID_ATA_FEATURE_SET_SMART_ENABLED} | ID_ATA_SATA=$env{ID_ATA_SATA} | ID_ATA_WRITE_CACHE=$env{ID_ATA_WRITE_CACHE} | ID_ATA_WRITE_CACHE_ENABLED=$env{ID_ATA_WRITE_CACHE_ENABLED} | ID_VENDOR_ID=$env{ID_VENDOR_ID} | ID_MODEL_ID=$env{ID_MODEL_ID} ]] #### ATTRIBUTE::::[[ size=$attr{size} | KERNEL=$kernel | idProduct=$attr{idProduct} | idVendor=$attr{idVendor} | manufacturer=$attr{manufacturer} | product=$attr{product} | model=$attr{model} | removable=$attr{removable} ]]"
LABEL="label__hdd_smart_dump_on_usb_trigger_rules_end"
sudo systemctl --no-pager -l status 'hdd_smart_dump_on_usb_trigger*'
插入USB设备的输出:
● [email protected] - HDD SMART Dump on USB Trigger - target unit for dev/sdb
Loaded: loaded (/etc/systemd/system/[email protected]; static)
Active: active since Mon 2024-02-19 14:17:50 +0545; 2min 24s ago
Docs: man:systemd.unit(5)
man:systemd.target(5)
man:systemd.special(7)
Feb 19 14:17:50 ajthapa-vcomputer systemd[1]: Reached target [email protected] - HDD SMART Dump on USB Trigger - target unit for dev/sdb.
没有 的输出systemctl --user --no-pager -l status 'hdd_*'
。
设置-03:
文件:
/etc/00_hdd_smart_dump_on_usb_trigger.conf
/etc/systemd/system/[email protected]
/etc/systemd/system/[email protected]/disable_manual_start.conf
/etc/systemd/system/[email protected]
/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh
/etc/udev/rules.d/99-hdd-smart-dump-on-usb-trigger.udev.rules
/opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_display_with_zenity.sh
/opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_on_usb_trigger.sh
/home/ajthapa/.config/systemd/user/hdd_smart_dump_display_using_zenity.service
内容/home/ajthapa/.config/systemd/user/hdd_smart_dump_display_using_zenity.service
:
[Unit]
Description=HDD SMART Dump Display Using Zenity Dialogue
Documentation=man:systemd.unit(5) man:systemd.exec(5) man:systemd.special(7) man:systemd.target(5)
StopWhenUnneeded=yes
After=hdd_smart_dump_on_usb_trigger@%i.service
#BindsTo=%i.device
RefuseManualStart=true
RefuseManualStop=true
[Service]
Type=oneshot
ExecStart=-/bin/bash -c '/opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_display_with_zenity.sh --display-dialogue'
[Install]
WantedBy=hdd_smart_dump_on_usb_trigger@%i.service
命令的输出systemctl --user enable hdd_smart_dump_display_using_zenity.service
:
Created symlink /home/ajthapa/.config/systemd/user/[email protected]/hdd_smart_dump_display_using_zenity.service → /home/ajthapa/.config/systemd/user/hdd_smart_dump_display_using_zenity.service.
Unit /home/ajthapa/.config/systemd/user/hdd_smart_dump_display_using_zenity.service is added as a dependency to a non-existent unit [email protected].
“...依赖项添加到不存在的单元...”阻止在用户单元中启动编码脚本。
在 setup-03 中,udev .rules 文件仅触发 systemd 文件的系统单元。
设置-04:
文件列表:
/etc/00_hdd_smart_dump_on_usb_trigger.conf
/etc/systemd/system/[email protected]
/etc/systemd/system/[email protected]/disable_manual_start.conf
/etc/systemd/system/[email protected]
/etc/udev/00_hdd_smart_dump_on_usb_trigger.udev.sh
/etc/udev/rules.d/99-hdd-smart-dump-on-usb-trigger.udev.rules
/opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_display_with_zenity.sh
/opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_on_usb_trigger.sh
/home/ajthapa/.config/systemd/user/[email protected]
/home/ajthapa/.config/systemd/user/[email protected]
内容:/home/ajthapa/.config/systemd/user/[email protected]
[Unit]
Description=HDD SMART Dump Display Using Zenity Dialogue
Documentation=man:systemd.unit(5) man:systemd.exec(5) man:systemd.special(7) man:systemd.target(5)
ConditionPathExistsGlob=/sys/class/block/sd*
RefuseManualStart=true
RefuseManualStop=true
[Service]
Type=oneshot
ExecStart=-/bin/bash -c '/opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_display_with_zenity.sh --display-dialogue'
内容:/home/ajthapa/.config/systemd/user/[email protected]
[Unit]
Description=HDD SMART Dump Display Using Zenity Dialogue - target unit for %I
Documentation=man:systemd.unit(5) man:systemd.exec(5) man:systemd.special(7) man:systemd.target(5)
StopWhenUnneeded=yes
Requires=hdd_smart_dump_display_using_zenity@%i.service
Before=hdd_smart_dump_display_using_zenity@%i.service
RefuseManualStart=true
RefuseManualStop=true
system-unit .target 和 user-unit .target 由 udev 规则触发。通过这种 systemd 系统、用户单元和 udev 规则的配置,这些用户单元似乎在系统单元之前执行。例如,当第一次连接 USB 设备时,zenity 显示空白。当设备弹出并再次连接时,用户单元首先执行并读取由系统单元运行的脚本写入的先前值,因此显示(先前插入的设备的)过时值。
更新:在 setup-04 中,在用户单元 .service 文件中,我添加了大约 3-5 秒的延迟,并且设置按预期工作,但这不是我想要的方式,我希望通过以下方式完成单元文件中的 Systemd 设置。
ExecStart=-/bin/bash -c 'sleep 3s; /opt/hdd_smart_dump_on_usb_trigger/bin/hdd_smart_dump_display_with_zenity.sh --display-dialogue'
我在 .service 用户单元文件中使用。
知道我在这些设置中做错了什么吗?
这是一个从 Systemd 用户服务内部触发
zenity
对话框的演示,该对话框由插入(添加)USB 磁盘时触发的 UDEV 规则触发...此答案的目的是用作模板或样板,它是并不意味着作为您的用例的实际解决方案。创建用户服务单元文件:
通知 Systemd 守护进程:
启用它并启动它:
...这应该会触发
zenity
对话窗口,并且您应该已经看到它。创建 UDEV 规则:
...
SYSTEMD_USER_WANTS
用户服务与SYSTEMD_WANTS
系统服务的注意事项。重新启动 UDEV 服务以捕获新的规则文件:
测试一下:
插入 USB 磁盘,您应该会看到
zenity
对话窗口被触发...只要图形用户会话正在运行,这应该在任何显示服务器上同样触发...更多相关讨论请参见此处。