0

I am using systemd to autolaunch a service with the following script: (see below)

I am trying to send an email before the service is started (the commented out line).

the link at the end of the line /home/vincent/wintergreen/service_files/IB_restart_email is the content of the email, as described here in paragraph 7.

Unit]
Description=Manages an instance of IBController

[Service]
Type=forking
User=vincent
Group=vincent
ExecStart=/bin/bash -c "cd /opt/IBController && bash IBControllerStart.sh -inline && sleep 10"
# ExecStartPre=/usr/bin/mail -s "Restarting TWS" [email protected] < /home/vincent/wintergreen/service_files/IB_restart_email 
Environment=DISPLAY=:0.0
KillMode=control-group
TimeoutSec=0
Restart=always

[Install]
WantedBy=graphical.target

However, this line returns the error mail: Cannot parse address <' (while expanding <'): Malformed email address. (i can see the error message when opening the journalctl)

This command works when used directly in the shell. Anyone has an idea how to make this mail sending line work when used from the systemd file?

PS: I am using postfix for the mail sending

2
  • Have you try in format cat /home/vincent/wintergreen/service_files/IB_restart_email|/usr/bin/mail -s "Restarting TWS" [email protected] because < symbol is user as part of email address Commented May 16, 2018 at 16:31
  • 1
    You used /bin/bash -c ... for the ExecStart, so why not also for the ExecStartPre line?
    – thrig
    Commented May 16, 2018 at 16:41

1 Answer 1

2

As documented in man systemd.service, systemd has a limited support for shell syntax, which does not include "<". So, the character is set to the "mail" command, resulting in this error.

I presume you are most interested in emails due to automatic restarts, which wold be due to service crashes.

For that, the OnFailure= directive is a better choice. Use it to provide a spaces-separated list of units that are activated when the unit enters the failed state.

There are already ready-made solutions to handle this, like this one which will email you the "status" output (including some log output) of the service when it fails.

Also, consider using the WorkingDirectory= directive instead of manually calling "cd" in ExecStart=.

It also not clear why "sleep 10" would be needed as part of starting the app.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .