我正在尝试将 chromium 作为服务运行,因为我需要 pulseaudio 正在运行。
服务文件是:
[Unit]
Description = Kiosk launcher as service
After = pulseaudio.service
Wants =
Requires =
[Service]
Type = simple
PIDFile = /var/run/kiosk.pid
ExecStart = /usr/bin/chromium --no-sandbox /var/www/Kiosk/trunk/indexLocker.php
Restart = on-abort
StartLimitInterval = 60
StartLimitBurst = 10
[Install]
WantedBy =
我运行systemctl start kiosk
但没有任何反应。
status 选项的输出为:
● kiosk.service - Kiosk launcher as service
Loaded: loaded (/etc/systemd/system/kiosk.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2022-07-21 17:38:37 CEST; 8s ago
Process: 9283 ExecStart=/usr/bin/chromium --no-sandbox /var/www/Kiosk/trunk/indexLocker.php (code=exited, sta
Main PID: 9283 (code=exited, status=1/FAILURE)
Jul 21 17:38:37 tinkerboard systemd[1]: kiosk.service: Failed with result 'exit-code'.
我写在这里只是为了更好地显示输出:
linaro@tinkerboard:~/.config/systemd/user$ ls -la
total 12
drwxr-xr-x 2 linaro linaro 4096 Jul 22 09:22 .
drwxr-xr-x 3 linaro linaro 4096 Jul 21 17:11 ..
-rw-r--r-- 1 linaro linaro 327 Jul 22 09:22 kiosk.service
linaro@tinkerboard:~/.config/systemd/user$
linaro@tinkerboard:~/.config/systemd/user$ systemctl --user start kiosk
Failed to start kiosk.service: Unit kiosk.service not found.
linaro@tinkerboard:~/.config/systemd/user$
linaro@tinkerboard:~/.config/systemd/user$ echo $HOME
/home/linaro
linaro@tinkerboard:~/.config/systemd/user$ whoami
linaro
linaro@tinkerboard:~/.config/systemd/user$
抱歉,但我看不到问题所在..
- - 添加 - -
linaro@tinkerboard:~/.config/systemd/user$ strace -e trace=file systemctl --user start kiosk > output
execve("/bin/systemctl", ["systemctl", "--user", "start", "kiosk"], [/* 39 vars */]) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/lib/systemd/tls/v7l/neon/vfp/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/v7l/neon/vfp", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/tls/v7l/neon/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/v7l/neon", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/tls/v7l/vfp/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/v7l/vfp", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/tls/v7l/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/v7l", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/tls/neon/vfp/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/neon/vfp", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/tls/neon/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/neon", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/tls/vfp/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/vfp", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/tls/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/v7l/neon/vfp/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/v7l/neon/vfp", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/v7l/neon/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/v7l/neon", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/v7l/vfp/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/v7l/vfp", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/v7l/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/v7l", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/neon/vfp/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/neon/vfp", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/neon/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/neon", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/vfp/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/vfp", 0xbed08cc0) = -1 ENOENT (No such file or directory)
open("/lib/systemd/libsystemd-shared-232.so", O_RDONLY|O_CLOEXEC) = 3
open("/lib/systemd/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
open("/lib/systemd/libpthread.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
open("/lib/systemd/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libcap.so.2", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/liblzma.so.5", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/arm-linux-gnueabihf/liblz4.so.1", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libgcrypt.so.20", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libacl.so.1", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libidn.so.11", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libseccomp.so.2", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libpcre.so.3", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libgpg-error.so.0", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libattr.so.1", O_RDONLY|O_CLOEXEC) = 3
statfs("/sys/fs/selinux", 0xbed0a2a4) = -1 ENOENT (No such file or directory)
statfs("/selinux", 0xbed0a2a4) = -1 ENOENT (No such file or directory)
open("/proc/filesystems", O_RDONLY) = 3
access("/etc/selinux/config", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_IDENTIFICATION", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/arm-linux-gnueabihf/gconv/gconv-modules.cache", O_RDONLY) = 3
open("/usr/lib/locale/C.UTF-8/LC_MEASUREMENT", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_TELEPHONE", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_ADDRESS", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_NAME", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_PAPER", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_MESSAGES", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_MESSAGES/SYS_LC_MESSAGES", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_MONETARY", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_COLLATE", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_TIME", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_NUMERIC", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/C.UTF-8/LC_CTYPE", O_RDONLY|O_CLOEXEC) = 3
open("/proc/self/stat", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
stat64("/proc/1/root", 0xbed0a108) = -1 EACCES (Permission denied)
open("/sys/fs/kdbus/1000-user/bus", O_RDWR|O_NOCTTY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
Failed to start kiosk.service: Unit kiosk.service not found.
+++ exited with 5 +++
我没有找到访问该文件的尝试...
-- 增加 2 --
我错过了打字systemctl --user daemon-reload
。
现在找到了服务但没有任何反应。
linaro@tinkerboard:~/.config/systemd/user$ systemctl --user status kiosk
● kiosk.service - Kiosk launcher as service
Loaded: loaded (/home/linaro/.config/systemd/user/kiosk.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2022-07-22 15:01:55 CEST; 2min 28s ago
Process: 3489 ExecStart=/usr/bin/chromium (code=exited, status=1/FAILURE)
Main PID: 3489 (code=exited, status=1/FAILURE)
Jul 22 15:01:54 tinkerboard systemd[1184]: Started Kiosk launcher as service.
Jul 22 15:01:55 tinkerboard systemd[1184]: kiosk.service: Main process exited, code=exited, status=1/FAILURE
Jul 22 15:01:55 tinkerboard systemd[1184]: kiosk.service: Unit entered failed state.
Jul 22 15:01:55 tinkerboard systemd[1184]: kiosk.service: Failed with result 'exit-code'.
-- 增加 3 --
我在命令行上添加了 --enable-logging 并生成了日志调试。
[4837:4837:0722/155433.606728:WARNING:browser_main_loop.cc(297)] Gtk: cannot open display:
显示变量是否丢失?为什么?
- 更新 -
我修改了 ExecStart 来运行脚本。在脚本的命令行上添加了 DISPLAY 变量。
[Unit]
Description = Kiosk launcher as service
After = pulseaudio.service
Wants =
Requires =
[Service]
Type = simple
ExecStart = /home/amtek/launchService.sh
Restart = always
[Install]
WantedBy = graphical-session.target
如果我手动运行该服务,则由systemctl --user start kiosk
浏览器启动。如果我关闭浏览器,浏览器将重新启动。
但是如果我重新启动计算机,浏览器不会自动启动,并且我无法在 dmesg 或 syslog 中找到任何错误消息。
唯一的线索是:
linaro@tinkerboard:~$ systemctl --user status kiosk
● kiosk.service - Kiosk launcher as service
Loaded: loaded (/home/linaro/.config/systemd/user/kiosk.service; enabled; vendor preset: enabled)
Active: inactive (dead)
答案1
它在 systemd 的总线上运行--system
。我们知道这一点是因为您的服务文件位于/etc/systemd/system
.问题是root
通常没有桌面会话。即使 root 有一个(或多个)桌面会话,您也需要定义在哪个会话上显示此窗口。
在 systemd 的--user
总线上运行它。这将导致 chromium 以您的登录用户身份运行(而不是以 root 身份运行)。更重要的是,它将导致服务的环境继承登录用户的DISPLAY
环境XAUTHORITY
变量。
在公交车上运行--user
:
kiosk.service
将文件移动到~/.config/systemd/user/
.如果该目录不存在,请创建它。- 将您设置
WantedBy=
为用户总线上存在的内容。最好的情况是使用graphical-session.target
.这将导致 chromium 仅在桌面准备就绪后启动。这适用于大多数(但不是全部)桌面环境。如果您使用的东西尚未实现graphical-session.target(或者也许您正在调用xinit
自己),则使用WantedBy=default.target
. systemctl --user start kiosk.service
使用(不要使用sudo
)测试您的服务
或者,您可以继续在总线上运行它--system
,但您需要设置:
Environment=DISPLAY=:0 XAUTHORITY=/run/user/1000/gdm/Xauthority
(将这些值替换为与您的显示相关的值)。WantedBy=graphical.target
确保只有在显示器运行后才启动User=kioskuser
以避免授予您的用户 root 权限。