Chromium をサービスとして実行できません。

Chromium をサービスとして実行できません。

パルスオーディオを実行する必要があるため、Chromeをサービスとして実行しようとしています。

サービスファイルは次のとおりです。

[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ますが、何も起こりません。
ステータスオプションの出力は次のとおりです。

● 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通常、デスクトップセッションがないことです。ルートに少なくとも1つのデスクトップセッションがある場合でも、このウィンドウが表示されるセッションを定義する必要があります。

systemdのバス--userで実行してください。これにより、Chromeはrootとして実行されず、ログインしたユーザーとして実行されます。さらに重要なのは、サービス環境がログインしたユーザーのDISPLAY環境XAUTHORITY変数を継承することです。

バスで走る--user

  1. kiosk.serviceファイルをに移動します~/.config/systemd/user/。ディレクトリがない場合は作成します。
  2. WantedBy=ユーザーバスに存在するものに設定します。最良の方法はを使用することですgraphical-session.target。これにより、デスクトップが準備されているときにのみChromeが起動します。これはほとんどの(すべてではない)デスクトップ環境で機能します。まだgraphic-session.targetを実装していないものを使用する場合(またはxinit直接呼び出す場合)WantedBy=default.target
  3. systemctl --user start kiosk.service(使用しない)を使ってsudoサービスをテストしてください。

または、バス上で実行することはできますが、--system次の設定が必要です。

  1. Environment=DISPLAY=:0 XAUTHORITY=/run/user/1000/gdm/Xauthority(この値をディスプレイに関連する値に置き換えます)。
  2. WantedBy=graphical.targetモニターが実行された後にのみ開始してください。
  3. User=kioskuserユーザーにroot権限を付与したくない場合

おすすめ記事