How to Run ASSP As A Systemd Service With Systemctl

Running the Anti-Spam SMTP Proxy (ASSP) reliably on a modern Linux server requires a proper service manager. By default, ASSP needs to start as root to bind to privileged mail ports (like port 25), after which it forks and spawns its main worker processes under a non-privileged user like nobody.

Using a custom systemd service file allows Linux to seamlessly handle this handoff, manage automatic restarts on failure, and handle process tracking without dealing with legacy PID files.


The Complete systemd Service File

Create a new service unit configuration file using your preferred text editor:

sudo nano /etc/systemd/system/assp.service

Paste the following optimized configuration into the file:

[Unit]
Description=ASSP (Anti-Spam SMTP Proxy)
After=network.target

[Service]
Type=forking
WorkingDirectory=/usr/local/assp
ExecStart=/usr/bin/perl /usr/local/assp/assp.pl
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Why This Configuration Works

  • Type=forking: Crucial for ASSP. It tells systemd that the initial process (started as root) will spawn a child process and then exit. systemd will wait for this handoff to complete rather than assuming the application crashed.
  • Root Execution: By omitting a User= directive in the service file, systemd launches the Perl script as root. This gives ASSP the authority to bind to port 25 before it internally drops its own privileges down to the nobody process.
  • No PID File Required: Modern systemd uses Linux control groups (cgroups) to track process trees. It will automatically detect and monitor the spawned nobody worker process without needing a legacy PIDFile directive.
  • Automatic Restarts: The Restart=always and RestartSec=5 directives ensure that if ASSP experiences a memory leak or crash, the system will automatically spin it back up after 5 seconds.

Activating and Managing ASSP

Once your service file is saved, run the following sequence to notify the system manager, enable the boot hook, and launch the proxy:

# 1. Reload systemd to detect the new service file
sudo systemctl daemon-reload

# 2. Enable ASSP to start automatically on system boot
sudo systemctl enable assp

# 3. Start the ASSP proxy service immediately
sudo systemctl start assp

Verifying the Service Status

To ensure that systemd is accurately tracking the background process tree, check the service status:

sudo systemctl status assp

You should see an active (running) status, and the CGroup section at the bottom will display the active Perl processes running under the nobody user.

Monitoring Real-Time Logs

Because systemd manages the execution environment, all standard output from ASSP is sent straight to the system journal. You can follow live spam-filtering logs using journalctl:

sudo journalctl -u assp -f

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.