MariaDB System Service
Wait for VPN
Since we use our Wireguard VPN for database replication between our servers, and set MariaDB to listen on the Wireguard network interface for incoming connections, we have to make sure that Wireguard VPN is up and ready before the MariaDB database server is started.
The Systemd services file for the MariaDB database server
/lib/systemd/system/mariadb.service
is created as part of the software
package installation. The recommended method is to create a Systemd
override-file and not change anything in the provided service file, as it
would be lost on software package updates.
You can create a override file easily with the help of the systemctl command:
$ sudo systemctl edit mariadb.service
This will start your editor with an empty file, where you can add your own custom Systemd service configuration options.
[Unit]
After=sys-devices-virtual-net-wg0.device unbound.service
BindsTo=sys-devices-virtual-net-wg0.device
The line After=sys-devices-virtual-net-wg0.device
ensures that the
wg0
VPN network interface is up before the mariadb.service
is
started.
The line BindsTo=wg0
ensures that if the WireGuard network interface
goes down , the MariaDB database server will be stopped too.
After you save and exit of the editor, the file will be saved as
/etc/systemd/system/mariadb.service.d/override.conf
and Systemd will
reload its configuration.