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# Set defaults 21: ${var_run_enable:="NO"} 22: ${var_run_mtree:="/var/db/mtree/BSD.var-run.mtree"} 23: ${var_run_autosave:="YES"} 24 25_var_run_load() { 26 test -f ${var_run_mtree} && 27 mtree -U -i -q -f ${var_run_mtree} -p /var/run > /dev/null 28} 29 30_var_run_save() { 31 if [ ! -d $(dirname ${var_run_mtree}) ]; then 32 mkdir -p ${var_run_mtree} 33 fi 34 mtree -dcbj -p /var/run > ${var_run_mtree} 35} 36 37_var_run_start() { 38 df -ttmpfs /var/run > /dev/null 2>&1 && 39 _var_run_load 40} 41 42_var_run_stop() { 43 df -ttmpfs /var/run > /dev/null 2>&1 && 44 checkyesno var_run_autosave && 45 _var_run_save 46} 47 48run_rc_command "$1" 49