1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # VirtualBox autostart service init script.
|
---|
4 | #
|
---|
5 | # Copyright (C) 2012-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 autostart service
|
---|
18 | #
|
---|
19 | ### BEGIN INIT INFO
|
---|
20 | # Provides: vboxautostart-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 autostart service
|
---|
26 | ### END INIT INFO
|
---|
27 |
|
---|
28 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
29 |
|
---|
30 | [ -f /etc/debian_release -a -f /lib/lsb/init-functions ] || NOLSB=yes
|
---|
31 | [ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
|
---|
32 |
|
---|
33 | if [ -n "$INSTALL_DIR" ]; then
|
---|
34 | binary="$INSTALL_DIR/VBoxAutostart"
|
---|
35 | else
|
---|
36 | binary="/usr/lib/virtualbox/VBoxAutostart"
|
---|
37 | fi
|
---|
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 |
|
---|
45 | system=unknown
|
---|
46 | if [ -f /etc/redhat-release ]; then
|
---|
47 | system=redhat
|
---|
48 | elif [ -f /etc/SuSE-release ]; then
|
---|
49 | system=suse
|
---|
50 | elif [ -f /etc/debian_version ]; then
|
---|
51 | system=debian
|
---|
52 | elif [ -f /etc/gentoo-release ]; then
|
---|
53 | system=gentoo
|
---|
54 | elif [ -f /etc/slackware-version ]; then
|
---|
55 | system=slackware
|
---|
56 | elif [ -f /etc/lfs-release ]; then
|
---|
57 | system=lfs
|
---|
58 | else
|
---|
59 | system=other
|
---|
60 | fi
|
---|
61 |
|
---|
62 | if [ -z "$NOLSB" ]; then
|
---|
63 | . /lib/lsb/init-functions
|
---|
64 | fail_msg() {
|
---|
65 | echo ""
|
---|
66 | log_failure_msg "$1"
|
---|
67 | }
|
---|
68 | succ_msg() {
|
---|
69 | log_success_msg " done."
|
---|
70 | }
|
---|
71 | begin_msg() {
|
---|
72 | log_daemon_msg "$@"
|
---|
73 | }
|
---|
74 | fi
|
---|
75 |
|
---|
76 | if [ "$system" = "redhat" ]; then
|
---|
77 | . /etc/init.d/functions
|
---|
78 | if [ -n "$NOLSB" ]; then
|
---|
79 | start_daemon() {
|
---|
80 | usr="$1"
|
---|
81 | shift
|
---|
82 | daemon --user $usr $@
|
---|
83 | }
|
---|
84 | fail_msg() {
|
---|
85 | echo_failure
|
---|
86 | echo
|
---|
87 | }
|
---|
88 | succ_msg() {
|
---|
89 | echo_success
|
---|
90 | echo
|
---|
91 | }
|
---|
92 | begin_msg() {
|
---|
93 | echo -n "$1"
|
---|
94 | }
|
---|
95 | fi
|
---|
96 | fi
|
---|
97 |
|
---|
98 | if [ "$system" = "suse" ]; then
|
---|
99 | . /etc/rc.status
|
---|
100 | start_daemon() {
|
---|
101 | usr="$1"
|
---|
102 | shift
|
---|
103 | su - $usr -c "$*"
|
---|
104 | }
|
---|
105 | if [ -n "$NOLSB" ]; then
|
---|
106 | fail_msg() {
|
---|
107 | rc_failed 1
|
---|
108 | rc_status -v
|
---|
109 | }
|
---|
110 | succ_msg() {
|
---|
111 | rc_reset
|
---|
112 | rc_status -v
|
---|
113 | }
|
---|
114 | begin_msg() {
|
---|
115 | echo -n "$1"
|
---|
116 | }
|
---|
117 | fi
|
---|
118 | fi
|
---|
119 |
|
---|
120 | if [ "$system" = "debian" ]; then
|
---|
121 | start_daemon() {
|
---|
122 | usr="$1"
|
---|
123 | shift
|
---|
124 | bin="$1"
|
---|
125 | shift
|
---|
126 | start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
|
---|
127 | }
|
---|
128 | killproc() {
|
---|
129 | start-stop-daemon --stop --exec $@
|
---|
130 | }
|
---|
131 | if [ -n "$NOLSB" ]; then
|
---|
132 | fail_msg() {
|
---|
133 | echo " ...fail!"
|
---|
134 | }
|
---|
135 | succ_msg() {
|
---|
136 | echo " ...done."
|
---|
137 | }
|
---|
138 | begin_msg() {
|
---|
139 | echo -n "$1"
|
---|
140 | }
|
---|
141 | fi
|
---|
142 | fi
|
---|
143 |
|
---|
144 | if [ "$system" = "gentoo" ]; then
|
---|
145 | if [ -f /sbin/functions.sh ]; then
|
---|
146 | . /sbin/functions.sh
|
---|
147 | elif [ -f /etc/init.d/functions.sh ]; then
|
---|
148 | . /etc/init.d/functions.sh
|
---|
149 | fi
|
---|
150 | start_daemon() {
|
---|
151 | usr="$1"
|
---|
152 | shift
|
---|
153 | bin="$1"
|
---|
154 | shift
|
---|
155 | start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
|
---|
156 | }
|
---|
157 | killproc() {
|
---|
158 | start-stop-daemon --stop --exec $@
|
---|
159 | }
|
---|
160 | if [ -n "$NOLSB" ]; then
|
---|
161 | fail_msg() {
|
---|
162 | echo " ...fail!"
|
---|
163 | }
|
---|
164 | succ_msg() {
|
---|
165 | echo " ...done."
|
---|
166 | }
|
---|
167 | begin_msg() {
|
---|
168 | echo -n "$1"
|
---|
169 | }
|
---|
170 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
171 | shift
|
---|
172 | fi
|
---|
173 | fi
|
---|
174 | fi
|
---|
175 |
|
---|
176 | if [ "$system" = "slackware" ]; then
|
---|
177 | killproc() {
|
---|
178 | killall $1
|
---|
179 | rm -f $PIDFILE
|
---|
180 | }
|
---|
181 | if [ -n "$NOLSB" ]; then
|
---|
182 | fail_msg() {
|
---|
183 | echo " ...fail!"
|
---|
184 | }
|
---|
185 | succ_msg() {
|
---|
186 | echo " ...done."
|
---|
187 | }
|
---|
188 | begin_msg() {
|
---|
189 | echo -n "$1"
|
---|
190 | }
|
---|
191 | fi
|
---|
192 | start_daemon() {
|
---|
193 | usr="$1"
|
---|
194 | shift
|
---|
195 | su - $usr -c "$*"
|
---|
196 | }
|
---|
197 | fi
|
---|
198 |
|
---|
199 | if [ "$system" = "lfs" ]; then
|
---|
200 | . /etc/rc.d/init.d/functions
|
---|
201 | if [ -n "$NOLSB" ]; then
|
---|
202 | fail_msg() {
|
---|
203 | echo_failure
|
---|
204 | }
|
---|
205 | succ_msg() {
|
---|
206 | echo_ok
|
---|
207 | }
|
---|
208 | begin_msg() {
|
---|
209 | echo $1
|
---|
210 | }
|
---|
211 | fi
|
---|
212 | start_daemon() {
|
---|
213 | usr="$1"
|
---|
214 | shift
|
---|
215 | su - $usr -c "$*"
|
---|
216 | }
|
---|
217 | status() {
|
---|
218 | statusproc $1
|
---|
219 | }
|
---|
220 | fi
|
---|
221 |
|
---|
222 | if [ "$system" = "other" ]; then
|
---|
223 | if [ -n "$NOLSB" ]; then
|
---|
224 | fail_msg() {
|
---|
225 | echo " ...fail!"
|
---|
226 | }
|
---|
227 | succ_msg() {
|
---|
228 | echo " ...done."
|
---|
229 | }
|
---|
230 | begin_msg() {
|
---|
231 | echo -n "$1"
|
---|
232 | }
|
---|
233 | fi
|
---|
234 | fi
|
---|
235 |
|
---|
236 | vboxdrvrunning() {
|
---|
237 | lsmod | grep -q "vboxdrv[^_-]"
|
---|
238 | }
|
---|
239 |
|
---|
240 | start() {
|
---|
241 | [ -z "$VBOXAUTOSTART_DB" ] && exit 0
|
---|
242 | [ -z "$VBOXAUTOSTART_CONFIG" ] && exit 0
|
---|
243 | begin_msg "Starting VirtualBox VMs configured for autostart";
|
---|
244 | vboxdrvrunning || {
|
---|
245 | fail_msg "VirtualBox kernel module not loaded!"
|
---|
246 | exit 0
|
---|
247 | }
|
---|
248 | PARAMS="--background --start --config $VBOXAUTOSTART_CONFIG"
|
---|
249 |
|
---|
250 | # prevent inheriting this setting to VBoxSVC
|
---|
251 | unset VBOX_RELEASE_LOG_DEST
|
---|
252 |
|
---|
253 | for user in `ls $VBOXAUTOSTART_DB/*.start`
|
---|
254 | do
|
---|
255 | start_daemon `basename $user | sed -ne "s/\(.*\).start/\1/p"` $binary $PARAMS > /dev/null 2>&1
|
---|
256 | done
|
---|
257 |
|
---|
258 | return $RETVAL
|
---|
259 | }
|
---|
260 |
|
---|
261 | stop() {
|
---|
262 | [ -z "$VBOXAUTOSTART_DB" ] && exit 0
|
---|
263 | [ -z "$VBOXAUTOSTART_CONFIG" ] && exit 0
|
---|
264 |
|
---|
265 | PARAMS="--stop --config $VBOXAUTOSTART_CONFIG"
|
---|
266 |
|
---|
267 | # prevent inheriting this setting to VBoxSVC
|
---|
268 | unset VBOX_RELEASE_LOG_DEST
|
---|
269 |
|
---|
270 | for user in `ls $VBOXAUTOSTART_DB/*.stop`
|
---|
271 | do
|
---|
272 | start_daemon `basename $user | sed -ne "s/\(.*\).stop/\1/p"` $binary $PARAMS > /dev/null 2>&1
|
---|
273 | done
|
---|
274 |
|
---|
275 | return $RETVAL
|
---|
276 | }
|
---|
277 |
|
---|
278 | case "$1" in
|
---|
279 | start)
|
---|
280 | start
|
---|
281 | ;;
|
---|
282 | stop)
|
---|
283 | stop
|
---|
284 | ;;
|
---|
285 | *)
|
---|
286 | echo "Usage: $0 {start|stop}"
|
---|
287 | exit 1
|
---|
288 | esac
|
---|
289 |
|
---|
290 | exit $RETVAL
|
---|