You are not logged in.
EDIT - solved here: https://bbs.archlinux.org/viewtopic.php … 5#p1956395
Hi,
I'm looking for a solution for notify a systemd service failure.
I'm able to send email for systemd service (following this guide: https://wiki.archlinux.org/index.php/Sy … _services).
I can't make the same things for --user service, like timers.
I tried to replicate the service.d folder in ~/.config/systemd/user:
% cat ~/.config/systemd/user/service.d/toplevel-override.conf
[Unit]
OnFailure=user-failure-notification@%n
% cat ~/.config/systemd/user/user-failure-notification@.service
[Unit]
Description=Send a notification about a failed systemd unit
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/systemd-email my-email %i
User=root
Group=systemd-journalUnfortunatly no email for the --user service. What's wrong wtih it?
Thank you
Last edited by monotiz (2021-02-16 08:02:34)
Offline
What's wrong wtih it?
That's a bit difficult to say without seeing the actual notification script. Did you check the journal?
Disclaimer: I've never actually tried this so I don't know if it's possible.
Jin, Jîyan, Azadî
Offline
Hi,
I'm looking for a solution for notify a systemd service failure.
Using an utterly simple function for this, I get a notification on tmux bar, but you can use it anyway you like.
sf() {
systemctl --failed --no-legend | awk '{ printf "%s ",$2; }'
}Offline
That's a bit difficult to say without seeing the actual notification script. Did you check the journal?
Disclaimer: I've never actually tried this so I don't know if it's possible.
In the previous code, check for user-failure-notification@.service.
It's call a systemd-email script that send an email to my account. It's work for the system service.
Using an utterly simple function for this, I get a notification on tmux bar, but you can use it anyway you like.
Ok. I'm looking into it.
Last edited by monotiz (2021-02-16 07:31:55)
Offline
I see two immediate issues without being able to look more into it:
1. Unless something has changed, you can't have a system service dependency in a user service file (After=network.target)
2. You have "User=root" which I don't think is possible in a user service file.
Offline
I see two immediate issues without being able to look more into it:
1. Unless something has changed, you can't have a system service dependency in a user service file (After=network.target)
2. You have "User=root" which I don't think is possible in a user service file.
Not only that, the 'override.conf' says 'start service - user-failure-notification - but there's nothing in it to check against. That wont work OC, you need to run a comparrison at least or a tools(read script F.I.) that does that job.
Also, I do agree with firecat53, a user service don't have root as user. Also to check if a service has failed you don't need to be root even on a default hardened-kernel!
I don't say you need not tweak this services but I think you get closer with:
# sf.service
[Unit]
Description=systemctl failed
OnFailure=sf-noti.service
[Service]
ExecStart=~/bin/service-checker sf
# sf-noti.service
[Unit]
Description=Send notification
[Service]
Type=simple
ExecStart=/usr/local/bin/systemd-email my-email %i
ExecStop=systemctl --user start sf.service
StandardError=journalOffline
Hi guys... thank you for your reply. I solved! Here the solution (maybe help some others).
For the system service, check the wiki page: https://wiki.archlinux.org/index.php/Sy … d_services
For the systemd/User service, I made a simple test service to generate an error:
$ cat ~/.config/systemd/user/test.service
[Unit]
Description=Test for sendmail
[Service]
Type=oneshot
ExecStart=make an error here!
[Install]
WantedBy=default.targetNext, I created a toplevel-override:
$ cat ~/.config/systemd/user/service.d/toplevel-override.conf
[Unit]
OnFailure=user-failure-notification@%nand a service for notification:
$ cat ~/.config/systemd/user/user-failure-notification@.service
[Unit]
Description=Send a notification about a failed systemd unit
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/systemd-user-email my-email %i
StandardError=journalCreat an empty drop-in like descript in the wiki page:
$ mkdir ~/.config/systemd/user/user-failure-notification@.service.d
$ touch ~/.config/systemd/user/user-failure-notification@.service.d/toplevel-override.confLast, the systemd-user-mail script:
$ cat /usr/local/bin/systemd-user-email
#!/bin/sh
/usr/bin/sendmail -t <<ERRMAIL
To: $1
From: systemd <root@$HOSTNAME>
Subject: $2
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
$(systemctl status --user --full "$2")
ERRMAILOffline