¿Cómo puedo encontrar la causa exacta por la que el servicio systemd no puede iniciarse (el servicio tiene una configuración de archivo de unidad incorrecta)?

¿Cómo puedo encontrar la causa exacta por la que el servicio systemd no puede iniciarse (el servicio tiene una configuración de archivo de unidad incorrecta)?

Es realmente molesto que systemdsolo respondiera que mi configuración de un archivo de servicio es incorrecta, pero no especifica dónde está el error exactamente:

/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 del directorio, /etc/repmgrlos dos comandos funcionaron bien. Pero el servicio systemd simplemente respondió con un error:

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

Respuesta1

Puedes usar el systemd-analyze verifycomando. Si ponemos el contenido de su pregunta en pgha.service, vemos:

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

Recibes este error porque el propio systemd usa%<something> tokens (consulta laSección "Especificadores" delsystemd.unit(5) página de manual.

Necesitarías escribir:

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

información relacionada