Redis with custom data dir: systemd config file changed automatically?
I'm running Redis 4.0.9 on Ubuntu 18.04.1 LTS with a custom data dir for the RBD file.
To make this work, besides updating the dir
in redis.conf
to the new location, I also had to update /etc/systemd/system/redis.service
and set:
ReadWriteDirectories=-/my/custom/data/dir
(as described here: https://stackoverflow.com/questions/44814351/failed-opening-the-rdb-file-read-only-file-system)
Everything was working fine, until suddenly one day Redis started giving the Failed opening the RDB file backup.rdb (in server root dir /var/lib/redis) for saving: Read-only file system
error again, as if the ReadWriteDirectories
was not set to the new data dir.
I checked /etc/systemd/system/redis.service
and the ReadWriteDirectories
entry I added was indeed gone. I added it back and, after restarting, Redis works fine again and can sava data.
My question is: how could /etc/systemd/system/redis.service
change and my ReadWriteDirectories
line disappear? I am the only one with access to this machine. Is this file overwritten automatically in some cases? Can I disable that?
You're not meant to edit the systemd service files shipped with packages. These can be replaced at any time, e.g. when the package is updated.
Instead, you should create override files containing the changes you want to make. These will be preserved because they are not part of the system package which gets updated.
The simple way to do this is to run systemctl edit redis
. This will create an override drop-in file /etc/systemd/system/redis.service.d/override.conf
, in which you can place your changes (and the proper section):
[Service]
ReadWriteDirectories=-/my/custom/data/dir
You may also create that directory and place files ending in .conf
in it manually. But do not leave the directory empty, as this will disable the service.
In either case, run systemctl daemon-reload
and you are ready to restart your service.