systemd サービスが起動できない (サービスのユニット ファイル設定が間違っている) 正確な原因を見つけるにはどうすればよいですか?

systemd サービスが起動できない (サービスのユニット ファイル設定が間違っている) 正確な原因を見つけるにはどうすればよいですか?

systemdこれは、サービス ファイルの構成が間違っているという応答のみで、どこが間違っているのか正確には指定されていないため、非常に迷惑です。

/lib/systemd/system/auto_pgha.service:

[Unit]
Description=PostgreSQL High Availability
After=network.service
After=firewalld.service


[Service]
Type=simple
WorkingDirectory=/etc/repmgr
ExecStartPre=/bin/bash -c 'echo -e "\n"  `date +"%Y/%m/%d %a, %X"`": STARTING \n"  >> pgha.log'
ExecStart=/bin/bash -c "python3 pg_high_availability.py  &>> pgha.log"
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

ディレクトリ内では、/etc/repmgr2 つのコマンドは正常に動作しました。しかし、systemd サービスはエラーで応答しました:

# systemctl start auto_pgha
Failed to start auto_pgha.service: Unit auto_pgha.service has a bad unit file setting.
See system logs and 'systemctl status auto_pgha.service' for details.

# systemctl status -l auto_pgha
○ auto_pgha.service - PostgreSQL High Availability
     Loaded: bad-setting (Reason: Unit auto_pgha.service has a bad unit file setting.)
......
auto_pgha.service: Unit configuration has fatal error, unit will not be be started. 

答え1

コマンドを使用できますsystemd-analyze verify。質問の内容を に入力するとpgha.service、次のようになります。

$ systemd-analyze verify pgha.service
.../pgha.service:10: Failed to resolve unit specifiers in echo -e "
"  `date +"%Y/%m/%d %a, %X"`": STARTING
"  >> pgha.log: Invalid slot
pgha.service: Unit configuration has fatal error, unit will not be started.
Unit pgha.service has a bad unit file setting.

このエラーは、systemd自体がトークンを使用しているために発生します%<something>systemd.unit(5)マニュアルページの「指定子」セクション

次のように記述する必要があります:

ExecStartPre=/bin/bash -c 'echo -e "\n"  `date +"%%Y/%%m/%%d %%a, %%X"`": STARTING \n"  >> pgha.log'

関連情報