diff options
| -rw-r--r-- | 0003-Fix-8051-use-old-way-as-fallback-to-save-configurati.patch | 96 | ||||
| -rw-r--r-- | redis-sentinel.init | 2 | ||||
| -rw-r--r-- | redis-sentinel.service | 6 | ||||
| -rw-r--r-- | redis-shutdown | 2 | ||||
| -rw-r--r-- | redis.init | 2 | ||||
| -rw-r--r-- | redis.service | 4 | ||||
| -rw-r--r-- | redis.spec | 38 | 
7 files changed, 40 insertions, 110 deletions
diff --git a/0003-Fix-8051-use-old-way-as-fallback-to-save-configurati.patch b/0003-Fix-8051-use-old-way-as-fallback-to-save-configurati.patch deleted file mode 100644 index ddc2066..0000000 --- a/0003-Fix-8051-use-old-way-as-fallback-to-save-configurati.patch +++ /dev/null @@ -1,96 +0,0 @@ -From bd2302cb5ff137e03b056c9643991bd7ce7f0f5e Mon Sep 17 00:00:00 2001 -From: Remi Collet <remi@remirepo.net> -Date: Mon, 16 Nov 2020 11:04:10 +0100 -Subject: [PATCH] Fix #8051 use old way as fallback to save configuration file - in non writable dir - ---- - src/config.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 65 insertions(+) - -diff --git a/src/config.c b/src/config.c -index 07ed91e5f..c93407265 100644 ---- a/src/config.c -+++ b/src/config.c -@@ -1580,6 +1580,67 @@ void rewriteConfigRemoveOrphaned(struct rewriteConfigState *state) { -     dictReleaseIterator(di); - } -  -+/* This function overwrites the old configuration file with the new content. -+ * -+ * 1) The old file length is obtained. -+ * 2) If the new content is smaller, padding is added. -+ * 3) A single write(2) call is used to replace the content of the file. -+ * 4) Later the file is truncated to the length of the new content. -+ * -+ * This way we are sure the file is left in a consistent state even if the -+ * process is stopped between any of the four operations. -+ * -+ * This fallback method is called when atomic fails because of missing -+ * write permission in the configuration directory (e.g. /etc) -+ * -+ * The function returns 0 on success, otherwise -1 is returned and errno -+ * set accordingly. */ -+int rewriteConfigOverwriteFileFallback(char *configfile, sds content) { -+    int retval = 0; -+    int fd = open(configfile,O_RDWR|O_CREAT,0644); -+    int content_size = sdslen(content), padding = 0; -+    struct stat sb; -+    sds content_padded; -+ -+    /* 1) Open the old file (or create a new one if it does not -+     *    exist), get the size. */ -+    if (fd == -1) return -1; /* errno set by open(). */ -+    if (fstat(fd,&sb) == -1) { -+        close(fd); -+        return -1; /* errno set by fstat(). */ -+    } -+ -+    /* 2) Pad the content at least match the old file size. */ -+    content_padded = sdsdup(content); -+    if (content_size < sb.st_size) { -+        /* If the old file was bigger, pad the content with -+         * a newline plus as many "#" chars as required. */ -+        padding = sb.st_size - content_size; -+        content_padded = sdsgrowzero(content_padded,sb.st_size); -+        content_padded[content_size] = '\n'; -+        memset(content_padded+content_size+1,'#',padding-1); -+    } -+ -+    /* 3) Write the new content using a single write(2). */ -+    if (write(fd,content_padded,strlen(content_padded)) == -1) { -+        retval = -1; -+        goto cleanup; -+    } -+ -+    /* 4) Truncate the file to the right length if we used padding. */ -+    if (padding) { -+        if (ftruncate(fd,content_size) == -1) { -+            /* Non critical error... */ -+        } -+    } -+    serverLog(LL_DEBUG, "Rewritten config file (%s) successfully", configfile); -+ -+cleanup: -+    sdsfree(content_padded); -+    close(fd); -+    return retval; -+} -+ - /* This function replaces the old configuration file with the new content -  * in an atomic manner. -  * -@@ -1608,6 +1669,10 @@ int rewriteConfigOverwriteFile(char *configfile, sds content) { - #endif -  -     if (fd == -1) { -+        if (errno == EACCES) { -+            serverLog(LL_DEBUG, "Could not create tmp config file (%s), try fallback", strerror(errno)); -+            return rewriteConfigOverwriteFileFallback(configfile, content); -+        } -         serverLog(LL_WARNING, "Could not create tmp config file (%s)", strerror(errno)); -         return retval; -     } ---  -2.25.4 - diff --git a/redis-sentinel.init b/redis-sentinel.init index 1f8c005..d75f1c9 100644 --- a/redis-sentinel.init +++ b/redis-sentinel.init @@ -20,7 +20,7 @@ name="redis-sentinel"  exec="/usr/bin/$name"  shut="/usr/libexec/redis-shutdown"  pidfile="/var/run/redis/sentinel.pid" -SENTINEL_CONFIG="/etc/redis-sentinel.conf" +SENTINEL_CONFIG="/etc/redis/sentinel.conf"  [ -e /etc/sysconfig/redis-sentinel ] && . /etc/sysconfig/redis-sentinel diff --git a/redis-sentinel.service b/redis-sentinel.service index ec4ade4..a055cf5 100644 --- a/redis-sentinel.service +++ b/redis-sentinel.service @@ -1,10 +1,12 @@  [Unit]  Description=Redis Sentinel  After=network.target +After=network-online.target +Wants=network-online.target  [Service] -ExecStart=/usr/bin/redis-sentinel /etc/redis-sentinel.conf --daemonize no --supervised systemd -ExecStop=/usr/libexec/redis-shutdown redis-sentinel +ExecStart=/usr/bin/redis-sentinel /etc/redis/sentinel.conf --daemonize no --supervised systemd +ExecStop=/usr/libexec/redis-shutdown sentinel  Type=notify  User=redis  Group=redis diff --git a/redis-shutdown b/redis-shutdown index 53b9f09..1a4335a 100644 --- a/redis-shutdown +++ b/redis-shutdown @@ -12,7 +12,7 @@ if [ -z "$SERVICE_NAME" ]; then  fi  # Get the proper config file based on service name -CONFIG_FILE="/etc/$SERVICE_NAME.conf" +CONFIG_FILE="/etc/redis/$SERVICE_NAME.conf"  # Use awk to retrieve host, port from config file  HOST=`awk '/^[[:blank:]]*bind/ { print $2 }' $CONFIG_FILE | tail -n1` @@ -20,7 +20,7 @@ name="redis-server"  exec="/usr/bin/$name"  shut="/usr/libexec/redis-shutdown"  pidfile="/var/run/redis/redis.pid" -REDIS_CONFIG="/etc/redis.conf" +REDIS_CONFIG="/etc/redis/redis.conf"  [ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis diff --git a/redis.service b/redis.service index 94ef85b..4e59720 100644 --- a/redis.service +++ b/redis.service @@ -1,9 +1,11 @@  [Unit]  Description=Redis persistent key-value database  After=network.target +After=network-online.target +Wants=network-online.target  [Service] -ExecStart=/usr/bin/redis-server /etc/redis.conf --daemonize no --supervised systemd +ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --daemonize no --supervised systemd  ExecStop=/usr/libexec/redis-shutdown  Type=notify  User=redis @@ -52,7 +52,7 @@  Name:              redis  Version:           %{upstream_ver}%{?upstream_pre:~%{upstream_pre}} -Release:           2%{?dist} +Release:           3%{?dist}  Summary:           A persistent key-value database  Group:             Applications/Databases  License:           BSD @@ -83,8 +83,6 @@ Source10:          https://github.com/antirez/%{name}-doc/archive/%{doc_commit}/  Patch0001:         0001-1st-man-pageis-for-redis-cli-redis-benchmark-redis-c.patch  # https://github.com/antirez/redis/pull/3494 - symlink  Patch0002:         0002-install-redis-check-rdb-as-a-symlink-instead-of-dupl.patch -# https://github.com/antirez/redis/pull/8058 - config rewrite -Patch0003:         0003-Fix-8051-use-old-way-as-fallback-to-save-configurati.patch  BuildRequires:     gcc @@ -210,7 +208,6 @@ and removal, status checks, resharding, rebalancing, and other operations.  mv ../%{name}-doc-%{doc_commit} doc  %patch0001 -p1  %patch0002 -p1 -%patch0003 -p1  %if %{with jemalloc}  rm -frv deps/jemalloc @@ -289,8 +286,8 @@ install -d %{buildroot}%{redis_modules_dir}  install -pDm644 %{S:1} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}  # Install configuration files. -install -pDm640 %{name}.conf %{buildroot}%{_sysconfdir}/%{name}.conf -install -pDm640 sentinel.conf %{buildroot}%{_sysconfdir}/%{name}-sentinel.conf +install -pDm640 %{name}.conf  %{buildroot}%{_sysconfdir}/%{name}/%{name}.conf +install -pDm640 sentinel.conf %{buildroot}%{_sysconfdir}/%{name}/sentinel.conf  %if %{with systemd}  # Install systemd unit files. @@ -368,6 +365,26 @@ useradd -r -g %{name} -d %{_sharedstatedir}/%{name} -s /sbin/nologin \  exit 0  %post +if [ -f %{_sysconfdir}/%{name}.conf ]; then +  if [ -f %{_sysconfdir}/%{name}/%{name}.conf.rpmnew ]; then +    rm    %{_sysconfdir}/%{name}/%{name}.conf.rpmnew +  fi +  if [ -f %{_sysconfdir}/%{name}/%{name}.conf ]; then +    mv    %{_sysconfdir}/%{name}/%{name}.conf %{_sysconfdir}/%{name}/%{name}.conf.rpmnew +  fi +  mv %{_sysconfdir}/%{name}.conf %{_sysconfdir}/%{name}/%{name}.conf +  echo -e "\nWarning: %{name} configuration is now in %{_sysconfdir}/%{name} directory\n" +fi +if [ -f %{_sysconfdir}/%{name}-sentinel.conf ]; then +  if [ -f %{_sysconfdir}/%{name}/sentinel.conf.rpmnew ]; then +    rm    %{_sysconfdir}/%{name}/sentinel.conf.rpmnew +  fi +  if [ -f %{_sysconfdir}/%{name}/sentinel.conf ]; then +    mv    %{_sysconfdir}/%{name}/sentinel.conf %{_sysconfdir}/%{name}/sentinel.conf.rpmnew +  fi +  mv %{_sysconfdir}/%{name}-sentinel.conf %{_sysconfdir}/%{name}/sentinel.conf +fi +  %if %{with systemd}  %systemd_post %{name}.service  %systemd_post %{name}-sentinel.service @@ -409,8 +426,9 @@ fi  %license COPYING-jemalloc  %endif  %config(noreplace) %{_sysconfdir}/logrotate.d/%{name} -%attr(0640, redis, root) %config(noreplace) %{_sysconfdir}/%{name}.conf -%attr(0640, redis, root) %config(noreplace) %{_sysconfdir}/%{name}-sentinel.conf +%attr(0750, redis, root) %dir %{_sysconfdir}/%{name} +%attr(0640, redis, root) %config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf +%attr(0640, redis, root) %config(noreplace) %{_sysconfdir}/%{name}/sentinel.conf  %dir %attr(0750, redis, redis) %{_libdir}/%{name}  %dir %attr(0750, redis, redis) %{redis_modules_dir}  %dir %attr(0750, redis, redis) %{_sharedstatedir}/%{name} @@ -457,6 +475,10 @@ fi  %changelog +* Mon Nov 23 2020 Remi Collet <remi@remirepo.net> - 6.0.9-3 +- move configuration in /etc/redis per upstream recommendation +  see https://github.com/redis/redis/issues/8051 +  * Mon Nov 16 2020 Remi Collet <remi@remirepo.net> - 6.0.9-2  - fix broken config rewrite feature using patch from    https://github.com/redis/redis/pull/8058  | 
