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