I have the following service configured:
[Unit]
Description=SCollector
After=NetworkManager.service
[Service]
Type=simple
ExecStart=/bin/sh -c "/opt/scollector/scollector /opt/scollector/collectors || (echo '' | /usr/bin/mail -s 'scollector died' [email protected] && exit -1)"
Restart=on-failure
[Install]
WantedBy=multi-user.target
For some reason, that mail command never sends any mail when the scollector process exits with non-0. This works AOK when run on the command line, /bin/sh call and all. I've captured STDOUT and STDERR of mail, and it is throwing no errors. There is nothing in maillog.
What gives? Why won't it send mail?
ExecStartrunsexit -1whenscollectorexits with0. Is it ok?exit. I'll fix it in the question regardless so it doesn't red-herring anyone.ExecStart=/bin/sh -c "false || (echo '' | /usr/bin/mail -s 'scollector died' [email protected] && exit -1)". Does it work? Which version ofsystemdare you using?systemdnuking the double-forkedsendmailcall frommail. I'm on cent7, which usessystemd 208.ExecStart=/bin/sh -c "/usr/bin/mail -s test [email protected] </dev/null"will never send mail, unless you change theKillModeas indicated in my answer.