1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Sun VirtualBox
|
---|
4 | # Linux Additions Guest Additions service daemon init script.
|
---|
5 | #
|
---|
6 | # Copyright (C) 2006-2009 Oracle Corporation
|
---|
7 | #
|
---|
8 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | # available from http://www.virtualbox.org. This file is free software;
|
---|
10 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | # General Public License (GPL) as published by the Free Software
|
---|
12 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | #
|
---|
16 |
|
---|
17 | # chkconfig: 35 35 65
|
---|
18 | # description: VirtualBox Additions service
|
---|
19 | #
|
---|
20 | ### BEGIN INIT INFO
|
---|
21 | # Provides: vboxadd-service
|
---|
22 | # Required-Start: vboxadd
|
---|
23 | # Required-Stop: vboxadd
|
---|
24 | # Default-Start: 2 3 4 5
|
---|
25 | # Default-Stop: 0 1 6
|
---|
26 | # Description: VirtualBox Additions Service
|
---|
27 | ### END INIT INFO
|
---|
28 |
|
---|
29 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
30 |
|
---|
31 | system=unknown
|
---|
32 | if [ -f /etc/redhat-release ]; then
|
---|
33 | system=redhat
|
---|
34 | PIDFILE="/var/lock/subsys/vboxadd-service"
|
---|
35 | elif [ -f /etc/SuSE-release ]; then
|
---|
36 | system=suse
|
---|
37 | PIDFILE="/var/lock/subsys/vboxadd-service"
|
---|
38 | elif [ -f /etc/debian_version ]; then
|
---|
39 | system=debian
|
---|
40 | PIDFILE="/var/run/vboxadd-service"
|
---|
41 | elif [ -f /etc/gentoo-release ]; then
|
---|
42 | system=gentoo
|
---|
43 | PIDFILE="/var/run/vboxadd-service"
|
---|
44 | elif [ -f /etc/arch-release ]; then
|
---|
45 | system=arch
|
---|
46 | PIDFILE="/var/run/vboxadd-service"
|
---|
47 | elif [ -f /etc/slackware-version ]; then
|
---|
48 | system=slackware
|
---|
49 | PIDFILE="/var/run/vboxadd-service"
|
---|
50 | elif [ -f /etc/lfs-release ]; then
|
---|
51 | system=lfs
|
---|
52 | PIDFILE="/var/run/vboxadd-service.pid"
|
---|
53 | else
|
---|
54 | system=other
|
---|
55 | if [ -d /var/run -a -w /var/run ]; then
|
---|
56 | PIDFILE="/var/run/vboxadd-service"
|
---|
57 | fi
|
---|
58 | fi
|
---|
59 |
|
---|
60 | if [ "$system" = "redhat" ]; then
|
---|
61 | . /etc/init.d/functions
|
---|
62 | fail_msg() {
|
---|
63 | echo_failure
|
---|
64 | echo
|
---|
65 | }
|
---|
66 |
|
---|
67 | succ_msg() {
|
---|
68 | echo_success
|
---|
69 | echo
|
---|
70 | }
|
---|
71 |
|
---|
72 | begin() {
|
---|
73 | echo -n "$1"
|
---|
74 | }
|
---|
75 | fi
|
---|
76 |
|
---|
77 | if [ "$system" = "suse" ]; then
|
---|
78 | . /etc/rc.status
|
---|
79 | daemon() {
|
---|
80 | startproc ${1+"$@"}
|
---|
81 | }
|
---|
82 |
|
---|
83 | fail_msg() {
|
---|
84 | rc_failed 1
|
---|
85 | rc_status -v
|
---|
86 | }
|
---|
87 |
|
---|
88 | succ_msg() {
|
---|
89 | rc_reset
|
---|
90 | rc_status -v
|
---|
91 | }
|
---|
92 |
|
---|
93 | begin() {
|
---|
94 | echo -n "$1"
|
---|
95 | }
|
---|
96 | fi
|
---|
97 |
|
---|
98 | if [ "$system" = "debian" ]; then
|
---|
99 | daemon() {
|
---|
100 | start-stop-daemon --start --exec $1 -- $2
|
---|
101 | }
|
---|
102 |
|
---|
103 | killproc() {
|
---|
104 | start-stop-daemon --stop --exec $@
|
---|
105 | }
|
---|
106 |
|
---|
107 | fail_msg() {
|
---|
108 | echo " ...fail!"
|
---|
109 | }
|
---|
110 |
|
---|
111 | succ_msg() {
|
---|
112 | echo " ...done."
|
---|
113 | }
|
---|
114 |
|
---|
115 | begin() {
|
---|
116 | echo -n "$1"
|
---|
117 | }
|
---|
118 | fi
|
---|
119 |
|
---|
120 | if [ "$system" = "gentoo" ]; then
|
---|
121 | . /sbin/functions.sh
|
---|
122 | daemon() {
|
---|
123 | start-stop-daemon --start --exec $1 -- $2
|
---|
124 | }
|
---|
125 |
|
---|
126 | killproc() {
|
---|
127 | start-stop-daemon --stop --exec $@
|
---|
128 | }
|
---|
129 |
|
---|
130 | fail_msg() {
|
---|
131 | echo " ...fail!"
|
---|
132 | }
|
---|
133 |
|
---|
134 | succ_msg() {
|
---|
135 | echo " ...done."
|
---|
136 | }
|
---|
137 |
|
---|
138 | begin() {
|
---|
139 | echo -n "$1"
|
---|
140 | }
|
---|
141 |
|
---|
142 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
143 | shift
|
---|
144 | fi
|
---|
145 | fi
|
---|
146 |
|
---|
147 | if [ "$system" = "arch" ]; then
|
---|
148 | USECOLOR=yes
|
---|
149 | . /etc/rc.d/functions
|
---|
150 | daemon() {
|
---|
151 | $@
|
---|
152 | test $? -eq 0 && add_daemon rc.`basename $1`
|
---|
153 | }
|
---|
154 |
|
---|
155 | killproc() {
|
---|
156 | killall $@
|
---|
157 | rm_daemon `basename $@`
|
---|
158 | }
|
---|
159 |
|
---|
160 | fail_msg() {
|
---|
161 | stat_fail
|
---|
162 | }
|
---|
163 |
|
---|
164 | succ_msg() {
|
---|
165 | stat_done
|
---|
166 | }
|
---|
167 |
|
---|
168 | begin() {
|
---|
169 | stat_busy "$1"
|
---|
170 | }
|
---|
171 |
|
---|
172 | fi
|
---|
173 |
|
---|
174 | if [ "$system" = "slackware" ]; then
|
---|
175 | daemon() {
|
---|
176 | $1 $2
|
---|
177 | }
|
---|
178 |
|
---|
179 | killproc() {
|
---|
180 | killall $1
|
---|
181 | rm -f $PIDFILE
|
---|
182 | }
|
---|
183 |
|
---|
184 | fail_msg() {
|
---|
185 | echo " ...fail!"
|
---|
186 | }
|
---|
187 |
|
---|
188 | succ_msg() {
|
---|
189 | echo " ...done."
|
---|
190 | }
|
---|
191 |
|
---|
192 | begin() {
|
---|
193 | echo -n "$1"
|
---|
194 | }
|
---|
195 |
|
---|
196 | fi
|
---|
197 |
|
---|
198 | if [ "$system" = "lfs" ]; then
|
---|
199 | . /etc/rc.d/init.d/functions
|
---|
200 | daemon() {
|
---|
201 | loadproc $1 $2
|
---|
202 | }
|
---|
203 |
|
---|
204 | fail_msg() {
|
---|
205 | echo_failure
|
---|
206 | }
|
---|
207 |
|
---|
208 | succ_msg() {
|
---|
209 | echo_ok
|
---|
210 | }
|
---|
211 |
|
---|
212 | begin() {
|
---|
213 | echo $1
|
---|
214 | }
|
---|
215 |
|
---|
216 | status() {
|
---|
217 | statusproc $1
|
---|
218 | }
|
---|
219 | fi
|
---|
220 |
|
---|
221 | if [ "$system" = "other" ]; then
|
---|
222 | fail_msg() {
|
---|
223 | echo " ...fail!"
|
---|
224 | }
|
---|
225 |
|
---|
226 | succ_msg() {
|
---|
227 | echo " ...done."
|
---|
228 | }
|
---|
229 |
|
---|
230 | begin() {
|
---|
231 | echo -n "$1"
|
---|
232 | }
|
---|
233 | fi
|
---|
234 |
|
---|
235 | binary=/usr/sbin/VBoxService
|
---|
236 |
|
---|
237 | testbinary() {
|
---|
238 | test -x "$binary" || {
|
---|
239 | echo "Cannot run $binary"
|
---|
240 | exit 1
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | vboxaddrunning() {
|
---|
245 | lsmod | grep -q "vboxguest[^_-]"
|
---|
246 | }
|
---|
247 |
|
---|
248 | start() {
|
---|
249 | if ! test -f $PIDFILE; then
|
---|
250 | begin "Starting VirtualBox Guest Addition service ";
|
---|
251 | vboxaddrunning || {
|
---|
252 | echo "VirtualBox Additions module not loaded!"
|
---|
253 | exit 1
|
---|
254 | }
|
---|
255 | testbinary
|
---|
256 | daemon $binary > /dev/null
|
---|
257 | RETVAL=$?
|
---|
258 | test $RETVAL -eq 0 && echo `pidof VBoxService` > $PIDFILE
|
---|
259 | succ_msg
|
---|
260 | fi
|
---|
261 | return $RETVAL
|
---|
262 | }
|
---|
263 |
|
---|
264 | stop() {
|
---|
265 | if test -f $PIDFILE; then
|
---|
266 | begin "Stopping VirtualBox Guest Addition service ";
|
---|
267 | vboxaddrunning || {
|
---|
268 | echo "VirtualBox Additions module not loaded!"
|
---|
269 | exit 1
|
---|
270 | }
|
---|
271 | killproc $binary
|
---|
272 | RETVAL=$?
|
---|
273 | test $RETVAL -eq 0 && rm -f $PIDFILE
|
---|
274 | succ_msg
|
---|
275 | fi
|
---|
276 | return $RETVAL
|
---|
277 | }
|
---|
278 |
|
---|
279 | restart() {
|
---|
280 | stop && start
|
---|
281 | }
|
---|
282 |
|
---|
283 | status() {
|
---|
284 | echo -n "Checking for VBoxService"
|
---|
285 | if [ -f $PIDFILE ]; then
|
---|
286 | echo " ...running"
|
---|
287 | else
|
---|
288 | echo " ...not running"
|
---|
289 | fi
|
---|
290 | }
|
---|
291 |
|
---|
292 | case "$1" in
|
---|
293 | start)
|
---|
294 | start
|
---|
295 | ;;
|
---|
296 | stop)
|
---|
297 | stop
|
---|
298 | ;;
|
---|
299 | restart)
|
---|
300 | restart
|
---|
301 | ;;
|
---|
302 | status)
|
---|
303 | status
|
---|
304 | ;;
|
---|
305 | setup)
|
---|
306 | ;;
|
---|
307 | cleanup)
|
---|
308 | ;;
|
---|
309 | *)
|
---|
310 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
311 | exit 1
|
---|
312 | esac
|
---|
313 |
|
---|
314 | exit $RETVAL
|
---|