systemd服務狀態始終處於啟動狀態

systemd服務狀態始終處於啟動狀態

我遇到了 systemd 服務的問題,腳本的狀態始終處於「啟動狀態」而不是「活動」。我不確定是什麼問題。請幫我解決這個問題。

我創建了 systemd 服務,它將每 30 秒執行一個 bash 腳本

My script : 
#!/bin/bash
PGPORT=$1
echo "running through bash script thourgh  systemd working `date`" >> //tmp/diditwork.txt

我的systemd服務配置

[root@pglinux02 system]# cat /etc/systemd/system/test-pg.service
[Unit]
Description=PostgreSQL db Service
After=network.target

[Service]
User=postgres
Type=simple
ExecStart=/tmp/test.sh 5432
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
[root@pglinux02 system]#

我的腳本正在按預期執行,但是當我檢查服務的狀態時,它始終顯示「正在啟動」狀態

[root@pglinux02 system]# systemctl status test-pg.service
● test-pg.service - PostgreSQL db Service 
   Loaded: loaded (/etc/systemd/system/test-pg.service; enabled; vendor preset: disabled)
   Active: **activating (auto-restart)** since Fri 2021-10-29 19:49:57 GMT; 6s ago
  Process: 5274 ExecStart=/tmp/test.sh 5432 (code=exited, status=0/SUCCESS)
 Main PID: 5274 (code=exited, status=0/SUCCESS)
[root@pglinux02 system]#

使該服務“活動(運行)”的方法是什麼?如果新增另一個參數“RemainAfterExit=yes”,則腳本第一次執行,並且在後續間隔中不再執行

請指出我的錯誤以及解決方案

謝謝杜爾加

相關內容