xref: /freebsd/libexec/rc/rc.d/var_run (revision ed9712f8943573136fa92a0e61c8e7c10952eeb0)
1#!/bin/sh
2
3# PROVIDE: var_run
4# REQUIRE: mountcritlocal
5# BEFORE: cleanvar
6# KEYWORD: shutdown
7
8. /etc/rc.subr
9
10name=var_run
11rcvar=var_run_enable
12extra_commands="load save"
13start_cmd="_var_run_start"
14load_cmd="_var_run_load"
15save_cmd="_var_run_save"
16stop_cmd="_var_run_stop"
17
18load_rc_config $name
19
20# doesn't make sense to run in a svcj: config setting
21var_run_svcj="NO"
22
23_var_run_load() {
24	if [ -f "${var_run_mtree}" ] ; then
25		mtree -U -i -q -f "${var_run_mtree}" -p /var/run > /dev/null
26	fi
27}
28
29_var_run_save() {
30	if ! [ -d "${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	if df -ttmpfs /var/run > /dev/null 2>&1; then
38		_var_run_load
39	fi
40}
41
42_var_run_stop() {
43	if checkyesno var_run_autosave; then
44		if df -ttmpfs /var/run > /dev/null 2>&1; then
45			_var_run_save
46		fi
47	fi
48}
49
50run_rc_command "$1"
51