systemdサービスをロードするときのアクセスの表示

systemdサービスをロードするときのアクセスの表示

私はC言語とD言語で起動可能なサービスを書いています。

シンクライアントが設定されたユーザーデータベースがあります。ダウンロードプロセス中にネットワーク経由でこのデータベースにアクセスし、そこから特定のユーザーのMACアドレスに接続されているデータを取得します。実際、ユーザーは複数のモニターをシンクライアントに接続できます。各モニターのデータもデータベースからロードされます。xrandrモニターIDを知り、目的のモニターをある場所または別の場所に設定するソースコードを使用してプログラムを作成しました。実際には、ロードプロセス中に使用できないxrandrグローバル変数を使用してください。DISPLAY

● myservice-init.service - myservice
     Loaded: loaded (/etc/systemd/system/myservice-init.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-05-12 19:15:14 MSK; 55s ago
    Process: 1559 ExecStart=/etc/init.d/myservice-init (code=exited, status=1/FAILURE)
   Main PID: 1559 (code=exited, status=1/FAILURE)

мая 12 19:15:14 ts_d85ed3156a39 systemd[1]: Starting myservice...
мая 12 19:15:14 ts_d85ed3156a39 thinstation[1562]: Can't open display :0
мая 12 19:15:14 ts_d85ed3156a39 systemd[1]: myservice-init.service: Main process exited, code=exited, status=1/FAILURE
мая 12 19:15:14 ts_d85ed3156a39 systemd[1]: myservice-init.service: Failed with result 'exit-code'.
мая 12 19:15:14 ts_d85ed3156a39 systemd[1]: Failed to start myservice.

しかし、Xorgサービスを見てください。データはすぐそこにあります。

~# cat /etc/X11/xinit/xinitrc.d/50-systemd-user.sh

#!/bin/sh

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

ダウンロード後にサービスを開始しましたxorg.service。ただし、サービスの開始にこのコードを追加した後もエラーが発生します。

● myservice-init.service - myservice
     Loaded: loaded (/etc/systemd/system/myservice-init.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-05-12 19:08:52 MSK; 18s ago
    Process: 1560 ExecStart=/etc/init.d/myservice-init (code=exited, status=1/FAILURE)
   Main PID: 1560 (code=exited, status=1/FAILURE)

May 12 19:08:52 ts_d85ed3156a39 systemd[1]: Starting myservice...
May 12 19:08:52 ts_d85ed3156a39 thinstation[1564]: dbus-update-activation-environment: error: unable to connect to D-Bus: Unable to autolaun
May 12 19:08:52 ts_d85ed3156a39 thinstation[1570]: Can't open display :0
May 12 19:08:52 ts_d85ed3156a39 systemd[1]: myservice-init.service: Main process exited, code=exited, status=1/FAILURE
May 12 19:08:52 ts_d85ed3156a39 systemd[1]: myservice-init.service: Failed with result 'exit-code'.
May 12 19:08:52 ts_d85ed3156a39 systemd[1]: Failed to start myservice.

ちょうどアプリケーションを実行すると、正確に正しく実行されます。

IFace("enp3s0", "e8:5b:d2:11:6a:39", "192.168.0.15")
[Monitor("VGA-1", true, 1280, 1024)]

UPD。

ユーザーがログインしたときに起動しますが、DISPLAYを使用できないユーザーサービスを作成しました。

● myservice-init.service - myservice
     Loaded: loaded (/etc/systemd/user/myservice-init.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-05-12 22:31:30 MSK; 8min ago
    Process: 2550 ExecStart=/etc/init.d/myservice-init (code=exited, status=1/FAILURE)
   Main PID: 2550 (code=exited, status=1/FAILURE)

мая 12 22:31:30 ts_d85ed3156a39 systemd[2546]: Started myservice-init.
мая 12 22:31:30 ts_d85ed3156a39 myservice-init[2551]: Can't open display :0.0
мая 12 22:31:30 ts_d85ed3156a39 systemd[2546]: myservice-init.service: Main process exited, code=exited, status=1/FAILURE
мая 12 22:31:30 ts_d85ed3156a39 systemd[2546]: myservice-init.service: Failed with result 'exit-code'.

ベストアンサー1

おすすめ記事