From nobody Mon Sep 12 00:43:56 2022 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 4MQnsS31FSz4bt5y; Mon, 12 Sep 2022 00:43:56 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MQnsS2J7pz3mYw; Mon, 12 Sep 2022 00:43:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662943436; 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=A0sqbV0OZ6VQobQidDDcgF/ar4wvGirkLOu9lLhO3Kg=; b=CfkF1dfG4hWHfVHkAyIyLYFTlU1YNSE04xqbcZFk87ckBi2Pa1W8YGXFIDmKjY3Hka6Zts MXbl2dd2oFytdGJ93XDTCJOHOhCtEsP21m+bzUtYh/zlkked2tZ6pEZee+mpWg2N53qVT1 ABge+MmEd9sfjZCQ/oGDlWmQ5WbZ+nzaOPqeGW6SyDljirSxSbz8xS2KuXYdcbUIf7FEqI WFftGgiVUBEiRx0Ok3UTTrSb84GL5JF3Xug/z/t6LlCoxf5+CbZrFaY/FmoWQ6kNK7vcGY Ennod6b+EE+2+S0lffkB4UHBbqvvbr0EALV0EIeBuesj1vqt+LfMGnSyPmJ4lg== 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 4MQnsS1Jnrzpxg; Mon, 12 Sep 2022 00:43:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28C0huCT097981; Mon, 12 Sep 2022 00:43:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28C0huN4097980; Mon, 12 Sep 2022 00:43:56 GMT (envelope-from git) Date: Mon, 12 Sep 2022 00:43:56 GMT Message-Id: <202209120043.28C0huN4097980@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Cy Schubert Subject: git: eb3e5718bfba - stable/12 - libexec/rc: Add var_run rc script 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cy X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: eb3e5718bfba6e39d5dd34238b789ffaed974fad Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662943436; 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=A0sqbV0OZ6VQobQidDDcgF/ar4wvGirkLOu9lLhO3Kg=; b=lMoZere5glMxhPIkZmljzTpsktaTKKDgTWDyOJldiB/4LgtF+U7Hu/KrVj5AqyL1jvvOVc o8hxtbJa52YgECbQaNGF2CjTmV0oXUEThogEC3YUNfBrum4smGVM5yrQIKbERSevPBNatk lsgs8xZrltz01G0VauWVrisDpsIU8DXulRbfh4t2iYWwLtalIgVAcLZQkr4HxSz61PmKU5 lfMniyf7pAI0QupEcIBwnRI/77rXH53HUefpCZVpMmCyZPKXHMZMCEMap3pIHBPBFXQGOd FEss/A2Cg9M/d7wVo7Zk54RAvs1Eo/PaGLlQ+N4hCEbthyqlOhkMYb1pF1TNBw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1662943436; a=rsa-sha256; cv=none; b=Vl2kWJ4uQ2UqKGSoH9la7lXUlgut+8JcSlyIfu9wRE5x6DIsGaYhKbwshQb4fJ0pjiXaGs adlPAft+qwJrnd+/KYmfXcnoiClCqHzR0SM7y6EaNeSSE4hmt2/AcrmXH4mog8wIdY1Nfl nR+HdWuzbACu7xEd4Zg4385QgSXK30fKHcBK1qrr0JWr2NnCf1lUCi1ViPoHw+kKIhikm4 Yp3kE/aZgORQqCtiMZlT2JeduRHyvxviYbc3otddz5cJhd6A2SioUASNfyaAWITMWf9tVc 5ldrpA+57HWy8cwxfb9DmIwWjHvbSI4UWKqZLnlMlK2g9yMV+5BV4+CRhsk57g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=eb3e5718bfba6e39d5dd34238b789ffaed974fad commit eb3e5718bfba6e39d5dd34238b789ffaed974fad Author: Cy Schubert AuthorDate: 2022-08-28 12:48:25 +0000 Commit: Cy Schubert CommitDate: 2022-09-12 00:43:42 +0000 libexec/rc: Add var_run rc script Users with a tmpfs /var/run will lose the directory tree state of /var/run at reboot. This rc script will optionally (by default) capture the state of the directory structure in /var/run prior to shutdown and recreate it at system boot. Alternatively a user can save the state of the /var/run directories manually using service var_run save and disable the autosaving of /var/run state using the var_run_autosave variable, for those paranoid SSD users. PR: 259585, 259699 Reported by: freebsd@walstatt-de.de, Reviewed by: philip, gbe (previous version) Differential Revision: https://reviews.freebsd.org/D36386 (cherry picked from commit 27b9777c28b4e9474bdc500c28d04feec48fbb84) --- etc/mtree/BSD.var.dist | 2 ++ libexec/rc/rc.conf | 6 ++++++ libexec/rc/rc.d/Makefile | 1 + libexec/rc/rc.d/var_run | 47 +++++++++++++++++++++++++++++++++++++++++++++++ share/man/man5/rc.conf.5 | 28 ++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) diff --git a/etc/mtree/BSD.var.dist b/etc/mtree/BSD.var.dist index 7b54508c7b96..c7b34ab4a1df 100644 --- a/etc/mtree/BSD.var.dist +++ b/etc/mtree/BSD.var.dist @@ -46,6 +46,8 @@ .. ipf mode=0700 .. + mtree + .. ntp uname=ntpd gname=ntpd .. pkg diff --git a/libexec/rc/rc.conf b/libexec/rc/rc.conf index e6024cbd9bf6..122033d7fd88 100644 --- a/libexec/rc/rc.conf +++ b/libexec/rc/rc.conf @@ -58,6 +58,12 @@ varmfs_flags="-S" # Extra mount options for the mfs /var mfs_type="auto" # "md", "tmpfs", "auto" to prefer tmpfs with md as fallback populate_var="AUTO" # Set to YES to always (re)populate /var, NO to never cleanvar_enable="YES" # Clean the /var directory +var_run_enable="NO" # Save/restore /var/run structure at shutdown/reboot +var_run_autosave="NO" # Only restore /var/run structure at shutdown/reboot + # The user is expected to issue service var_run save to + # manually save the /var/run mtree +var_run_mtree="/var/db/mtree/BSD.var-run.mtree" + # Where to save /var/run mtree local_startup="/usr/local/etc/rc.d" # startup script dirs. script_name_sep=" " # Change if your startup scripts' names contain spaces rc_conf_files="/etc/rc.conf /etc/rc.conf.local" diff --git a/libexec/rc/rc.d/Makefile b/libexec/rc/rc.d/Makefile index 699505f98770..e7d00e3cc15c 100644 --- a/libexec/rc/rc.d/Makefile +++ b/libexec/rc/rc.d/Makefile @@ -119,6 +119,7 @@ CONFS= DAEMON \ ugidfw \ ${_utx} \ var \ + var_run \ watchdogd .if ${MK_NIS} != "no" diff --git a/libexec/rc/rc.d/var_run b/libexec/rc/rc.d/var_run new file mode 100755 index 000000000000..8da3f40a0e7c --- /dev/null +++ b/libexec/rc/rc.d/var_run @@ -0,0 +1,47 @@ +#!/bin/sh + +# PROVIDE: var_run +# REQUIRE: mountcritlocal +# BEFORE: cleanvar + +. /etc/rc.subr + +name=var_run +rcvar=var_run_enable +extra_commands="load save" +start_cmd="_var_run_start" +load_cmd="_var_run_load" +save_cmd="_var_run_save" +stop_cmd="_var_run_stop" + +load_rc_config $name + +# Set defaults +: ${var_run_enable:="NO"} +: ${var_run_mtree:="/var/db/mtree/BSD.var-run.mtree"} +: ${var_run_autosave:="YES"} + +_var_run_load() { + test -f ${var_run_mtree} && + mtree -U -i -q -f ${var_run_mtree} -p /var/run > /dev/null +} + +_var_run_save() { + if [ ! -d $(dirname ${var_run_mtree}) ]; then + mkdir -p ${var_run_mtree} + fi + mtree -dcbj -p /var/run > ${var_run_mtree} +} + +_var_run_start() { + df -ttmpfs /var/run > /dev/null 2>&1 && + _var_run_load +} + +_var_run_stop() { + df -ttmpfs /var/run > /dev/null 2>&1 && + checkyesno var_run_autosave && + _var_run_save +} + +run_rc_command "$1" diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index e11b25bcd651..0f82a5df93c6 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -447,6 +447,34 @@ is mounted on normal systems. Clean the .Pa /var directory. +.It Va var_run_enable +.Pq Vt bool +Set to "YES" to enable saving of the +.Pa /var/run +directory strcucture into an mtree file at shutdown and the reload of the +.Pa /var/run +directory structure at boot. +.It Va var_run_autosave +.Pq Vt bool +In some cases it may be undesirable to save +.Pa /var/run +at shutdown. +When set to "NO" +.Pa /var/run +is loaded at reboot but not saved at shutdown. Typically in this scenario +a +.Pa service +.Pa var_run +.Pa save +would be performed to save a copy of the +.Pa /var/run +directory structure once, to be reload during all subsequent reboots. +.It Va var_run_mtree +.Pq Vt str +Where to save the +.Pa /var/run +mtree. The default location is +.Pa /var/db/mtree/BSD.var-run.mtree . .It Va local_startup .Pq Vt str List of directories to search for startup script files.