From nobody Thu Aug 14 13:47:39 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4c2mlH3DDJz64TyW; Thu, 14 Aug 2025 13:47:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c2mlH1p1tz4JLV; Thu, 14 Aug 2025 13:47:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755179259; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Jg0hWVxqU3ZbdWOQxP+mNZw8C5+1zAu7jcjqZABS8PI=; b=QGNxuF3+2jl1V0zUr3BX/0w0yDn57EQ5qo8ZMY/a4aQZMZ/Xwm7SPrSEuqlmeEPR0++JJt 9ANad/qhp3LLzX0nSfKYzjHvtmsicYPGKi0kWNkbedJfOwHwQNHSAki14XTmRjx6zloBJJ kO1ZEotG6f7w2vTZ1mdKl6qQzQQK4APuUZoQIr2SCy+HwnICdqxrlapRPZFsu6OI9+xZBB t2TuZc7sxHIcpeJg7VHof7Fr6JoITdxOAovsEqH6TPyS/dEMKei6EIA6gWDvV8gboKbWUE wlrTwTUl2nrlaKyNA8hb/La1HEliOxetTOC8uNWYUAUWM9/ZFSHJYDZfJycawg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755179259; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Jg0hWVxqU3ZbdWOQxP+mNZw8C5+1zAu7jcjqZABS8PI=; b=O8as69/a9HV3L86Fk/79dLtg9IiqIO+0EO8Ayv7W3aO1TaqNqwj5w/UXPNsleMda0R85OY 4Y3+HiLyE938JLF1zwK5K8y8e2b2w7yTf8UNC44QOvQpAgHL7O8GHugKnLDZFfV4JZtDdk LrqSqJgPV3QRqUB0MawNZzkvNBF6kQQ8jn+KOq5rsK+L8fY/ecOgouFMpjsFNUHFvJJb+t U+HDBYqrQDYpLuV4LI4GEp1Z99j9sVJ4+nauLjb4WNgZJ7z0e5kd7NFoR8GkWzC5szmQXI KkuivRMui4KkeMw6jpQsw73REqe8oEaDTEnvDWaRgDK11ckucpGMY2oBclH9HQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1755179259; a=rsa-sha256; cv=none; b=YmyEdXiWF6OPE5+8bH/IwNpN6X4335AuY5W7gGyB/ijqcu+SSs/GKiUbw902ztV5XP/et/ NpygvHAe2B0IEP4Y6hmGhVeg2i/hS9kHuL27opTxro2wFHWu7kpxWBXpPI0AkiB+mQKKLB 9kL+c9l+MmzFYEF6mBtdl6aCwPmG2yGG5q9gCz1tk2H1uTE7WkyqQuGYuSCqmy7Sv0GI0/ Ew7vJ8SYL5cj/1TZ9MVurjSf5U9cisfVNoK83erXIBnv1kM9vW8tCe3JtQJChcNNazY6We 9bDg5vSj3wuTc7Ds0E8U+Ly3wDoESF6iHNkT5mQgIbd98P5fS+nv4NhPA5nwGQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4c2mlH1B87zvts; Thu, 14 Aug 2025 13:47:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 57EDldhb017118; Thu, 14 Aug 2025 13:47:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57EDldPb017115; Thu, 14 Aug 2025 13:47:39 GMT (envelope-from git) Date: Thu, 14 Aug 2025 13:47:39 GMT Message-Id: <202508141347.57EDldPb017115@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 51dbdd1d8634 - stable/14 - rc: improve NAME_setup handling List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 51dbdd1d8634bf0d5af2a3d5a521a6576cc93a37 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=51dbdd1d8634bf0d5af2a3d5a521a6576cc93a37 commit 51dbdd1d8634bf0d5af2a3d5a521a6576cc93a37 Author: Franco Fichtner AuthorDate: 2024-05-24 16:38:56 +0000 Commit: Mark Johnston CommitDate: 2025-08-14 13:41:18 +0000 rc: improve NAME_setup handling Reload is used for service reconfiguration as well and lacks a NAME_prepend-like mechanism so it makes sense to extend the NAME_reload hook into this action. precmd may use configuration checks and blocks setup from doing its designated work (e.g. nginx). In moving the invoke of the setup script in front allows us to provide custom scripts for config file generation and fixing prior to precmd checking configuration integrity. Also introduce _run_rc_setup to separate the launcher from the main one. Let it run correctly in the case of restart_precmd and block further execution as would be the case in start due to the internal plumbing of restart being split into calling stop and start afterwards. Differential-Revsiion: https://reviews.freebsd.org/D36259 Signed-off-by: Franco Fichtner Reviewed by: imp, oshogbo Pull Request: https://github.com/freebsd/freebsd-src/pull/1258 (cherry picked from commit 11333dd580b704fb4ff0836e1d1a0634099b0cf6) --- libexec/rc/rc.subr | 72 ++++++++++++++++++++++++++++++++---------------- share/man/man8/rc.subr.8 | 11 ++++++-- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index 75110a0313cd..239ec4707b33 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -813,7 +813,8 @@ startmsg() # # ${name}_prepend n Command added before ${command}. # -# ${name}_setup n Command executed before ${command}. +# ${name}_setup n Command executed during start, restart and +# reload before ${rc_arg}_precmd is run. # # ${name}_login_class n Login class to use, else "daemon". # @@ -1075,9 +1076,9 @@ run_rc_command() return 1 fi - # if there's a custom ${XXX_cmd}, - # run that instead of the default - # + # if there's a custom ${XXX_cmd}, + # run that instead of the default + # eval _cmd=\$${rc_arg}_cmd \ _precmd=\$${rc_arg}_precmd \ _postcmd=\$${rc_arg}_postcmd @@ -1086,6 +1087,15 @@ run_rc_command() if [ -n "$_env" ]; then eval "export -- $_env" fi + + # service can redefine all so + # check for valid setup target + if [ "$rc_arg" = 'start' -o \ + "$rc_arg" = 'restart' -o \ + "$rc_arg" = 'reload' ]; then + _run_rc_setup || \ + warn "failed to setup ${name}" + fi _run_rc_precmd || return 1 _run_rc_doit "$_cpusetcmd $_cmd $rc_extra_args" || return 1 _run_rc_postcmd @@ -1135,13 +1145,14 @@ run_rc_command() return 1 fi + _run_rc_setup || warn "failed to setup ${name}" if ! _run_rc_precmd; then warn "failed precmd routine for ${name}" return 1 fi - # setup the full command to run - # + # setup the full command to run + # startmsg "Starting ${name}." if [ -n "$_chroot" ]; then _cd= @@ -1172,24 +1183,18 @@ $_cpusetcmd $command $rc_flags $command_args" fi fi - if [ -n "$_setup" ]; then - if ! _run_rc_doit "$_setup"; then - warn "failed to setup ${name}" - fi - fi - - # Prepend default limits + # Prepend default limits _doit="$_cd limits -C $_login_class $_limits $_doit" - # run the full command - # + # run the full command + # if ! _run_rc_doit "$_doit"; then warn "failed to start ${name}" return 1 fi - # finally, run postcmd - # + # finally, run postcmd + # _run_rc_postcmd ;; @@ -1202,14 +1207,14 @@ $_cpusetcmd $command $rc_flags $command_args" _run_rc_precmd || return 1 - # send the signal to stop - # + # send the signal to stop + # echo "Stopping ${name}." _doit=$(_run_rc_killcmd "${sig_stop:-TERM}") _run_rc_doit "$_doit" || return 1 - # wait for the command to exit, - # and run postcmd. + # wait for the command to exit, + # and run postcmd. wait_for_pids $rc_pid _run_rc_postcmd @@ -1221,6 +1226,8 @@ $_cpusetcmd $command $rc_flags $command_args" return 1 fi + _run_rc_setup || warn "failed to setup ${name}" + _run_rc_precmd || return 1 _doit=$(_run_rc_killcmd "${sig_reload:-HUP}") @@ -1230,9 +1237,11 @@ $_cpusetcmd $command $rc_flags $command_args" ;; restart) - # prevent restart being called more - # than once by any given script - # + _run_rc_setup || warn "failed to setup ${name}" + + # prevent restart being called more + # than once by any given script + # if ${_rc_restart_done:-false}; then return 0 fi @@ -1346,6 +1355,7 @@ $_cpusetcmd $command $rc_flags $command_args" # _precmd R # _postcmd R # _return W +# _setup R # _run_rc_offcmd() { @@ -1391,6 +1401,20 @@ _run_rc_postcmd() return 0 } +_run_rc_setup() +{ + # prevent multiple execution on restart => stop/start split + if ! ${_rc_restart_done:-false} && [ -n "$_setup" ]; then + debug "run_rc_command: ${rc_arg}_setup: $_setup" + eval "$_setup" + _return=$? + if [ $_return -ne 0 ]; then + return 1 + fi + fi + return 0 +} + _run_rc_doit() { local _m diff --git a/share/man/man8/rc.subr.8 b/share/man/man8/rc.subr.8 index 844ba0356692..d61307f483b2 100644 --- a/share/man/man8/rc.subr.8 +++ b/share/man/man8/rc.subr.8 @@ -686,8 +686,15 @@ This is a generic version of or .Va ${name}_nice . .It Va ${name}_setup -Command to be run prior to -.Va command . +Optional command to be run during +.Cm start , +.Cm restart , +and +.Cm reload +prior to the respective +.Ar argument Ns Va _precmd . +If the command fails for any reason it will output a warning, +but execution will continue. .It Ar argument Ns Va _cmd Shell commands which override the default method for .Ar argument .