From: Zurab Kvachadze <zurabid2016@gmail.com>
To: gentoo-dev@lists.gentoo.org
Cc: Zurab Kvachadze <zurabid2016@gmail.com>
Subject: [gentoo-dev] [RFC PATCH 04/19] www-servers/nginx: add nginx-r5.initd
Date: Wed, 17 Jul 2024 15:05:36 +0300 [thread overview]
Message-ID: <20240717120553.31866-5-zurabid2016@gmail.com> (raw)
In-Reply-To: <20240717120553.31866-1-zurabid2016@gmail.com>
This is the fifth revision of the init.d script for NGINX.
Starting with this commit, NGINX does not check its configuration twice
upon start and configuration reload (bug 481456). In the former case, if
any errors occur, the error message will be printed. This is not the
case with the reload() function though, as it is impossible to
programmatically check if it has succeeded.
Previously, the stop_post() function would block the termination of the
NGINX service from finishing successfuly by returning 1 after not being
able to remove the PID-file. This was caused due to the PID-file being
deleted before the code block in question got executed. This revision
removes this troublesome statement.
The start_pre() now utilises "checkpath" to create, if it is not
present, the /var/tmp/nginx directory, where NGINX stores its temporary
files.
Bug: https://bugs.gentoo.org/481456
Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
---
www-servers/nginx/files/nginx-r5.initd | 117 +++++++++++++++++++++++++
1 file changed, 117 insertions(+)
create mode 100644 www-servers/nginx/files/nginx-r5.initd
diff --git a/www-servers/nginx/files/nginx-r5.initd b/www-servers/nginx/files/nginx-r5.initd
new file mode 100644
index 000000000000..1eafb75a9e37
--- /dev/null
+++ b/www-servers/nginx/files/nginx-r5.initd
@@ -0,0 +1,117 @@
+#!/sbin/openrc-run
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+name="NGINX"
+description="Robust, small and high performance HTTP and reverse proxy server"
+description_configtest="Run NGINX's internal config check."
+description_upgrade="Upgrade the NGINX binary without losing connections."
+description_reload="Reload the NGINX configuration without losing connections."
+
+NGINX_CONFIGFILE=${NGINX_CONFIGFILE:-/etc/nginx/nginx.conf}
+NGINX_MAXWAITTIME=${NGINX_MAXWAITTIME:-3}
+
+command="/usr/sbin/nginx"
+start_stop_daemon_args=${NGINX_SSDARGS:-"--wait 1000"}
+pidfile=${NGINX_PIDFILE:-/run/nginx.pid}
+user=${NGINX_USER:-nginx}
+group=${NGINX_GROUP:-nginx}
+retry=${NGINX_TERMTIMEOUT:-"TERM/60/KILL/5"}
+
+extra_commands="configtest"
+extra_started_commands="upgrade reload"
+
+depend() {
+ need net
+ use dns logger netmount
+}
+
+start_pre() {
+ checkpath -d -o root:root /var/tmp/nginx || return 1
+}
+
+stop_pre() {
+ if [ "${RC_CMD}" = "restart" ]; then
+ configtest || return 1
+ fi
+}
+
+start() {
+ ebegin "Starting NGINX"
+ set -f
+ local output
+ output="$(start-stop-daemon --start --exec "${command}" -p "${pidfile}" \
+ ${start_stop_daemon_args} -- -c "${NGINX_CONFIGFILE}" 2>&1)"
+ if ! eend $? ; then
+ eerror "Failed to start NGINX, please have a look at its output below:"
+ # Delete the last line in a POSIX-compliant way because it contains
+ # "start-stop-daemon failed..."
+ printf '%s\n' "${output}" | sed '$d'
+ eerror "Starting NGINX failed, please correct the errors above"
+ return 1
+ else
+ if [ -n "${output}" ]; then
+ ewarn "NGINX has started successfuly, yet there are warnings:"
+ printf "%s\n" "${output}"
+ ewarn "Please take a notice of the warnings above"
+ fi
+ return 0
+ fi
+}
+
+
+reload() {
+ ebegin "Refreshing NGINX's configuration"
+ start-stop-daemon --signal SIGHUP --pidfile "${pidfile}"
+ eend $? "Failed to reload NGINX's configuration, please correct the errors above"
+}
+
+upgrade() {
+ einfo "Upgrading NGINX"
+ configtest || { eerror "Unable to upgrade NGINX: Configuration check failed";
+ return 1; }
+
+ einfo "Sending USR2 signal to the old binary"
+ start-stop-daemon --signal SIGUSR2 --pidfile "${pidfile}"
+
+ ebegin "Waiting up to ${NGINX_MAXWAITTIME} seconds for NGINX to upgrade"
+ local startdate pidfile_found
+ pidfile_found=0
+ startdate="$(date +%s)"
+ while [ $(("$(date +%s)" - startdate)) -le "${NGINX_MAXWAITTIME}" ]; do
+ if [ -f "${pidfile}" ] && [ -f "${pidfile}.oldbin" ]; then
+ pidfile_found=1
+ break
+ fi
+ sleep 1
+ done
+
+ [ "${pidfile_found}" = 1 ]
+ if ! eend $?; then
+ eerror "NGINX has failed to upgrade in time. This might have been caused either"
+ eerror "by a configuration error, uncaught by the configuration check, or, more"
+ eerror "likely, by NGINX taking more time to load the configuration than is"
+ eerror "allowed by the NGINX_MAXWAITTIME variable"
+ eerror "The maximum waiting time can be adjusted by setting the NGINX_MAXWAITTIME"
+ eerror "variable to a larger value in /etc/conf.d/nginx"
+ return 1
+ fi
+
+ einfo "Sending QUIT signal to the old binary"
+ start-stop-daemon --signal SIGQUIT --pidfile "${pidfile}.oldbin" ||
+ { eerror "The old NGINX binary may not have been stopped properly: Sending QUIT signal failed";
+ return 1; }
+
+ einfo "The upgrade completed successfuly"
+}
+
+configtest() {
+ ebegin "Checking NGINX's configuration"
+ local output
+ output="$("${command}" -c "${NGINX_CONFIGFILE}" -t 2>&1)"
+ if ! eend $?; then
+ printf '%s\n' "${output}"
+ eerror "Configuration check failed, please correct the errors above"
+ return 1
+ fi
+}
--
2.44.2
next prev parent reply other threads:[~2024-07-17 12:07 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-17 12:05 [gentoo-dev] [RFC PATCH 00/19] Rework NGINX packaging in Gentoo by introducing nginx{,-module}.eclass Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 01/19] nginx.eclass: Add new eclass for building the NGINX server Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 02/19] nginx-module.eclass: Add new eclass for building NGINX external modules Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 03/19] www-servers/nginx: add myself as a proxy maintainer; update metadata.xml Zurab Kvachadze
2024-07-17 12:05 ` Zurab Kvachadze [this message]
2024-07-17 12:41 ` [gentoo-dev] [RFC PATCH 04/19] www-servers/nginx: add nginx-r5.initd Michael Orlitzky
2024-07-19 9:20 ` Zurab Kvachadze
2024-07-19 10:31 ` Michael Orlitzky
2024-07-19 16:33 ` Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 05/19] www-servers/nginx: add nginx-r1.confd Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 06/19] www-servers/nginx: add nginx-r2.service Zurab Kvachadze
2024-07-20 16:58 ` Alexander Tsoy
2024-07-20 17:15 ` Michael Orlitzky
2024-07-20 17:25 ` Alexander Tsoy
2024-07-20 19:17 ` Alexander Tsoy
2024-07-20 21:07 ` Michael Orlitzky
2024-07-21 21:19 ` Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 07/19] www-servers/nginx: add nginx-r2.logrotate Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 08/19] www-servers/nginx: add nginx-r4.conf Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 09/19] profiles/desc: reword and update nginx_modules_http.desc Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 10/19] profiles/desc: reword and update nginx_modules_mail.desc Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 11/19] profiles/desc: reword and update nginx_modules_stream.desc Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 12/19] profiles/categories: Add www-nginx category for external NGINX modules Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 13/19] www-servers/nginx: revbump 1.26.1-r1 to 1.26.1-r2, use nginx.eclass Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 14/19] www-servers/nginx: revbump 1.27.0-r1 to 1.27.0-r2, " Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 15/19] www-servers/nginx: add 9999 live version, " Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 16/19] www-nginx/ngx_devel_kit: new package, add 0.3.3 Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 17/19] www-nginx/ngx-echo: new package, add 0.63 Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 18/19] www-nginx/ngx-encrypted-session: new package, add 0.09 Zurab Kvachadze
2024-07-17 12:05 ` [gentoo-dev] [RFC PATCH 19/19] www-nginx/ngx-set-misc: new package, add 0.33 Zurab Kvachadze
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240717120553.31866-5-zurabid2016@gmail.com \
--to=zurabid2016@gmail.com \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox