xref: /freebsd/libexec/rc/rc.d/var_run (revision dda082e0093936517795d386242ff9abcdaeff53)
1#!/bin/sh
2
3# PROVIDE: var_run
4# REQUIRE: mountcritlocal
5# BEFORE: cleanvar
6
7. /etc/rc.subr
8
9name=var_run
10rcvar=var_run_enable
11extra_commands="load save"
12start_cmd="_var_run_start"
13load_cmd="_var_run_load"
14save_cmd="_var_run_save"
15stop_cmd="_var_run_stop"
16
17load_rc_config $name
18
19# Set defaults
20: ${var_run_enable:="NO"}
21: ${var_run_mtree:="/var/db/mtree/BSD.var-run.mtree"}
22: ${var_run_autosave:="YES"}
23
24_var_run_load() {
25	test -f ${var_run_mtree} &&
26		mtree -U -i -q -f ${var_run_mtree} -p /var/run > /dev/null
27}
28
29_var_run_save() {
30	if [ ! -d $(dirname ${var_run_mtree}) ]; then
31		mkdir -p ${var_run_mtree}
32	fi
33	mtree -dcbj -p /var/run > ${var_run_mtree}
34}
35
36_var_run_start() {
37	df -ttmpfs /var/run > /dev/null 2>&1 &&
38		_var_run_load
39}
40
41_var_run_stop() {
42	df -ttmpfs /var/run > /dev/null 2>&1 &&
43		checkyesno var_run_autosave &&
44			_var_run_save
45}
46
47run_rc_command "$1"
48