Skip to content

Service Management

Complete guide to managing Mailborder services using SystemD.

Overview

Mailborder consists of multiple services that work together:

Service Purpose Dependencies
mb-rpcd RPC daemon (core) MariaDB, Redis
mb-filter Email content filtering mb-rpcd, Rspamd, ClamAV
mb-milter Milter protocol interface mb-rpcd
mb-eval Email evaluation engine mb-rpcd
mb-virtuoso Mail virtualization mb-rpcd
mb-scribe Logging and analytics mb-rpcd
mb-cron Scheduled tasks mb-rpcd
mb-guardian Security monitoring mb-rpcd

All services managed by SystemD.

Service Status

Check All Services

Quick status check:

sudo mb-status

Example output:

Mailborder V6 System Status
============================

Core Services:
  ✓ mb-rpcd       RUNNING  (PID 1234, uptime 5d 12h)
  ✓ mb-filter     RUNNING  (PID 1235, uptime 5d 12h)
  ✓ mb-milter     RUNNING  (PID 1237, uptime 5d 12h)
  ✓ mb-eval       RUNNING  (PID 1238, uptime 5d 12h)
  ✓ mb-virtuoso   RUNNING  (PID 1239, uptime 5d 12h)
  ✓ mb-scribe     RUNNING  (PID 1240, uptime 5d 12h)
  ✓ mb-cron       ENABLED  (timer active)
  ✓ mb-guardian   RUNNING  (PID 1242, uptime 5d 12h)

Dependencies:
  ✓ MariaDB       RUNNING  (PID 987, uptime 10d 3h)
  ✓ Redis         RUNNING  (PID 988, uptime 10d 3h)
  ✓ Postfix       RUNNING  (PID 989, uptime 10d 3h)
  ✓ Rspamd        RUNNING  (PID 990, uptime 10d 3h)
  ✓ ClamAV        RUNNING  (PID 991, uptime 10d 3h)
  ✓ Nginx         RUNNING  (PID 992, uptime 10d 3h)

System Health: GOOD
CPU Usage: 15%
Memory Usage: 2.1 GB / 8.0 GB (26%)
Disk Usage: 45 GB / 100 GB (45%)

Individual Service Status

Using SystemD:

sudo systemctl status mb-rpcd
sudo systemctl status mb-filter
sudo systemctl status mb-milter

Example output:

