rc.d: Add mounttmpfs to support tmpfs at /var/run and /tmp
[dragonfly.git] / etc / rc.d / accounting
1 #!/bin/sh
2 #
3 # $FreeBSD: head/etc/rc.d/accounting 234927 2012-05-02 14:25:39Z jhb $
4 #
5
6 # PROVIDE: accounting
7 # REQUIRE: mountcritremote
8 # BEFORE: DAEMON
9 # KEYWORD: nojail
10
11 . /etc/rc.subr
12
13 name="accounting"
14 rcvar="accounting_enable"
15 accounting_command="/usr/sbin/accton"
16 accounting_file="/var/account/acct"
17
18 extra_commands="rotate_log"
19
20 start_cmd="accounting_start"
21 stop_cmd="accounting_stop"
22 rotate_log_cmd="accounting_rotate_log"
23
24 accounting_start()
25 {
26         local _dir
27
28         _dir="${accounting_file%/*}"
29         if [ ! -d "$_dir" ]; then
30                 if ! mkdir -p "$_dir"; then
31                         err 1 "Could not create $_dir."
32                 fi
33         fi
34
35         if [ ! -e "$accounting_file" ]; then
36                 echo -n "Creating accounting file ${accounting_file}"
37                 touch "$accounting_file"
38                 echo '.'
39         fi
40         chmod 644 "$accounting_file"
41
42         echo "Turning on accounting."
43         ${accounting_command} ${accounting_file}
44 }
45
46 accounting_stop()
47 {
48         echo "Turning off accounting."
49         ${accounting_command}
50 }
51
52 accounting_rotate_log()
53 {
54         local _dir _file
55
56         _dir="${accounting_file%/*}"
57         cd $_dir
58
59         if checkyesno accounting_enable; then
60                 _file=`mktemp newacct-XXXXX`
61                 chmod 644 $_file
62                 ${accounting_command} ${_dir}/${_file}
63         fi
64
65         mv ${accounting_file} ${accounting_file}.0
66
67         if checkyesno accounting_enable; then
68                 mv $_file ${accounting_file}
69         fi
70 }
71
72 load_rc_config $name
73 run_rc_command "$1"