How to override a property in a Systemd unit

Sometimes you install a package with a Systemd service unit, but you want to override a property. To do this, run the following:

sudo systemctl edit mariadb.service

Add the stuff you want to override, such as:

[Service]
Restart=always

Then save the file. This will create a new file in:

/etc/systemd/system/mariadb.service.d/override.conf

Restart the service:

sudo systemctl daemon-reload
sudo systemctl restart mariadb.service

You can verify it works by:

[cbrake@xyz ~]$ sudo systemctl show mariadb | grep Restart=
Restart=always
2 Likes

This is handy tip, it can also be used when building offline images like we do with yocto e.g. /etc/systemd/system/mariadb.service.d/override.conf can be emitted via a bbappend and packaged into final image.