大网数据广告活动
服务器运维问答

Redis with custom data dir: systemd config file changed automatically?

· 52CE 我爱测

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:…

问题原文

原帖链接 · Andrei O · CC BY-SA 4.0

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?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-12-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。