From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 7C106158170 for ; Wed, 17 Jul 2024 12:07:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5F78E2BC122; Wed, 17 Jul 2024 12:06:03 +0000 (UTC) Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 2A18C2BC11B for ; Wed, 17 Jul 2024 12:06:03 +0000 (UTC) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-52e9944764fso7821761e87.3 for ; Wed, 17 Jul 2024 05:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721217962; x=1721822762; darn=lists.gentoo.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xfCZuhPkfH3JgKBYcFZgBqF62WQemL75Ur8f6tc0qM8=; b=G2NK/kp2KbGUr+Q5dVS/SBVzEh9LNF6htWtIkcXdWd6qkVSm8IPhkiUKIEEkUDBspO 4hLPUVoPnldP4DUQ9KvXqioPGQ09a70Qo4Fb+4iAA+5Gh+bdv0JDfOOoJtDfYa9ZedjO ttMLGNjGmmoJvJAUkju1FivNUTOTMUDfdms5x6TTLYTwK58wbhhr6jGdEzD9o0fhqF7Q AT0Z4Tsmh+93yhAPboqXwDvg8KXC3aCQ0/SOHNEwMtSjClibuA3fMuD/jBMxR/Axi6Is Dfv9j3TPSQaCp53p41RHr6L4PKgNuxkDO1Hq0yE44PMBPMMstsbMRyuFbWVVkCobiVZD s4mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721217962; x=1721822762; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xfCZuhPkfH3JgKBYcFZgBqF62WQemL75Ur8f6tc0qM8=; b=OFv6BJjxXyu1sWPFZlJS7453bxB+LU7r5fKxPDZsgHfdcq4b7X7L/Ae2bPcsmxMq2h k0HoS3mN+5igWq3g66FBrna126BxcjwopRLv9rtmVHQUnew460aN2K2Estx+xLwRMARc alCBEYe7EynVeyEKHM29zUt9OKH5RMOCJrH+32Z0QU0+w0VCbP/a8kAKjkkc0+Hqjzdr QA/+YOgJvTxZ18HMV/HRrue5qzSwshMF28RmhzmxHjlKOjVaDOk3evs4hjTXkzZRm3AD goIBEl/1Wn3jxNgpYe1vp+Ylc02XncwKogxIM3EK2/TfWJ/tQ7cSE+Gh5ucvgIkqtvBv gD3g== X-Gm-Message-State: AOJu0Yz/mA1j3shp0dRTffGvoMxF4Ix/9wyEsBHZmf0+InYqBlhM58Hr ZZfDOl2YigMZCpnZbsp0aUOmmqlgVLPam43duo+jieBMht3AAy5JgvRO3w== X-Google-Smtp-Source: AGHT+IENhQMldLhBUmSl7DT+/PhM/s4nT0ohtxQfWqaKIFiSU75k3BKaaaNPt4wNNIigDOAIRqXc6Q== X-Received: by 2002:a2e:b60a:0:b0:2ee:4dc6:fe28 with SMTP id 38308e7fff4ca-2eefd162928mr10276111fa.40.1721217961305; Wed, 17 Jul 2024 05:06:01 -0700 (PDT) Received: from localhost.localdomain ([62.244.50.57]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2eee1914ad5sm14636941fa.79.2024.07.17.05.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 05:06:01 -0700 (PDT) From: Zurab Kvachadze To: gentoo-dev@lists.gentoo.org Cc: Zurab Kvachadze Subject: [gentoo-dev] [RFC PATCH 04/19] www-servers/nginx: add nginx-r5.initd Date: Wed, 17 Jul 2024 15:05:36 +0300 Message-ID: <20240717120553.31866-5-zurabid2016@gmail.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240717120553.31866-1-zurabid2016@gmail.com> References: <20240717120553.31866-1-zurabid2016@gmail.com> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: 5ae800ff-0d00-47ae-bd10-4df83c329644 X-Archives-Hash: 35644f47098116afed3fe2381ab04dcb 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 --- 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