Solved /etc/rc.shutdown.local doesn't save a variable

I'm trying to save the backlight brightness level before shutdown, but it's not saving it. Maybe it's trying to access it too late? How do I do it then?

Here's my rc.shutdown.local (it is executable by all):
Code:
/usr/bin/backlight -f /dev/backlight/backlight0 | /usr/bin/awk '{print $NF}' > /var/db/backlight_level
 
Ok, /etc/rc.shutdown does not call rc.shutdown.local on FreeBSD 14.3? (But we do use rc.local!) Sure looks like it, looking through rc.shutdown. Is there a way to do this without writing a service?
 
Well, this is strange. I put this line
/usr/bin/backlight -f /dev/backlight/backlight0 | /usr/bin/awk '{print $NF}' > /var/db/backlight_level
to save backlight value straight into /etc/rc.shutdown file near the top, after load_rc_config, just to test, and it STILL doesn't save the value. Is this real life?
 
/etc/rc.d/local calls rc.local and rc.shutdown.local:
Ok, then.

The shutdown script doesn't save the value for some reason. I freaking edit /etc/rc.shutdown and it doesn't do it.

Is it because ZFS gets unmounted by the time shutdown scripts get executed? But then I tried to even write a service that would save the value BEFORE filesystems trigger, meaning when that service stopped the filesystem would still be mounted, and it still didn't save the value.
🔍
 
/etc/rc.d/local calls rc.local and rc.shutdown.local:
Ok, then.

The shutdown script doesn't save the value for some reason. I freaking edit /etc/rc.shutdown and it doesn't do it.

Is it because ZFS gets unmounted by the time shutdown scripts get executed? But then I tried to even write a service that would save the value AFTER filesystems trigger, meaning when that service stopped the filesystem would still be mounted, and it still didn't save the value.
🔍
 
Ok, more and more details are coming out.

rc.shutdown is entirely not run when I reboot/shutdown the machine, it seems. When I execute the rc.shutdown manually I see various shutdown messages printed to screen, but I see none of them when I issue "sudo reboot" or "sudo poweroff".

Why would FreeBSD14.3 not run the rc.shutdown script?
 
I suggest you use save-entropy(8)’s /etc/rc.d/random as your blueprint. Thread 100903. You want to save and restore the backlight brightness. This is one “service”. Keeping the logic in two files – rc.local and rc.shutdown.local – is kind of awkward.​
[…] Here's my rc.shutdown.local (it is executable by all): […]
As you know by know /etc/rc.shutdown.local gets sourced by /etc/rc.d/local:​
Bash:
		                . /etc/rc.shutdown.local
It is not necessary to set the executable bit on files that are source’d (the . is shorthand for source), but it doesn’t harm either.​
Code:
/usr/bin/backlight -f /dev/backlight/backlight0 | /usr/bin/awk '{print $NF}' > /var/db/backlight_level
You know backlight(8) has a -q flag, right? And /dev/backlight/backlight0 is the default device anyway.​
[…] Is it because ZFS gets unmounted by the time shutdown scripts get executed? […]
Uhm, no? The scripts aren’t cached in RAM or anything.​
 
Turns out reboot bypasses the orderly shutdown. The "right" way to reboot that engages rc.shutdown is via shutdown -r now.
 
Back
Top