Mdmonitor configuration

In the past I received a mail message on system startup from mdmonitor which confirms the state of the RAID. It was enabled by setting MDADM_MONITOR_ARGS=" --scan --test " in /etc/sysconfig/mdmonitor. Since the last update this hasn’t been working. I think the problem lies in /lib/systemd/system/mdmonitor.service which contains:

[Service]
Type=forking
PIDFile=/var/run/mdadm/mdadm.pid
EnvironmentFile=-/etc/sysconfig/mdmonitor
ExecStart=/sbin/mdadm --monitor --scan -f --pid-file=/var/run/mdadm/mdadm.pid

whereas I believe it should be:

[Service]
Type=forking
PIDFile=/var/run/mdadm/mdadm.pid
EnvironmentFile=-/etc/sysconfig/mdmonitor
ExecStart=/sbin/mdadm --monitor --scan -f --pid-file=/var/run/mdadm/mdadm.pid $OPTIONS

Is this a bug, and if so Alma or RHEL?

You’re right – the shipped unit file isn’t ideal. Taking a look at EL7 it looks correct:

# /usr/lib/systemd/system/mdmonitor.service
[Unit]
Description=Software RAID monitoring and management
After=syslog.target
ConditionPathExists=/etc/mdadm.conf

[Service]
Type=forking
PIDFile=/var/run/mdadm/mdadm.pid
Environment= MDADM_MONITOR_ARGS=--scan
EnvironmentFile=-/etc/sysconfig/mdmonitor
ExecStart=/sbin/mdadm --monitor $MDADM_MONITOR_ARGS -f --pid-file=/var/run/mdadm/mdadm.pid

[Install]
WantedBy=multi-user.target

I’d probably consider keeping that same variable name (MDADM_MONITOR_ARGS) for posterity.

I believe this would need to be fixed upstream.

Yes, that’s fixed it. I’ve edited the service file to have the default environment and the corrected ExecStart and it failed. Oops, forgot that you need systemctl restart mdmonitor first! Then it worked and geenrated the email message as required.

Thanks.

A note for people, who might be new to systemd:
An “edit” means creating a new unit file with same name under /etc/systemd/system/.
This supercedes (or augments) the version that is under /usr/lib/systemd/system/.

A way to get into editing a file in proper location is:
systemctl edit mdmonitor.service or systemctl --full edit mdmonitor.service

More in man systemctl and https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/assembly_working-with-systemd-unit-files_configuring-basic-system-settings

Thanks for that jlehtone. I must confess that I regard the whole systemd mess as a black box to avoid touching at all times. There’s no clarity or debugging and so I find workarounds where possible; under C8 I found that /etc/init.d still worked fine, though with protests! I haven’t needed to use it yet under Alma. By the way, a weird editor comes up by default, to make your commands usable try export EDITOR=vim (or for the “other side” presumably emacs).