systemd サービスで bash スクリプトを実行するにはどうすればいいですか?

systemd サービスで bash スクリプトを実行するにはどうすればいいですか?

systemd 経由でグラフィカル アプリケーションを起動したいです。以前 udev 経由で起動しようとしましたが、ルールの終了後にアプリケーションが強制終了されました。systemd 経由でアプリケーションを直接実行すると動作しますが、いくつかの制約付きでアプリケーションを起動するスクリプトを実行すると動作しません。

私のサービス ファイルは次のようになります。

[Unit]
Description=App starter

[Service]
Type=oneshot
RemainAfterExit=yes
Environment=DISPLAY=:0
Environment=HOME=/home/user/
ExecStart=/home/user/runApp

[Install]
WantedBy=multi-user.target

journalctl -xeは私に

Sep 25 13:50:00 host systemd[1]: Starting App starter...
Subject: A start job for unit app.service has begun execution
Defined-By: systemd
Support: https://forum.manjaro.org/c/support
 
A start job for unit xournalpp.service has begun execution.
 
The job identifier is 19196.
Sep 25 13:50:00 host runApp[313232]: App is not running
Sep 25 13:50:00 host systemd[1]: app.service: Main process exited, code=exited, status=1/FAILURE
Subject: Unit process exited
Defined-By: systemd
Support: https://forum.manjaro.org/c/support
 
An ExecStart= process belonging to unit xournalpp.service has exited.
 
The process' exit code is 'exited' and its exit status is 1.
Sep 25 13:50:00 host systemd[1]: app.service: Failed with result 'exit-code'.
Subject: Unit failed
Defined-By: systemd
Support: https://forum.manjaro.org/c/support
 
The unit xournalpp.service has entered the 'failed' state with result 'exit-code'.
Sep 25 13:50:00 host systemd[1]: Failed to start App starter.
Subject: A start job for unit app.service has failed
Defined-By: systemd
Support: https://forum.manjaro.org/c/support
 
A start job for unit app.service has finished with a failure.
 
The job identifier is 19196 and the job result is failed.

ここにスクリプトがあります。 によってバックグラウンドで実行されていることが原因でしょうか&? スクリプトを再利用したいのでこれが必要です。

#!/bin/bash

  if pgrep app
  then
      echo App is running
          wmctrl -x -a app
          wmctrl -x -r app -b "add,maximized_vert,maximized_horz"
          
  else
          echo App is not running
          /usr/bin/app & disown
  fi

答え1

権限の問題かもしれません。

/home/user通常、他のユーザーによるアクセスは許可されず、apparmor や selinux などのセキュリティ システムでは通常、このような使用が禁止されています。

systemd でスクリプトを使用する場合は、 に配置することをお勧めします/usr/local/bin

関連情報