VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/vboxballoonctrl-service.sh@ 58326

Last change on this file since 58326 was 58326, checked in by vboxsync, 9 years ago

Installers/linux: service output clean-up.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1#!/bin/sh
2#
3# VirtualBox watchdog daemon init script.
4#
5# Copyright (C) 2006-2015 Oracle Corporation
6#
7# This file is part of VirtualBox Open Source Edition (OSE), as
8# available from http://www.virtualbox.org. This file is free software;
9# you can redistribute it and/or modify it under the terms of the GNU
10# General Public License (GPL) as published by the Free Software
11# Foundation, in version 2 as it comes in the "COPYING" file of the
12# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14#
15
16# chkconfig: 345 35 65
17# description: VirtualBox watchdog daemon
18#
19### BEGIN INIT INFO
20# Provides: vboxballoonctrl-service
21# Required-Start: vboxdrv
22# Required-Stop: vboxdrv
23# Default-Start: 2 3 4 5
24# Default-Stop: 0 1 6
25# Description: VirtualBox watchdog daemon
26### END INIT INFO
27
28PATH=$PATH:/bin:/sbin:/usr/sbin
29SCRIPTNAME=vboxballoonctrl-service.sh
30
31[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
32
33if [ -n "$INSTALL_DIR" ]; then
34 binary="$INSTALL_DIR/VBoxBalloonCtrl"
35else
36 binary="/usr/lib/virtualbox/VBoxBalloonCtrl"
37fi
38
39# silently exit if the package was uninstalled but not purged,
40# applies to Debian packages only (but shouldn't hurt elsewhere)
41[ ! -f /etc/debian_release -o -x $binary ] || exit 0
42
43[ -r /etc/default/virtualbox ] && . /etc/default/virtualbox
44
45PIDFILE="/var/run/${SCRIPTNAME}"
46
47# Preamble for Gentoo
48if [ "`which $0`" = "/sbin/rc" ]; then
49 shift
50fi
51
52begin_msg()
53{
54 test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
55 logger -t "${SCRIPTNAME}" "${1}."
56}
57
58succ_msg()
59{
60 logger -t "${SCRIPTNAME}" "${1}."
61}
62
63fail_msg()
64{
65 echo "${SCRIPTNAME}: failed: ${1}." >&2
66 logger -t "${SCRIPTNAME}" "failed: ${1}."
67}
68
69start_daemon() {
70 usr="$1"
71 shift
72 su - $usr -c "$*"
73}
74
75killproc() {
76 killall $1
77 rm -f $PIDFILE
78}
79
80if which start-stop-daemon >/dev/null 2>&1; then
81 start_daemon() {
82 usr="$1"
83 shift
84 bin="$1"
85 shift
86 start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
87 }
88
89 killproc() {
90 start-stop-daemon --stop --exec $@
91 }
92fi
93
94vboxdrvrunning() {
95 lsmod | grep -q "vboxdrv[^_-]"
96}
97
98check_single_user() {
99 if [ -n "$2" ]; then
100 fail_msg "VBOXWATCHDOG_USER must not contain multiple users!"
101 exit 1
102 fi
103}
104
105start() {
106 if ! test -f $PIDFILE; then
107 [ -z "$VBOXWATCHDOG_USER" -a -z "$VBOXBALLOONCTRL_USER" ] && exit 0
108 [ -z "$VBOXWATCHDOG_USER" ] && VBOXWATCHDOG_USER="$VBOXBALLOONCTRL_USER"
109 begin_msg "Starting VirtualBox watchdog service" console;
110 check_single_user $VBOXWATCHDOG_USER
111 vboxdrvrunning || {
112 fail_msg "VirtualBox kernel module not loaded!"
113 exit 0
114 }
115 # Handle legacy parameters, do not add any further ones unless absolutely necessary.
116 [ -z "$VBOXWATCHDOG_BALLOON_INTERVAL" -a -n "$VBOXBALLOONCTRL_INTERVAL" ] && VBOXWATCHDOG_BALLOON_INTERVAL="$VBOXBALLOONCTRL_INTERVAL"
117 [ -z "$VBOXWATCHDOG_BALLOON_INCREMENT" -a -n "$VBOXBALLOONCTRL_INCREMENT" ] && VBOXWATCHDOG_BALLOON_INCREMENT="$VBOXBALLOONCTRL_INCREMENT"
118 [ -z "$VBOXWATCHDOG_BALLOON_DECREMENT" -a -n "$VBOXBALLOONCTRL_DECREMENT" ] && VBOXWATCHDOG_BALLOON_DECREMENT="$VBOXBALLOONCTRL_DECREMENT"
119 [ -z "$VBOXWATCHDOG_BALLOON_LOWERLIMIT" -a -n "$VBOXBALLOONCTRL_LOWERLIMIT" ] && VBOXWATCHDOG_BALLOON_LOWERLIMIT="$VBOXBALLOONCTRL_LOWERLIMIT"
120 [ -z "$VBOXWATCHDOG_BALLOON_SAFETYMARGIN" -a -n "$VBOXBALLOONCTRL_SAFETYMARGIN" ] && VBOXWATCHDOG_BALLOON_SAFETYMARGIN="$VBOXBALLOONCTRL_SAFETYMARGIN"
121 [ -z "$VBOXWATCHDOG_ROTATE" -a -n "$VBOXBALLOONCTRL_ROTATE" ] && VBOXWATCHDOG_ROTATE="$VBOXBALLOONCTRL_ROTATE"
122 [ -z "$VBOXWATCHDOG_LOGSIZE" -a -n "$VBOXBALLOONCTRL_LOGSIZE" ] && VBOXWATCHDOG_LOGSIZE="$VBOXBALLOONCTRL_LOGSIZE"
123 [ -z "$VBOXWATCHDOG_LOGINTERVAL" -a -n "$VBOXBALLOONCTRL_LOGINTERVAL" ] && VBOXWATCHDOG_LOGINTERVAL="$VBOXBALLOONCTRL_LOGINTERVAL"
124
125 PARAMS="--background"
126 [ -n "$VBOXWATCHDOG_BALLOON_INTERVAL" ] && PARAMS="$PARAMS --balloon-interval \"$VBOXWATCHDOG_BALLOON_INTERVAL\""
127 [ -n "$VBOXWATCHDOG_BALLOON_INCREMENT" ] && PARAMS="$PARAMS --balloon-inc \"$VBOXWATCHDOG_BALLOON_INCREMENT\""
128 [ -n "$VBOXWATCHDOG_BALLOON_DECREMENT" ] && PARAMS="$PARAMS --balloon-dec \"$VBOXWATCHDOG_BALLOON_DECREMENT\""
129 [ -n "$VBOXWATCHDOG_BALLOON_LOWERLIMIT" ] && PARAMS="$PARAMS --balloon-lower-limit \"$VBOXWATCHDOG_BALLOON_LOWERLIMIT\""
130 [ -n "$VBOXWATCHDOG_BALLOON_SAFETYMARGIN" ] && PARAMS="$PARAMS --balloon-safety-margin \"$VBOXWATCHDOG_BALLOON_SAFETYMARGIN\""
131 [ -n "$VBOXWATCHDOG_ROTATE" ] && PARAMS="$PARAMS -R \"$VBOXWATCHDOG_ROTATE\""
132 [ -n "$VBOXWATCHDOG_LOGSIZE" ] && PARAMS="$PARAMS -S \"$VBOXWATCHDOG_LOGSIZE\""
133 [ -n "$VBOXWATCHDOG_LOGINTERVAL" ] && PARAMS="$PARAMS -I \"$VBOXWATCHDOG_LOGINTERVAL\""
134 # prevent inheriting this setting to VBoxSVC
135 unset VBOX_RELEASE_LOG_DEST
136 start_daemon $VBOXWATCHDOG_USER $binary $PARAMS > /dev/null 2>&1
137 # ugly: wait until the final process has forked
138 sleep .1
139 PID=`pidof $binary 2>/dev/null`
140 if [ -n "$PID" ]; then
141 echo "$PID" > $PIDFILE
142 RETVAL=0
143 succ_msg "VirtualBox watchdog service started"
144 else
145 RETVAL=1
146 fail_msg "VirtualBox watchdog service failed to start"
147 fi
148 fi
149 return $RETVAL
150}
151
152stop() {
153 if test -f $PIDFILE; then
154 begin_msg "Stopping VirtualBox watchdog service" console;
155 killproc $binary
156 RETVAL=$?
157 if ! pidof $binary > /dev/null 2>&1; then
158 rm -f $PIDFILE
159 succ_msg "VirtualBox watchdog service stopped"
160 else
161 fail_msg "VirtualBox watchdog service failed to stop"
162 fi
163 fi
164 return $RETVAL
165}
166
167restart() {
168 stop && start
169}
170
171status() {
172 echo -n "Checking for VBox watchdog service"
173 if [ -f $PIDFILE ]; then
174 echo " ...running"
175 else
176 echo " ...not running"
177 fi
178}
179
180case "$1" in
181start)
182 start
183 ;;
184stop)
185 stop
186 ;;
187restart)
188 restart
189 ;;
190force-reload)
191 restart
192 ;;
193status)
194 status
195 ;;
196setup)
197 ;;
198cleanup)
199 ;;
200*)
201 echo "Usage: $0 {start|stop|restart|status}"
202 exit 1
203esac
204
205exit $RETVAL
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette