63

I have installed MySQL on my Arch Linux server. I moved the data directory to a place under /home, where my RAID volume is mounted. I noticed that mysqld will not start in this configuration by default since the systemd unit contains the setting ProtectHome=true.

I want to override just this setting. I don't want to re-specify the ExecStart or similar commands, in case they change when the package is upgraded.

I tried making a simple file at /etc/systemd/system called mysqld.service and added only these lines:

[Service]
ProtectHome=false

This doesn't work as it looks like the service in /etc replaces, not overrides, the system service.

Is there a way to override settings in systemd unit files this way without directly modifying the files in /usr/lib/systemd/system? (which is what I have done for now as a temporary fix, although that will end up reverted if the package is updated)

2

2 Answers 2

114

systemctl edit will create a drop-in file where you can override most of the settings, but these files have some specifics worth mentioning:

Note that for drop-in files, if one wants to remove entries from a setting that is parsed as a list (and is not a dependency), such as AssertPathExists= (or e.g. ExecStart= in service units), one needs to first clear the list before re-adding all entries except the one that is to be removed.

#/etc/systemd/system/httpd.service.d/local.conf
[Unit]
AssertPathExists=
AssertPathExists=/srv/www

Dependencies (After=, etc.) cannot be reset to an empty list, so dependencies can only be added in drop-ins. If you want to remove dependencies, you have to override the entire unit.

To override the entire unit, use systemctl edit --full, this will make a copy in /etc if there is none yet and let you edit it.

See also Systemd delete overrides

4
  • 16
    +1 for the tip about clearing ExecStart
    – JoeNahmias
    Commented Aug 20, 2019 at 2:36
  • +1 Do you know where this is documented? I mean specifically the altering/clearing/adding-to behaviour of drop-ins?
    – AndreasT
    Commented Apr 9, 2020 at 12:15
  • 2
    @AndreasT: this is a direct quote from the documentation linked to in the post ("drop-in file"). Or have I misunderstood your question?
    – user
    Commented Apr 9, 2020 at 12:23
  • As an addition: You can also override systemd sockets the same way: sudo systemctl edit exampled.socket.
    – rugk
    Commented May 11, 2021 at 12:33
34

You may override a systemd unit file using

systemctl edit mysqld.service

Any statements made in the override file will take priority.

3
  • 2
    if only it wasn't interactive only ;(
    – Hvisage
    Commented Nov 7, 2021 at 12:37
  • 1
    @Hvisage it's possible to just create a folder and a file instead of running systemctl edit command. For example: mkdir /etc/systemd/system/coturn.service.d/ && echo -e "[Service]\nRestart=always" > /etc/systemd/system/coturn.service.d/overrides.conf Commented Jan 24, 2022 at 14:36
  • 4
    @Hvisage If writing the override file non-interactively, you may subsequently need to run sudo systemctl daemon-reload.
    – Asclepius
    Commented Feb 18, 2022 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .