Finished backup-to-swappable draft

This commit is contained in:
2023-04-26 22:12:40 +02:00
parent 6a4dea3582
commit 7eed695623
40 changed files with 115 additions and 37 deletions

View File

@@ -0,0 +1,6 @@
# server_native-systemd-mail
# see
- https://wiki.archlinux.org/index.php/Systemd/Timers#MAILTO
- https://serverfault.com/questions/876233/how-to-send-an-email-if-a-systemd-service-is-restarted/876254
- https://serverfault.com/questions/694818/get-notification-when-systemd-monitored-service-enters-failed-state

View File

@@ -0,0 +1,4 @@
- name: "restart systemd-email service"
systemd:
name: systemd-email.service
daemon_reload: yes

View File

@@ -0,0 +1,18 @@
- name: install smtp-forwarder
pacman: name=smtp-forwarder state=present
- name: configure msmtprc.conf.j2
template: src=msmtprc.conf.j2 dest=/root/.msmtprc
- name: "create {{systemd_email_folder}}"
file:
path: "{{systemd_email_folder}}"
state: directory
mode: 0755
- name: configure systemd-email.sh
template: src=systemd-email.sh.j2 dest={{systemd_email_folder}}systemd-email.sh
- name: configure systemd-email.service
template: src=systemd-email@.service.j2 dest=/etc/systemd/system/systemd-email@.service
notify: restart systemd-email service

View File

@@ -0,0 +1,15 @@
# Set default values for all following accounts.
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
account system_email
host {{system_email_host}}
port {{system_email_port}}
from {{system_email}}
user {{system_email_username}}
password {{system_email_password}}
account default : system_email

View File

@@ -0,0 +1,11 @@
#!/bin/bash
/usr/bin/sendmail -t <<ERRMAIL
To: {{administrator_email}}
From: systemd <{{system_email}}>
Subject: $1
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
$(systemctl status --full "$1")
ERRMAIL

View File

@@ -0,0 +1,8 @@
[Unit]
Description=status email for %i to user
[Service]
Type=oneshot
ExecStart=/bin/bash {{systemd_email_folder}}systemd-email.sh %i
User=root
Group=systemd-journal

View File

@@ -0,0 +1 @@
systemd_email_folder: "{{path_administrator_scripts}}systemd_email/"