[SOLVED] Systemd dependencies for mail forwarding

Elliott Partridge

Well-Known Member
Oct 7, 2018
57
11
48
Pittsburgh, PA
Piggy-backing off this thread:
https://forum.proxmox.com/threads/p...il-server-is-not-available.108893/post-495825

How should I set up the dependencies for a systemd service to ensure mail delivery during startup & shutdown of the system? From the thread linked above, I'll need to consider the cluster file system (pve-cluster.service). Any others?

For a concrete example, here's a service that invokes a script that sends mail. I want this to be able to send a mail both during shutdown and startup of the system.
Code:
[Unit]
Description=Send email at system Start and Stop
Wants=postfix.service
After=postfix.service pve-cluster.service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/local/sbin/bootmail.sh startup
ExecStop=/usr/local/sbin/bootmail.sh shutdown

[Install]
WantedBy=multi-user.target
 
Another wrench in this is that my mail server may be running in a container on the host, so I would also want to start this systemd service after VMs & containers have started. Which service is that? lxc.service, pve-guests.service?
 
Got it to work with pve-guests.service, but I did have to add a delay (using ExecStartPre) to give the mail server time to start up. Here's my final config (which successfully delivers mail for both start & shutdown):
Code:
[Unit]
Description=Send email at system Start and Stop
Wants=postfix.service
After=postfix.service pve-guests.service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStartPre=/bin/sleep 30
ExecStart=/usr/local/sbin/bootmail.sh startup
ExecStop=/usr/local/sbin/bootmail.sh shutdown

[Install]
WantedBy=multi-user.target