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/repmgr두 명령이 제대로 작동했습니다. 그러나 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'

관련 정보