Skip to content

Automated Execution

anon edited this page May 30, 2025 · 1 revision

For continuous monitoring and timely reporting, MailLogSentinel should be configured to run automatically at regular intervals. The use of Systemd timers and services is the recommended method on modern Linux systems. The interactive setup process (--setup) is designed to help you generate template unit files for this purpose.

  • Generated Unit Files (during --setup): When you run the --setup wizard, it will offer to generate the following Systemd unit files. These files will be saved in the directory where you execute the setup command:

    • maillogsentinel.service: This service unit file defines how to run the core log extraction and processing task (i.e., running maillogsentinel without the --report flag).
    • maillogsentinel-extract.timer: This timer unit file defines a schedule (e.g., hourly) to trigger the maillogsentinel.service.
    • maillogsentinel-report.service: This service unit file defines how to run the email reporting task (i.e., running maillogsentinel --report).
    • maillogsentinel-report.timer: This timer unit file defines a schedule (e.g., daily, typically late in the evening) to trigger the maillogsentinel-report.service.
  • Manual Deployment and Activation Steps (User Responsibility):

    1. Review and Customize: After the unit files are generated, it is crucial to review them carefully.
      • Verify all paths (e.g., to the Python executable, the maillogsentinel script itself, and its configuration file specified in the ExecStart= line).
      • Most importantly, ensure the User= directive in the .service files is set to an appropriate non-root user. This user must have the necessary permissions to read the mail logs and write to MailLogSentinel's working and state directories.
      • Adjust the OnCalendar= schedules in the .timer files to match your desired frequency for log processing and reporting.
    2. Copy to Systemd Directory: Once you have reviewed and (if necessary) edited the unit files, copy them to the Systemd system directory, which is typically /etc/systemd/system/:
      sudo cp maillogsentinel.service maillogsentinel-extract.timer maillogsentinel-report.service maillogsentinel-report.timer /etc/systemd/system/
    3. Reload Systemd Daemon: Instruct Systemd to read the new (or modified) unit files:
      sudo systemctl daemon-reload
    4. Enable and Start Timers: To activate the schedules and ensure they persist across system reboots, enable and start the timers:
      sudo systemctl enable --now maillogsentinel-extract.timer
      sudo systemctl enable --now maillogsentinel-report.timer
      The --now option starts the timers immediately. If Persistent=true is set in the timer unit (which is the default for the generated templates), this may also trigger an immediate run of the associated service if it missed a scheduled run while the timer was inactive.
    5. Verify Operation: Check the status and next scheduled run times of your timers:
      systemctl list-timers --all
      You should see maillogsentinel-extract.timer and maillogsentinel-report.timer in the output. You can also inspect the logs of the services to ensure they are running correctly using journalctl:
      journalctl -u maillogsentinel.service -f 
      journalctl -u maillogsentinel-report.service -f
      (Use -f to follow the logs in real time).

Clone this wiki locally