[SOLVED] Systemd dependencies for mail forwarding

Elliott Partridge

Well-Known Member
Oct 7, 2018
56
11
48
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
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!