4

This is really annoying that systemd only responded that my configuration of a service file is wrong, but does not specify where is wrong exactly:

/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

Inside directory /etc/repmgr the two commands worked just fine. But the systemd service just responded with an 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.

George Y
  • 618
  • 3
  • 11
  • 20

1 Answers1

13

You can use the systemd-analyze verify command. If we put the content from your question into pgha.service, we see:

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

You're getting this error because systemd itself uses %<something> tokens (see the "Specifiers" section of the systemd.unit(5) man page.

You would need to write:

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