1 | #!/sbin/sh
|
---|
2 | # $Id: smf-vboxballoonctrl.sh 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
3 |
|
---|
4 | #
|
---|
5 | # Copyright (C) 2008-2023 Oracle and/or its affiliates.
|
---|
6 | #
|
---|
7 | # This file is part of VirtualBox base platform packages, as
|
---|
8 | # available from https://www.virtualbox.org.
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistribute it and/or
|
---|
11 | # modify it under the terms of the GNU General Public License
|
---|
12 | # as published by the Free Software Foundation, in version 3 of the
|
---|
13 | # License.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful, but
|
---|
16 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | # General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
22 | #
|
---|
23 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
24 | #
|
---|
25 |
|
---|
26 | #
|
---|
27 | # smf-vboxballoonctrl method
|
---|
28 | #
|
---|
29 | # Argument is the method name (start, stop, ...)
|
---|
30 |
|
---|
31 | . /lib/svc/share/smf_include.sh
|
---|
32 |
|
---|
33 | VW_OPT="$1"
|
---|
34 | VW_EXIT=0
|
---|
35 |
|
---|
36 | case $VW_OPT in
|
---|
37 | start)
|
---|
38 | if [ ! -f /opt/VirtualBox/VBoxBalloonCtrl ]; then
|
---|
39 | echo "ERROR: /opt/VirtualBox/VBoxBalloonCtrl does not exist."
|
---|
40 | return $SMF_EXIT_ERR_CONFIG
|
---|
41 | fi
|
---|
42 |
|
---|
43 | if [ ! -x /opt/VirtualBox/VBoxBalloonCtrl ]; then
|
---|
44 | echo "ERROR: /opt/VirtualBox/VBoxBalloonCtrl is not executable."
|
---|
45 | return $SMF_EXIT_ERR_CONFIG
|
---|
46 | fi
|
---|
47 |
|
---|
48 | # Get svc configuration
|
---|
49 | VBOXWATCHDOG_USER=`/usr/bin/svcprop -p config/user $SMF_FMRI 2>/dev/null`
|
---|
50 | [ $? != 0 ] && VBOXWATCHDOG_USER=
|
---|
51 | VBOXWATCHDOG_BALLOON_INTERVAL=`/usr/bin/svcprop -p config/balloon_interval $SMF_FMRI 2>/dev/null`
|
---|
52 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_INTERVAL=
|
---|
53 | VBOXWATCHDOG_BALLOON_INCREMENT=`/usr/bin/svcprop -p config/balloon_increment $SMF_FMRI 2>/dev/null`
|
---|
54 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_INCREMENT=
|
---|
55 | VBOXWATCHDOG_BALLOON_DECREMENT=`/usr/bin/svcprop -p config/balloon_decrement $SMF_FMRI 2>/dev/null`
|
---|
56 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_DECREMENT=
|
---|
57 | VBOXWATCHDOG_BALLOON_LOWERLIMIT=`/usr/bin/svcprop -p config/balloon_lowerlimit $SMF_FMRI 2>/dev/null`
|
---|
58 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_LOWERLIMIT=
|
---|
59 | VBOXWATCHDOG_BALLOON_SAFETYMARGIN=`/usr/bin/svcprop -p config/balloon_safetymargin $SMF_FMRI 2>/dev/null`
|
---|
60 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_SAFETYMARGIN=
|
---|
61 | VBOXWATCHDOG_ROTATE=`/usr/bin/svcprop -p config/logrotate $SMF_FMRI 2>/dev/null`
|
---|
62 | [ $? != 0 ] && VBOXWATCHDOG_ROTATE=
|
---|
63 | VBOXWATCHDOG_LOGSIZE=`/usr/bin/svcprop -p config/logsize $SMF_FMRI 2>/dev/null`
|
---|
64 | [ $? != 0 ] && VBOXWATCHDOG_LOGSIZE=
|
---|
65 | VBOXWATCHDOG_LOGINTERVAL=`/usr/bin/svcprop -p config/loginterval $SMF_FMRI 2>/dev/null`
|
---|
66 | [ $? != 0 ] && VBOXWATCHDOG_LOGINTERVAL=
|
---|
67 |
|
---|
68 | # Handle legacy parameters, do not add any further ones unless absolutely necessary.
|
---|
69 | if [ -z "$VBOXWATCHDOG_BALLOON_INTERVAL" ]; then
|
---|
70 | VBOXWATCHDOG_BALLOON_INTERVAL=`/usr/bin/svcprop -p config/interval $SMF_FMRI 2>/dev/null`
|
---|
71 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_INTERVAL=
|
---|
72 | fi
|
---|
73 | if [ -z "$VBOXWATCHDOG_BALLOON_INCREMENT" ]; then
|
---|
74 | VBOXWATCHDOG_BALLOON_INCREMENT=`/usr/bin/svcprop -p config/increment $SMF_FMRI 2>/dev/null`
|
---|
75 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_INCREMENT=
|
---|
76 | fi
|
---|
77 | if [ -z "$VBOXWATCHDOG_BALLOON_DECREMENT" ]; then
|
---|
78 | VBOXWATCHDOG_BALLOON_DECREMENT=`/usr/bin/svcprop -p config/decrement $SMF_FMRI 2>/dev/null`
|
---|
79 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_DECREMENT=
|
---|
80 | fi
|
---|
81 | if [ -z "$VBOXWATCHDOG_BALLOON_LOWERLIMIT" ]; then
|
---|
82 | VBOXWATCHDOG_BALLOON_LOWERLIMIT=`/usr/bin/svcprop -p config/lowerlimit $SMF_FMRI 2>/dev/null`
|
---|
83 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_LOWERLIMIT=
|
---|
84 | fi
|
---|
85 | if [ -z "$VBOXWATCHDOG_BALLOON_SAFETYMARGIN" ]; then
|
---|
86 | VBOXWATCHDOG_BALLOON_SAFETYMARGIN=`/usr/bin/svcprop -p config/safetymargin $SMF_FMRI 2>/dev/null`
|
---|
87 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_SAFETYMARGIN=
|
---|
88 | fi
|
---|
89 |
|
---|
90 | # Provide sensible defaults
|
---|
91 | [ -z "$VBOXWATCHDOG_USER" ] && VBOXWATCHDOG_USER=root
|
---|
92 |
|
---|
93 | # Assemble the parameter list
|
---|
94 | PARAMS="--background"
|
---|
95 | [ -n "$VBOXWATCHDOG_BALLOON_INTERVAL" ] && PARAMS="$PARAMS --balloon-interval \"$VBOXWATCHDOG_BALLOON_INTERVAL\""
|
---|
96 | [ -n "$VBOXWATCHDOG_BALLOON_INCREMENT" ] && PARAMS="$PARAMS --balloon-inc \"$VBOXWATCHDOG_BALLOON_INCREMENT\""
|
---|
97 | [ -n "$VBOXWATCHDOG_BALLOON_DECREMENT" ] && PARAMS="$PARAMS --balloon-dec \"$VBOXWATCHDOG_BALLOON_DECREMENT\""
|
---|
98 | [ -n "$VBOXWATCHDOG_BALLOON_LOWERLIMIT" ] && PARAMS="$PARAMS --balloon-lower-limit \"$VBOXWATCHDOG_BALLOON_LOWERLIMIT\""
|
---|
99 | [ -n "$VBOXWATCHDOG_BALLOON_SAFETYMARGIN" ] && PARAMS="$PARAMS --balloon-safety-margin \"$VBOXWATCHDOG_BALLOON_SAFETYMARGIN\""
|
---|
100 | [ -n "$VBOXWATCHDOG_ROTATE" ] && PARAMS="$PARAMS -R \"$VBOXWATCHDOG_ROTATE\""
|
---|
101 | [ -n "$VBOXWATCHDOG_LOGSIZE" ] && PARAMS="$PARAMS -S \"$VBOXWATCHDOG_LOGSIZE\""
|
---|
102 | [ -n "$VBOXWATCHDOG_LOGINTERVAL" ] && PARAMS="$PARAMS -I \"$VBOXWATCHDOG_LOGINTERVAL\""
|
---|
103 |
|
---|
104 | exec su - "$VBOXWATCHDOG_USER" -c "/opt/VirtualBox/VBoxBalloonCtrl $PARAMS"
|
---|
105 |
|
---|
106 | VW_EXIT=$?
|
---|
107 | if [ $VW_EXIT != 0 ]; then
|
---|
108 | echo "VBoxBalloonCtrl failed with $VW_EXIT."
|
---|
109 | VW_EXIT=1
|
---|
110 | fi
|
---|
111 | ;;
|
---|
112 | stop)
|
---|
113 | # Kill service contract
|
---|
114 | smf_kill_contract $2 TERM 1
|
---|
115 | ;;
|
---|
116 | *)
|
---|
117 | VW_EXIT=$SMF_EXIT_ERR_CONFIG
|
---|
118 | ;;
|
---|
119 | esac
|
---|
120 |
|
---|
121 | exit $VW_EXIT
|
---|