How to upgrade Redis without lost the change of redis.service file?

To run Redis as the Unix socket, I have changed the group in the file at /etc/systemd/system/redis.service

But when I update the system, the Redis get upgrade also if there is a new version, and the change in the file /etc/systemd/system/redis.service is lost.

Do you know how to keep the file redis.service when I upgrade Redis?

Thanks

This is not related to Hestia but… you should create an override.conf file for your service:

Let’s say you want to replace Group=redis to Group=random

Edit service with this command (it will create a file /etc/systemd/system/redis-server.service.d/override.conf:

systemctl edit redis.service

And here write the changes you need including the section. It is a good practice to blank first the variable and then apply the change just in case there are several variables with the same name.

### Editing /etc/systemd/system/redis-server.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Service]
Group=
Group=random

### Lines below this comment will be discarded
[...]

Save the file, reload systemd daemon files and restart redis.

systemctl daemon-reload
systemctl restart redis.service

And from now own your override.conf won’t be changed in future upgrades.

2 Likes

Thanks so much for your help. So, the final override.conf will look like below, right?

### Editing /etc/systemd/system/redis-server.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Service]
Group=redisgroup

### Lines below this comment will be discarded

### /lib/systemd/system/redis-server.service
# [Unit]
# Description=Advanced key-value store
# After=network.target
# Documentation=http://redis.io/documentation, man:redis-server(1)
#
# [Service]
# Type=notify
# ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
# ExecStop=/bin/kill -s TERM $MAINPID
# PIDFile=/run/redis/redis-server.pid
# TimeoutStopSec=0
# Restart=always
# User=redis
# Group=redisgroup
# RuntimeDirectory=redis
# RuntimeDirectoryMode=2755
#
# UMask=007
# PrivateTmp=yes
# LimitNOFILE=65535
# PrivateDevices=yes
# ProtectHome=yes
# ReadOnlyDirectories=/
# ReadWriteDirectories=-/var/lib/redis
# ReadWriteDirectories=-/var/log/redis
# ReadWriteDirectories=-/run/redis
#

In this case, I only changed the group from redis to redisgroup

1 Like

Looks good

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.