Centos / RHEL 8システムサービスは、カスタムの場所のスクリプトを参照できません。

Centos / RHEL 8システムサービスは、カスタムの場所のスクリプトを参照できません。

(/usr/local/bin..ではなく)場所に存在する単純なスクリプト用のシステムサービスを作成しようとしています。

以下のスクリプトは/home/vagrant/temp/test.sh

#!/bin/sh

MAX=500
i=0;
while true
do
i=$((i+1));
sleep 2
echo "$i = $(date)"
if [ $i == $MAX ]; then
  exit 0;
fi;
done;
fi

私はという単純なusr-print.serviceサービスを作成しました/etc/systemd/system/。ファイルの内容は次のとおりです。

[Unit]
Description=Simple print service
After=network.target

[Service]

Type=simple
Restart=always
StandardOutput=journal
StandardError=journal

ExecStart=/home/vagrant/temp/test.sh

[Install]
WantedBy=multi-user.target

サービスの開始に使用すると、systemctl daemon-reload; systemctl start usr-print.service次の例外が発生します。

● usr-print.service - Simple print service
   Loaded: loaded (/etc/systemd/system/usr-print.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2021-08-02 06:10:39 UTC; 7s ago
  Process: 1504 ExecStart=/home/vagrant/temp/test.sh (code=exited, status=203/EXEC)
 Main PID: 1504 (code=exited, status=203/EXEC)

Aug 02 06:10:39 localhost.localdomain systemd[1]: usr-print.service: Main process exited, code=exited, status=203/EXEC
Aug 02 06:10:39 localhost.localdomain systemd[1]: usr-print.service: Failed with result 'exit-code'.
Aug 02 06:10:39 localhost.localdomain systemd[1]: usr-print.service: Service RestartSec=100ms expired, scheduling restart.
Aug 02 06:10:39 localhost.localdomain systemd[1]: usr-print.service: Scheduled restart job, restart counter is at 5.
Aug 02 06:10:39 localhost.localdomain systemd[1]: Stopped Simple print service.
Aug 02 06:10:39 localhost.localdomain systemd[1]: usr-print.service: Start request repeated too quickly.
Aug 02 06:10:39 localhost.localdomain systemd[1]: usr-print.service: Failed with result 'exit-code'.
Aug 02 06:10:39 localhost.localdomain systemd[1]: Failed to start Simple print service.

ただし、スクリプトを移動して usr-print.service ファイルを更新すると、 ExecStart=/usr/local/bin/test.shサービスは期待どおりに起動します。

/home/vagrant/temp/test.shサービスファイルのパスを使用する方法はありますか?

Centos 7 -ExecStart=/home/vagrant/temp/test.shサービスファイルの操作中(シェル実行中)

Centos / RHEL 8 -ExecStart=/home/vagrant/temp/test.shサービスファイルが機能しません。

修正する:

SELinuxには実行権限がありますが、スクリプトを実行できないようです。

SELinux is preventing /usr/lib/systemd/systemd from execute access on the file /home/vagrant/temp/test.sh.
                                                              
*****  Plugin catchall (100. confidence) suggests   **************************

If you believe that systemd should be allowed execute access on the user-print-service file by default.
    Then you should report this as a bug.
    You can generate a local policy module to allow this access.
    Do allow this access for now by executing:
       # ausearch -c '(-service)' --raw | audit2allow -M my-service
       # semodule -X 300 -i my-service.pp

Redhatでこれに関連するチケットを見つけました。https://bugzilla.redhat.com/show_bug.cgi?id=1832231

ベストアンサー1

ローカルで実行する1つの可能な方法は、次を使用することです。

getenforceSELinux で試行モードが有効になりました。

sudo setenforce 0これを無効にし、許可モードに切り替えます。これでサービスが実行中です。

ただし、これは本番環境ではお勧めできません。

おすすめ記事