Como posso encontrar a causa exata da impossibilidade de iniciar o serviço systemd (o serviço tem uma configuração de arquivo de unidade incorreta)?

Como posso encontrar a causa exata da impossibilidade de iniciar o serviço systemd (o serviço tem uma configuração de arquivo de unidade incorreta)?

Isso é realmente irritante que systemdapenas respondeu que minha configuração de um arquivo de serviço está errada, mas não especifica exatamente onde está errado:

/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

Dentro do diretório, /etc/repmgros dois comandos funcionaram perfeitamente. Mas o serviço systemd respondeu com um erro:

# 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. 

Responder1

Você pode usar o systemd-analyze verifycomando. Se colocarmos o conteúdo da sua pergunta em pgha.service, veremos:

$ 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.

Você está recebendo este erro porque o próprio systemd usa %<something>tokens (veja oSeção "Especificadores" da systemd.unit(5)página de manual.

Você precisaria escrever:

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

informação relacionada