Page MenuHomeFreeBSD

libexec/rc: Add var_run rc script
ClosedPublic

Authored by cy on Aug 28 2022, 1:00 PM.

Details

Summary

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.

Test Plan

Running here

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

cy requested review of this revision.Aug 28 2022, 1:00 PM

This should probably be documented somewhere.

I wonder if users who are interested in preserving /var/run across reboots shouldn't simply use a persistent filesystem rather than tmpfs though ...

libexec/rc/rc.d/var_run
5

Why does this require zfs? It looks like this will work fine on other filesystems too.

(Incidentally: what does kq in the name refer to?)

This should probably be documented somewhere.

I wonder if users who are interested in preserving /var/run across reboots shouldn't simply use a persistent filesystem rather than tmpfs though ...

/var/run is already in /var which is persistent on UFS/ZFS. Persistence is the default. This script is there to support those who have added tmpfs /var/run to their fstab making it ephemeral. The problem with ephemeral /var/run is that ports assume that /var/run is persistent. The other alternative is to convince ports maintainers to add mkdirs to their rc scripts and if the pkg doesn't provide an rc script, create one simply to make sure the directory their package needs is in /var/run.

In short, this is to support those who have opted to make their FreeBSD systems non-standard.

Maybe some documentation in the handbook showing how to set this up should a person choose to. But that would be a separate review.

BTW, I did this same thing a week ago to maybe avoid a couple of writes here or there to my new SSD on my laptop. In real terms it probably won't make much difference though.

The use case definitely makes sense!

I think all that's needed is a couple of lines in share/man/man5/rc.conf.5.

Maybe also add this (default NO) to libexec/rc/rc.conf with a one-line comment.

Other than that, this looks good to me. Thank you!

Added man page updates, mtree for /var/db/mtree, and defaults/rc.conf.

Helps to use the correct diff file. Also regenerated with -U99999.

Looks good to me! Thank you.

Last remaining question: why the REQUIRE: zfs? As I understand it, this will only work if zfs_enable="YES". I don't see anything here that would only work on ZFS.

cy marked an inline comment as done.Sep 1 2022, 2:59 AM
cy added inline comments.
libexec/rc/rc.d/var_run
5

It needs all local filesystems.

The kq- is a local thing I put in all local rc-scripts. I thought I had removed all local quirks.

cy marked an inline comment as done.

Removed local quirks I had thought I'd already removed.

REQUIRE and BEFORE are more specific: need mountcrictlocal and must be run before cleanvar because cleanvar touches /var/run.

Perfect! Thanks for the rework. :-)

Reviewed by: philip

This revision is now accepted and ready to land.Sep 1 2022, 3:35 AM
This revision now requires review to proceed.Sep 2 2022, 4:08 PM
gbe added a subscriber: gbe.

LGTM for the man page parts and thanks for working on it.

This revision is now accepted and ready to land.Sep 2 2022, 9:23 PM
share/man/man5/rc.conf.5
479

New Sentence new line, sorry I overlooked it.

cy marked an inline comment as done.Sep 4 2022, 12:53 PM
cy added inline comments.
share/man/man5/rc.conf.5
479

Fixed. Thanks for spotting this.

cy marked an inline comment as done.

Start sentence on a new line.

This revision now requires review to proceed.Sep 4 2022, 12:54 PM
This revision is now accepted and ready to land.Sep 5 2022, 2:54 AM
This revision was automatically updated to reflect the committed changes.