VirtualBox

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

Last change on this file since 69498 was 69498, checked in by vboxsync, 7 years ago

backed out r118835 as it incorrectly updated the 'This file is based on' file headers.

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