Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"service nginx upgrade" does not respect custom config file location #24

Open
CEbhNwPM opened this issue Jan 1, 2025 · 4 comments
Open
Labels
bug Something isn't working

Comments

@CEbhNwPM
Copy link

CEbhNwPM commented Jan 1, 2025

This affects the RPM postuninstall scriptlet in the nginx.org RPM packages, which executes "service nginx upgrade" when upgrading nginx via dnf.

I have a systemd unit override like this:

ExecStart=
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx-custom.conf 

I do this to avoid modifying the packaged nginx.conf and have all customized configuration in files that are not tracked by the package manager.

Specifically, this line in /usr/libexec/initscripts/legacy-actions/nginx/upgrade uses the wrong config file:
${nginx} -t -c ${conffile} -q || return 6

This test can fail in any number of scenarios. For example, my nginx-custom.conf defines a custom log_format which is referenced in included conf.d/*.conf files.
In this case, dnf returns "Binary upgrade failed, please check nginx's error.log" and the running process is not upgraded.

It would be much better if the upgrade script used the command line and arguments of the running nginx process instead of guessing, just like it gets the PID file from the systemd unit as well.

@CEbhNwPM CEbhNwPM added the bug Something isn't working label Jan 1, 2025
@thresheek thresheek transferred this issue from nginx/nginx Jan 2, 2025
@thresheek
Copy link
Member

Hi @CEbhNwPM!

Indeed, it's a valid issue. I've transferred it to the repository we use to track changes in nginx packaging.

To fix that, I suppose we could provide an overridable default for conffile in /usr/libexec/initscripts/legacy-actions/nginx/upgrade and in /usr/lib/systemd/system/nginx.service. Then, a system administrator could override it via /etc/sysconfig/nginx.

Something like the following (I'm going to put a PR for it at some point):

diff --git a/rpm/SOURCES/nginx.service b/rpm/SOURCES/nginx.service
index e509a2e..55384a9 100644
--- a/rpm/SOURCES/nginx.service
+++ b/rpm/SOURCES/nginx.service
@@ -7,7 +7,9 @@ Wants=network-online.target
 [Service]
 Type=forking
 PIDFile=/var/run/nginx.pid
-ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
+Environment="conffile=/etc/nginx/nginx.conf"
+EnvironmentFile=/etc/sysconfig/nginx
+ExecStart=/usr/sbin/nginx -c ${conffile}
 ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
 ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"

diff --git a/rpm/SOURCES/nginx.upgrade.sh b/rpm/SOURCES/nginx.upgrade.sh
index 25f5c22..7a881c6 100644
--- a/rpm/SOURCES/nginx.upgrade.sh
+++ b/rpm/SOURCES/nginx.upgrade.sh
@@ -8,7 +8,7 @@ fi

 prog=nginx
 nginx=/usr/sbin/nginx
-conffile=/etc/nginx/nginx.conf
+conffile=${conffile:-/etc/nginx/nginx.conf}
 pidfile=`/usr/bin/systemctl show -p PIDFile nginx.service | sed 's/^PIDFile=//' | tr ' ' '\n'`
 SLEEPSEC=${SLEEPSEC:-1}
 UPGRADEWAITLOOPS=${UPGRADEWAITLOOPS:-5}

I don't like the idea of parsing arguments and CLI, to be honest. I believe it's best to provide a reasonable configuration instead of guessing.

thresheek added a commit to thresheek/pkg-oss that referenced this issue Jan 2, 2025
This allows administrator to redefine a custom location for a
configuration file to be used during upgrade and startup.

References: nginx#24
@CEbhNwPM
Copy link
Author

CEbhNwPM commented Jan 6, 2025

Excellent, thank you very much for the quick and clean solution. As long as /etc/sysconfig/nginx is not included in the package, this will work.

@thresheek
Copy link
Member

That's actually one of the things I see that packages do differently, some include %config(noreplace) /etc/sysconfig/%name, and some don't. (At least on Alma Linux 9). I tend not to, but need to explore this more.

thresheek added a commit that referenced this issue Jan 7, 2025
This allows administrator to redefine a custom location for a
configuration file to be used during upgrade and startup.

References: #24
thresheek added a commit that referenced this issue Jan 8, 2025
This allows administrator to redefine a custom location for a
configuration file to be used during upgrade and startup.

References: #24
@thresheek
Copy link
Member

Hey @CEbhNwPM - I've pushed the changes to both main and stable branches for our packages. Note that this does not mean the packages will be modified right now - this will only apply to the future releases, e.g. 1.27.4 and 1.26.3 when they're out. There is no ETA for those at this moment.

I can keep this FR open until those are released and notify you of changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@thresheek @CEbhNwPM and others