You are not logged in.

#1 2016-06-17 04:07:50

Salkay
Member
Registered: 2014-05-22
Posts: 412

[SOLVED] Cannot mail error message from systemd

I'm following the wiki on how to "set up systemd to send an e-mail when a unit fails". However I can't get it to work. I set it up as described, replacing both instances of `user` and the one instance of `address` with my user `salkay`.

I then test with `sudo systemctl start status-email-salkay@dbus.service`, which fails silently with no email sent.

$ sudo systemctl status status-email-salkay@dbus.service
● status-email-salkay@dbus.service - status email for dbus to salkay
   Loaded: loaded (/etc/systemd/system/status-email-salkay@.service; static; vendor preset: disabled)
   Active: inactive (dead)

Jun 17 13:44:27 salkay-XPS-17 systemd[1]: Starting status email for dbus to salkay...
Jun 17 13:44:28 salkay-XPS-17 systemd-email[5052]: 2016-06-17 13:44:28 Warning: No server certificate defined; TLS connections will fail.
Jun 17 13:44:28 salkay-XPS-17 systemd-email[5052]:  Suggested action: either install a certificate or change tls_advertise_hosts option
Jun 17 13:44:28 salkay-XPS-17 systemd[1]: Started status email for dbus to salkay.

N.B. the warning message is a red herring, because I can run the command fine manually, resulting in a sent mail as expected.

$ sudo systemd-email salkay dbus
2016-06-17 14:02:33 Warning: No server certificate defined; TLS connections will fail.
 Suggested action: either install a certificate or change tls_advertise_hosts option
You have new mail.

As a side note, I'm ultimately wanting to run this as a user unit. I tried this originally, placing it at ` ~/.config/systemd/user/status-email-salkay@.service` but it also failed, with additional errors.

Jun 17 14:03:52 salkay-XPS-17 systemd[623]: Starting status email for dbus to salkay...
Jun 17 14:03:52 salkay-XPS-17 systemd[13410]: status-email-salkay@dbus.service: Failed at step GROUP spawning /usr/local/bin/systemd-email: Operation not permitted
Jun 17 14:03:52 salkay-XPS-17 systemd[623]: status-email-salkay@dbus.service: Main process exited, code=exited, status=216/GROUP
Jun 17 14:03:52 salkay-XPS-17 systemd[623]: Failed to start status email for dbus to salkay.
Jun 17 14:03:52 salkay-XPS-17 systemd[623]: status-email-salkay@dbus.service: Unit entered failed state.
Jun 17 14:03:52 salkay-XPS-17 systemd[623]: status-email-salkay@dbus.service: Failed with result 'exit-code'.

Last edited by Salkay (2016-06-21 12:31:15)

Offline

#2 2016-06-20 16:14:01

paulstelian97
Member
Registered: 2016-01-13
Posts: 28

Re: [SOLVED] Cannot mail error message from systemd

Of course it fails /:) systemd-email requires root but your service does not call sudo. You need to ensure the Exec command has "sudo " prepended to it and that the /usr/local/bin/systemd-email command is set to NOPASSWD: in sudoers, for all users.

Offline

#3 2016-06-21 06:45:27

Salkay
Member
Registered: 2014-05-22
Posts: 412

Re: [SOLVED] Cannot mail error message from systemd

paulstelian97 wrote:

Of course it fails /:) systemd-email requires root but your service does not call sudo. You need to ensure the Exec command has "sudo " prepended to it and that the /usr/local/bin/systemd-email command is set to NOPASSWD: in sudoers, for all users.

Thanks for the reply. However, this did not help. I'm not sure if you were referring to my final code block, as the first two were already run with root permissions. Regardless, I could already run systemd-email manually without root. It sends the email fine. I tried your advice anyway, but this made no difference; the third code block still failed (this time with a slightly different error message).

Jun 21 16:39:01 salkay-XPS-17 systemd[5422]: status-email-salkay@dbus.service: Failed at step GROUP spawning /usr/bin/sudo: Operation not permitted

I didn't try re-running the first two code blocks.

Offline

#4 2016-06-21 08:03:52

Raynman
Member
Registered: 2011-10-22
Posts: 1,250

Re: [SOLVED] Cannot mail error message from systemd

I'm not familiar with systemd-email, but I'd like to point out the following:

Salkay wrote:

as the first two were already run with root permissions.

You said you took the service file from the wiki and as that specifies a user and group, it does not run as root. These user/group settings are also the cause for the error messages you get when you try to use this system service as a user service.

Offline

#5 2016-06-21 12:30:43

Salkay
Member
Registered: 2014-05-22
Posts: 412

Re: [SOLVED] Cannot mail error message from systemd

Raynman wrote:

I'm not familiar with systemd-email, but I'd like to point out the following:

Salkay wrote:

as the first two were already run with root permissions.

You said you took the service file from the wiki and as that specifies a user and group, it does not run as root. These user/group settings are also the cause for the error messages you get when you try to use this system service as a user service.

Ah. Stupid me. Yes, you are totally correct. When I lose the two lines referring to user and group, I can run the --user version perfectly. Thank you very much for your help, Raynman, and paulstelian97 as well.

(Also, for future reference, I had to pass `--user` to the `systemctl status…` line in `/usr/local/bin/systemd-email`.)

Offline

Board footer

Powered by FluxBB