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)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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/wwwDependencies (
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
Method 2
You may override a systemd unit file using
systemctl edit mysqld.service
Any statements made in the override file will take priority.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0