● mb-rpcd.service - Mailborder RPC Daemon
   Loaded: loaded (/etc/systemd/system/mb-rpcd.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2025-01-08 10:23:45 UTC; 5 days ago
 Main PID: 1234 (mb-rpcd)
    Tasks: 12 (limit: 4915)
   Memory: 256.5M
   CGroup: /system.slice/mb-rpcd.service
           ├─1234 /usr/libexec/mailborder/php_enc/mb-rpcd: main
           ├─1235 /usr/libexec/mailborder/php_enc/mb-rpcd: worker
           ├─1236 /usr/libexec/mailborder/php_enc/mb-rpcd: worker
           └─1237 /usr/libexec/mailborder/php_enc/mb-rpcd: worker

Jan 13 14:23:45 mailborder systemd[1]: Started Mailborder RPC Daemon.

Compact status:

sudo systemctl is-active mb-rpcd     # Returns: active or inactive
sudo systemctl is-enabled mb-rpcd    # Returns: enabled or disabled
sudo systemctl is-failed mb-rpcd     # Returns: failed or active

Starting Services

Start Individual Service

Start service:

sudo systemctl start mb-rpcd

Verify started:

sudo systemctl status mb-rpcd

Start All Mailborder Services

Start in correct order:

# Start core first
sudo systemctl start mb-rpcd

# Then start dependent services
sudo systemctl start mb-filter
sudo systemctl start mb-milter
sudo systemctl start mb-eval
sudo systemctl start mb-virtuoso
sudo systemctl start mb-scribe
sudo systemctl start mb-guardian

# Enable cron timer
sudo systemctl start mb-cron.timer

Or use helper script:

sudo mb-services start

Start Dependencies

Start all required dependencies:

sudo systemctl start mariadb
sudo systemctl start redis-server
sudo systemctl start postfix
sudo systemctl start rspamd
sudo systemctl start clamav-daemon
sudo systemctl start nginx
sudo systemctl start php8.2-fpm

Stopping Services

Stop Individual Service

Stop service:

sudo systemctl stop mb-filter

Verify stopped:

sudo systemctl status mb-filter

Stop All Mailborder Services

Stop all services:

# Stop dependent services first
sudo systemctl stop mb-filter
sudo systemctl stop mb-milter
sudo systemctl stop mb-eval
sudo systemctl stop mb-virtuoso
sudo systemctl stop mb-scribe
sudo systemctl stop mb-guardian
sudo systemctl stop mb-cron.timer

# Then stop core
sudo systemctl stop mb-rpcd

Or use helper:

sudo mb-services stop

Graceful vs Force Stop

Graceful stop (default):

sudo systemctl stop mb-filter
# Waits for current operations to complete (up to 90 seconds)

Force stop:

sudo systemctl kill mb-filter
# Immediately terminates process

Force stop signal:

sudo systemctl kill -s SIGKILL mb-filter
# Nuclear option - use only if service hangs

Restarting Services

Restart Individual Service

Restart service:

sudo systemctl restart mb-filter

This: 1. Stops the service 2. Waits for process to exit 3. Starts the service again

Quick restart check:

sudo systemctl restart mb-filter && sudo systemctl status mb-filter

Restart All Services

Restart all Mailborder services:

sudo mb-services restart

Manual restart in order:

# Restart core first
sudo systemctl restart mb-rpcd

# Then restart dependent services
sudo systemctl restart mb-filter
sudo systemctl restart mb-milter
sudo systemctl restart mb-eval
sudo systemctl restart mb-virtuoso
sudo systemctl restart mb-scribe
sudo systemctl restart mb-guardian

Reload vs Restart

Reload (preferred - no downtime):

sudo systemctl reload mb-rpcd
- Reloads configuration without stopping - No connection interruption - Faster than restart

Restart (full stop/start):

sudo systemctl restart mb-rpcd
- Stops and starts service - Brief downtime - Required for binary/library updates

When to reload: - Configuration file changes - Policy updates - Minor setting adjustments

When to restart: - Software updates - Library updates - Major configuration changes - Service malfunction

Enabling and Disabling Services

Enable Service (Auto-start on Boot)

Enable service:

sudo systemctl enable mb-rpcd

Creates symlink:

Created symlink /etc/systemd/system/multi-user.target.wants/mb-rpcd.service
  → /etc/systemd/system/mb-rpcd.service.

Enable and start:

sudo systemctl enable --now mb-filter

Disable Service

Disable service:

sudo systemctl disable mb-filter

Disable and stop:

sudo systemctl disable --now mb-filter

Check Enabled Status

Is service enabled?:

sudo systemctl is-enabled mb-rpcd
# Returns: enabled, disabled, masked, or static

List all enabled Mailborder services:

sudo systemctl list-unit-files | grep mb-

Example output:

mb-cron.service        enabled
mb-cron.timer          enabled
mb-eval.service        enabled
mb-filter.service      enabled
mb-guardian.service    enabled
mb-milter.service      enabled
mb-rpcd.service        enabled
mb-scribe.service      enabled
mb-virtuoso.service    enabled

Service Dependencies

Understanding Dependencies

View service dependencies:

sudo systemctl list-dependencies mb-filter

Example output:

mb-filter.service
● ├─system.slice
● ├─mb-rpcd.service
● ├─rspamd.service
● ├─clamav-daemon.service
● └─sysinit.target

Reverse dependencies (what depends on this service):

sudo systemctl list-dependencies --reverse mb-rpcd

Start Order

Correct startup order:

  1. Infrastructure:
  2. MariaDB
  3. Redis
  4. Nginx
  5. PHP-FPM

  6. Email Stack:

  7. Postfix
  8. Rspamd
  9. ClamAV

  10. Mailborder Core:

  11. mb-rpcd (starts first, others depend on it)

  12. Mailborder Services:

  13. mb-filter
  14. mb-milter
  15. mb-eval
  16. mb-virtuoso
  17. mb-scribe
  18. mb-guardian
  19. mb-cron

SystemD handles this automatically via unit file dependencies.

Service Logs

View Service Logs

Using journalctl (SystemD journal):

# All logs for service
sudo journalctl -u mb-rpcd

# Last 50 lines
sudo journalctl -u mb-rpcd -n 50

# Follow (real-time)
sudo journalctl -u mb-rpcd -f

# Since time
sudo journalctl -u mb-rpcd --since "1 hour ago"
sudo journalctl -u mb-rpcd --since "2025-01-13 14:00:00"

# Today only
sudo journalctl -u mb-rpcd --since today

# Between times
sudo journalctl -u mb-rpcd --since "2025-01-13 10:00:00" --until "2025-01-13 12:00:00"

Service-specific log files:

# Service logs in /var/log/mailborder/
sudo tail -f /var/log/mailborder/mb-rpcd.log
sudo tail -f /var/log/mailborder/mb-filter.log
sudo tail -f /var/log/mailborder/mb-milter.log

Log Filtering

Filter by priority:

# Errors only
sudo journalctl -u mb-filter -p err

# Warnings and above
sudo journalctl -u mb-filter -p warning

# Priority levels: emerg, alert, crit, err, warning, notice, info, debug

Search logs:

# Search for keyword
sudo journalctl -u mb-rpcd | grep ERROR

# Case-insensitive search
sudo journalctl -u mb-rpcd | grep -i error

Multiple services:

sudo journalctl -u mb-rpcd -u mb-filter -u mb-milter

Service Performance

Resource Usage

CPU and memory per service:

sudo systemctl status mb-rpcd | grep -E "Memory|CPU"

Example output:

   Memory: 256.5M

Using top:

top -p $(pgrep -d',' mb-rpcd)

Using ps:

ps aux | grep mb-rpcd

Service Statistics

View service statistics:

sudo systemctl show mb-rpcd

Specific properties:

# Memory usage
sudo systemctl show mb-rpcd -p MemoryCurrent

# Active state
sudo systemctl show mb-rpcd -p ActiveState

# Uptime
sudo systemctl show mb-rpcd -p ActiveEnterTimestamp

Process Information

List processes:

# Main process
systemctl show mb-rpcd -p MainPID

# All processes
sudo systemctl status mb-rpcd | grep -A20 CGroup

Process tree:

pstree -p $(systemctl show mb-rpcd -p MainPID --value)

Service Configuration

Unit File Location

Service files:

/etc/systemd/system/mb-rpcd.service
/etc/systemd/system/mb-filter.service
/etc/systemd/system/mb-milter.service
/etc/systemd/system/mb-eval.service
/etc/systemd/system/mb-virtuoso.service
/etc/systemd/system/mb-scribe.service
/etc/systemd/system/mb-cron.service
/etc/systemd/system/mb-cron.timer
/etc/systemd/system/mb-guardian.service

Edit Service Configuration

Edit service file:

sudo systemctl edit --full mb-rpcd

Or directly:

sudo nano /etc/systemd/system/mb-rpcd.service

After editing, reload SystemD:

sudo systemctl daemon-reload
sudo systemctl restart mb-rpcd

Service Overrides

Create override (preferred):

sudo systemctl edit mb-rpcd

Creates:

/etc/systemd/system/mb-rpcd.service.d/override.conf

Example override:

[Service]
# Increase restart delay
RestartSec=30

# Change memory limit
MemoryLimit=1G

Reload after changes:

sudo systemctl daemon-reload
sudo systemctl restart mb-rpcd

Troubleshooting

Service Won't Start

Check status and errors:

sudo systemctl status mb-rpcd
sudo journalctl -u mb-rpcd -n 100

Common issues:

  1. Dependencies not running:

    sudo systemctl status mariadb
    sudo systemctl status redis-server
    

  2. Port already in use:

    sudo netstat -tulpn | grep :10031
    

  3. Permission errors:

    sudo ls -lh /var/run/mailborder/
    sudo chown -R mailborder:mailborder /var/run/mailborder/
    

  4. Configuration error:

    sudo mb-config --verify
    

Service Keeps Restarting

Check restart status:

sudo systemctl status mb-filter

View restart history:

sudo journalctl -u mb-filter | grep "Started\|Stopped"

Common causes: - Crashes on startup (check logs) - Database connection failures - Memory limit exceeded - Configuration errors

Disable auto-restart temporarily:

sudo systemctl edit mb-filter

Add:

[Service]
Restart=no

Then diagnose issue before re-enabling.

Service is Slow

Check resource usage:

sudo systemctl status mb-filter
top -p $(pgrep -d',' mb-filter)

Check logs for errors:

sudo journalctl -u mb-filter -n 100 | grep -i "slow\|timeout\|error"

Adjust workers/threads:

sudo mb-config set filter.workers 8
sudo systemctl restart mb-filter

Service Unresponsive

Check if process is running:

pgrep -a mb-rpcd

Check if accepting connections:

sudo netstat -tulpn | grep mb-rpcd

Send reload signal:

sudo systemctl reload mb-rpcd

Force restart if needed:

sudo systemctl restart mb-rpcd

Maintenance Tasks

Graceful Maintenance Window

Prepare for maintenance:

# 1. Stop accepting new email
sudo postfix stop

# 2. Wait for queue to clear
watch mailq

# 3. Stop Mailborder services
sudo mb-services stop

# 4. Perform maintenance
sudo apt upgrade
sudo mb-maintenance --all

# 5. Start services
sudo mb-services start

# 6. Resume mail
sudo postfix start

Service Updates

Update Mailborder:

# Stop services
sudo mb-services stop

# Update package
sudo apt update
sudo apt upgrade mailborder

# Reload SystemD (in case unit files changed)
sudo systemctl daemon-reload

# Start services
sudo mb-services start

# Verify
sudo mb-status

Clean Restart All

Complete clean restart:

# Stop all
sudo mb-services stop
sudo systemctl stop postfix rspamd clamav-daemon

# Clear temp files
sudo rm -rf /var/run/mailborder/*
sudo rm -rf /tmp/mbv6-*

# Restart dependencies
sudo systemctl restart mariadb
sudo systemctl restart redis-server

# Start mail stack
sudo systemctl start postfix
sudo systemctl start rspamd
sudo systemctl start clamav-daemon

# Start Mailborder
sudo mb-services start

# Verify
sudo mb-status

Best Practices

Service Management

  1. Always check dependencies first
  2. Ensure MariaDB and Redis are running
  3. Check Postfix, Rspamd, ClamAV status

  4. Use reload instead of restart when possible

  5. Faster
  6. No downtime
  7. Preserves connections

  8. Monitor logs during changes

    sudo journalctl -u mb-rpcd -u mb-filter -f
    

  9. Verify after changes

    sudo mb-status
    sudo mailq  # Check mail queue
    

  10. Document changes

  11. Keep notes of why services were restarted
  12. Track configuration changes

Automation

Create service check script:

#!/bin/bash
# /usr/local/bin/check-mailborder

SERVICES="mb-rpcd mb-filter mb-milter mb-eval mb-virtuoso mb-scribe mb-guardian"

for service in $SERVICES; do
    if ! systemctl is-active --quiet $service; then
        echo "Service $service is not running!"
        # Send alert
        mail -s "Mailborder Alert: $service down" admin@example.com <<< "Service $service is not running"
        # Attempt restart
        systemctl start $service
    fi
done

Add to cron:

sudo crontab -e

Add:

*/5 * * * * /usr/local/bin/check-mailborder

See Also