VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use