1 | #!/sbin/sh
|
---|
2 | # $Id: smf-vboxballoonctrl.sh 93115 2022-01-01 11:31:46Z vboxsync $
|
---|
3 |
|
---|
4 | #
|
---|
5 | # Copyright (C) 2008-2022 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 | #
|
---|
17 | # smf-vboxballoonctrl method
|
---|
18 | #
|
---|
19 | # Argument is the method name (start, stop, ...)
|
---|
20 |
|
---|
21 | . /lib/svc/share/smf_include.sh
|
---|
22 |
|
---|
23 | VW_OPT="$1"
|
---|
24 | VW_EXIT=0
|
---|
25 |
|
---|
26 | case $VW_OPT in
|
---|
27 | start)
|
---|
28 | if [ ! -f /opt/VirtualBox/VBoxBalloonCtrl ]; then
|
---|
29 | echo "ERROR: /opt/VirtualBox/VBoxBalloonCtrl does not exist."
|
---|
30 | return $SMF_EXIT_ERR_CONFIG
|
---|
31 | fi
|
---|
32 |
|
---|
33 | if [ ! -x /opt/VirtualBox/VBoxBalloonCtrl ]; then
|
---|
34 | echo "ERROR: /opt/VirtualBox/VBoxBalloonCtrl is not executable."
|
---|
35 | return $SMF_EXIT_ERR_CONFIG
|
---|
36 | fi
|
---|
37 |
|
---|
38 | # Get svc configuration
|
---|
39 | VBOXWATCHDOG_USER=`/usr/bin/svcprop -p config/user $SMF_FMRI 2>/dev/null`
|
---|
40 | [ $? != 0 ] && VBOXWATCHDOG_USER=
|
---|
41 | VBOXWATCHDOG_BALLOON_INTERVAL=`/usr/bin/svcprop -p config/balloon_interval $SMF_FMRI 2>/dev/null`
|
---|
42 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_INTERVAL=
|
---|
43 | VBOXWATCHDOG_BALLOON_INCREMENT=`/usr/bin/svcprop -p config/balloon_increment $SMF_FMRI 2>/dev/null`
|
---|
44 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_INCREMENT=
|
---|
45 | VBOXWATCHDOG_BALLOON_DECREMENT=`/usr/bin/svcprop -p config/balloon_decrement $SMF_FMRI 2>/dev/null`
|
---|
46 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_DECREMENT=
|
---|
47 | VBOXWATCHDOG_BALLOON_LOWERLIMIT=`/usr/bin/svcprop -p config/balloon_lowerlimit $SMF_FMRI 2>/dev/null`
|
---|
48 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_LOWERLIMIT=
|
---|
49 | VBOXWATCHDOG_BALLOON_SAFETYMARGIN=`/usr/bin/svcprop -p config/balloon_safetymargin $SMF_FMRI 2>/dev/null`
|
---|
50 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_SAFETYMARGIN=
|
---|
51 | VBOXWATCHDOG_ROTATE=`/usr/bin/svcprop -p config/logrotate $SMF_FMRI 2>/dev/null`
|
---|
52 | [ $? != 0 ] && VBOXWATCHDOG_ROTATE=
|
---|
53 | VBOXWATCHDOG_LOGSIZE=`/usr/bin/svcprop -p config/logsize $SMF_FMRI 2>/dev/null`
|
---|
54 | [ $? != 0 ] && VBOXWATCHDOG_LOGSIZE=
|
---|
55 | VBOXWATCHDOG_LOGINTERVAL=`/usr/bin/svcprop -p config/loginterval $SMF_FMRI 2>/dev/null`
|
---|
56 | [ $? != 0 ] && VBOXWATCHDOG_LOGINTERVAL=
|
---|
57 |
|
---|
58 | # Handle legacy parameters, do not add any further ones unless absolutely necessary.
|
---|
59 | if [ -z "$VBOXWATCHDOG_BALLOON_INTERVAL" ]; then
|
---|
60 | VBOXWATCHDOG_BALLOON_INTERVAL=`/usr/bin/svcprop -p config/interval $SMF_FMRI 2>/dev/null`
|
---|
61 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_INTERVAL=
|
---|
62 | fi
|
---|
63 | if [ -z "$VBOXWATCHDOG_BALLOON_INCREMENT" ]; then
|
---|
64 | VBOXWATCHDOG_BALLOON_INCREMENT=`/usr/bin/svcprop -p config/increment $SMF_FMRI 2>/dev/null`
|
---|
65 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_INCREMENT=
|
---|
66 | fi
|
---|
67 | if [ -z "$VBOXWATCHDOG_BALLOON_DECREMENT" ]; then
|
---|
68 | VBOXWATCHDOG_BALLOON_DECREMENT=`/usr/bin/svcprop -p config/decrement $SMF_FMRI 2>/dev/null`
|
---|
69 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_DECREMENT=
|
---|
70 | fi
|
---|
71 | if [ -z "$VBOXWATCHDOG_BALLOON_LOWERLIMIT" ]; then
|
---|
72 | VBOXWATCHDOG_BALLOON_LOWERLIMIT=`/usr/bin/svcprop -p config/lowerlimit $SMF_FMRI 2>/dev/null`
|
---|
73 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_LOWERLIMIT=
|
---|
74 | fi
|
---|
75 | if [ -z "$VBOXWATCHDOG_BALLOON_SAFETYMARGIN" ]; then
|
---|
76 | VBOXWATCHDOG_BALLOON_SAFETYMARGIN=`/usr/bin/svcprop -p config/safetymargin $SMF_FMRI 2>/dev/null`
|
---|
77 | [ $? != 0 ] && VBOXWATCHDOG_BALLOON_SAFETYMARGIN=
|
---|
78 | fi
|
---|
79 |
|
---|
80 | # Provide sensible defaults
|
---|
81 | [ -z "$VBOXWATCHDOG_USER" ] && VBOXWATCHDOG_USER=root
|
---|
82 |
|
---|
83 | # Assemble the parameter list
|
---|
84 | PARAMS="--background"
|
---|
85 | [ -n "$VBOXWATCHDOG_BALLOON_INTERVAL" ] && PARAMS="$PARAMS --balloon-interval \"$VBOXWATCHDOG_BALLOON_INTERVAL\""
|
---|
86 | [ -n "$VBOXWATCHDOG_BALLOON_INCREMENT" ] && PARAMS="$PARAMS --balloon-inc \"$VBOXWATCHDOG_BALLOON_INCREMENT\""
|
---|
87 | [ -n "$VBOXWATCHDOG_BALLOON_DECREMENT" ] && PARAMS="$PARAMS --balloon-dec \"$VBOXWATCHDOG_BALLOON_DECREMENT\""
|
---|
88 | [ -n "$VBOXWATCHDOG_BALLOON_LOWERLIMIT" ] && PARAMS="$PARAMS --balloon-lower-limit \"$VBOXWATCHDOG_BALLOON_LOWERLIMIT\""
|
---|
89 | [ -n "$VBOXWATCHDOG_BALLOON_SAFETYMARGIN" ] && PARAMS="$PARAMS --balloon-safety-margin \"$VBOXWATCHDOG_BALLOON_SAFETYMARGIN\""
|
---|
90 | [ -n "$VBOXWATCHDOG_ROTATE" ] && PARAMS="$PARAMS -R \"$VBOXWATCHDOG_ROTATE\""
|
---|
91 | [ -n "$VBOXWATCHDOG_LOGSIZE" ] && PARAMS="$PARAMS -S \"$VBOXWATCHDOG_LOGSIZE\""
|
---|
92 | [ -n "$VBOXWATCHDOG_LOGINTERVAL" ] && PARAMS="$PARAMS -I \"$VBOXWATCHDOG_LOGINTERVAL\""
|
---|
93 |
|
---|
94 | exec su - "$VBOXWATCHDOG_USER" -c "/opt/VirtualBox/VBoxBalloonCtrl $PARAMS"
|
---|
95 |
|
---|
96 | VW_EXIT=$?
|
---|
97 | if [ $VW_EXIT != 0 ]; then
|
---|
98 | echo "VBoxBalloonCtrl failed with $VW_EXIT."
|
---|
99 | VW_EXIT=1
|
---|
100 | fi
|
---|
101 | ;;
|
---|
102 | stop)
|
---|
103 | # Kill service contract
|
---|
104 | smf_kill_contract $2 TERM 1
|
---|
105 | ;;
|
---|
106 | *)
|
---|
107 | VW_EXIT=$SMF_EXIT_ERR_CONFIG
|
---|
108 | ;;
|
---|
109 | esac
|
---|
110 |
|
---|
111 | exit $VW_EXIT
|
---|