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 A9B83159C96 for ; Mon, 29 Jul 2024 21:54:12 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AE5D82BC0FC; Mon, 29 Jul 2024 21:52:51 +0000 (UTC) Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) (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 470262BC0F4 for ; Mon, 29 Jul 2024 21:52:51 +0000 (UTC) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5b3fff87e6bso596244a12.0 for ; Mon, 29 Jul 2024 14:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722289970; x=1722894770; 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=3J/Kc3xL2PZu2Uq/8VurDvabU5Xyfju42fXuGgSYXzo=; b=k2+yAPkaNE9L7rXuij6WIbEFMeDwoulDmhxKaayfSEr1Mm4Br2Y258t1dwvGJ80mPt ByfZ/0PLKITVs/OMEGDsSzFlsputgmFyYJXxxk08+kun/3GkPEaJtRX3j7t+xl0Oh+6L ITGt6BlAkBZdPTquoSOs/A9QJ/G451465xAtNeoPdsSswJFIDczE89Rqwhd5wKxz/csB ypuhm14ymglO6WotUj1ExNNwvY/uaKmkPmbiv2VCvLwjNmXrXP4VUFlv0BVtyDZAuqV2 B2P6b0uLHDHrOrNwBic30LMiZfSJP/IQlAegzd2rAd66dTGC/+mBEocLKFGXK1UZS4s3 WVfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722289970; x=1722894770; 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=3J/Kc3xL2PZu2Uq/8VurDvabU5Xyfju42fXuGgSYXzo=; b=vRj23uQkY7A9ADGo1Ky9/Ruz0NHdE9IInP1gKrS44QsDhb4crIo1Qlsv1HwOiczwpb Qw9K9glzxpn6SrGJmScrwwIh44KfHT47Y3h3KDRfOj5rDocSBWHR/Wvg90vWtqy+0DAD FPNRWpqRJD9ABOp3VdQ9ogHDQRaIMcPIIY+FISH4cWpNvN2szcOf+EFX90eKxRzWiKW0 UyM2NipmFcEtBeo5R9e+IKMIBoqmJ4yWhmmGgEwvz2eFV00+5aNKDSnli92MQICaM2CT 0k6NN6ToniJr/Tt3na1mntEyUOYLrSrVx53fxeDlhTG3QNRKgHsVYigJAIPGe32v5nJp x2IA== X-Gm-Message-State: AOJu0YzPA3MVwx5JO2iGgFxw5tzFT+JQc4+UWVbQmg1ru+NVMareejuN s9m6fUyBSRw9WIi41SM0XSRVL1MJ7AjGirXJBoF8i5gkN+7uKCIg1JSZrAE2 X-Google-Smtp-Source: AGHT+IEGHEEOnQNjyeLlOZkVnt2MQgtnaGYRakJC3g9ORERCWgyRZd85FAK5qVnYg4Lpt/a4tLitRg== X-Received: by 2002:a17:907:3fa4:b0:a77:eb34:3b44 with SMTP id a640c23a62f3a-a7d400a1a77mr666507366b.30.1722289969568; Mon, 29 Jul 2024 14:52:49 -0700 (PDT) Received: from localhost.localdomain ([62.244.50.57]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acad9046fsm564748266b.147.2024.07.29.14.52.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 14:52:49 -0700 (PDT) From: Zurab Kvachadze To: gentoo-dev@lists.gentoo.org Cc: conikost@gentoo.org, Zurab Kvachadze Subject: [gentoo-dev] [RFC PATCH v2 05/20] www-servers/nginx: add nginx-r5.initd Date: Tue, 30 Jul 2024 00:52:21 +0300 Message-ID: <20240729215241.13243-6-zurabid2016@gmail.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240729215241.13243-1-zurabid2016@gmail.com> References: <20240729215241.13243-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: 4540ed6a-10f8-4152-9159-9cc755492e65 X-Archives-Hash: 4da2ac5f9a6f6ce2dcd19005b6c4f010 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 | 112 +++++++++++++++++++++++++ 1 file changed, 112 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..ea5fdde0c9fa --- /dev/null +++ b/www-servers/nginx/files/nginx-r5.initd @@ -0,0 +1,112 @@ +#!/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/${RV_SVCNAME}.conf} +NGINX_MAXWAITTIME=${NGINX_MAXWAITTIME:-3} + +command="/usr/sbin/nginx" +start_stop_daemon_args=${NGINX_SSDARGS:-"--wait 1000"} +pidfile=/run/${RV_SVCNAME}.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() { + use dns logger netmount +} + +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}" -g "pid ${pidfile};" 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 has 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