xref: /freebsd/libexec/rc/rc.d/bgfsck (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: bgfsck
7# REQUIRE: cron devfs syslogd
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="background_fsck"
13desc="Run fsck in background"
14rcvar="background_fsck"
15start_cmd="bgfsck_start"
16start_precmd="bgfsck_start_precmd"
17stop_cmd=":"
18
19bgfsck_start_precmd()
20{
21	if [ $($ID -u) != 0 ]; then
22		err 1 "Must be root."
23	fi
24}
25
26bgfsck_start()
27{
28	: ${background_fsck_delay=0}
29	if [ -n "${rc_force}" ]; then
30		background_fsck_delay=0
31	fi
32	if [ ${background_fsck_delay} -lt 0 ]; then
33		warn "Background file system checks delayed indefinitely"
34		return 0
35	fi
36
37	bgfsck_msg='Starting background file system checks'
38	if [ "${background_fsck_delay}" -gt 0 ]; then
39		bgfsck_msg="${bgfsck_msg} in ${background_fsck_delay} seconds"
40	fi
41	if [ -z "${rc_force}" ]; then
42		check_startmsgs && echo "${bgfsck_msg}."
43	fi
44
45	(sleep ${background_fsck_delay}; nice -4 fsck -B -p) 2>&1 | \
46	    logger -p daemon.notice -t fsck &
47}
48
49load_rc_config $name
50run_rc_command "$1"
51