aboutsummaryrefslogtreecommitdiff
path: root/emulators/virtualbox-ose-legacy/files/vboxwatchdog.in
blob: c21bc03b35238e9c5e631142173c3e740c3522f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh

# PROVIDE: vboxwatchdog
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf[.local] to enable vboxwatchdog
#
# vboxwatchdog_enable (bool):	Set to "NO" by default.
#				Set it to "YES" to enable vboxwatchdog.
# vboxwatchdog_user (str):	User account to run with.
# vboxwatchdog_flags (str):	Custom flags for VBoxWatchdog.

. /etc/rc.subr

name=vboxwatchdog
rcvar=vboxwatchdog_enable

command="%%VBOXDIR%%/VBoxBalloonCtrl"
pidfile="/var/run/${name}.pid"

start_cmd="${name}_start"

vboxwatchdog_start()
{
	local pid

	HOME=$(/usr/sbin/pw usershow -7 -n "${vboxwatchdog_user}" | /usr/bin/cut -d: -f6)
	pid=$(check_pidfile $pidfile $command)

	if [ -n "${pid}" ]; then
		echo "${name} already running? (pid=${pid})."
		return 1
	fi

	# prevent inheriting this setting to VBoxSVC
	unset VBOX_RELEASE_LOG_DEST

	echo -n "Starting ${name}"
	/usr/bin/install -o ${vboxwatchdog_user} -g %%VBOXGROUP%% -m 644 /dev/null ${pidfile}
	/usr/sbin/daemon -f -p ${pidfile} -u ${vboxwatchdog_user} ${command} ${vboxwatchdog_flags}
	echo '.'
}

load_rc_config $name

: ${vboxwatchdog_enable="NO"}
: ${vboxwatchdog_user="%%VBOXUSER%%"}
: ${vboxwatchdog_flags=""}

run_rc_command "$1"