1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Linux Additions Guest Additions service daemon init script.
|
---|
4 | #
|
---|
5 | # Copyright (C) 2006-2012 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 Additions service
|
---|
18 | #
|
---|
19 | ### BEGIN INIT INFO
|
---|
20 | # Provides: vboxadd-service
|
---|
21 | # Required-Start: vboxadd
|
---|
22 | # Required-Stop: vboxadd
|
---|
23 | # Default-Start: 2 3 4 5
|
---|
24 | # Default-Stop: 0 1 6
|
---|
25 | # Description: VirtualBox Additions Service
|
---|
26 | ### END INIT INFO
|
---|
27 |
|
---|
28 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
29 |
|
---|
30 | system=unknown
|
---|
31 | if [ -f /etc/redhat-release ]; then
|
---|
32 | system=redhat
|
---|
33 | PIDFILE="/var/lock/subsys/vboxadd-service"
|
---|
34 | elif [ -f /etc/SuSE-release ]; then
|
---|
35 | system=suse
|
---|
36 | PIDFILE="/var/run/vboxadd-service"
|
---|
37 | elif [ -f /etc/debian_version ]; then
|
---|
38 | system=debian
|
---|
39 | PIDFILE="/var/run/vboxadd-service.pid"
|
---|
40 | elif [ -f /etc/gentoo-release ]; then
|
---|
41 | system=gentoo
|
---|
42 | PIDFILE="/var/run/vboxadd-service"
|
---|
43 | elif [ -f /etc/slackware-version ]; then
|
---|
44 | system=slackware
|
---|
45 | PIDFILE="/var/run/vboxadd-service"
|
---|
46 | elif [ -f /etc/lfs-release ]; then
|
---|
47 | system=lfs
|
---|
48 | PIDFILE="/var/run/vboxadd-service.pid"
|
---|
49 | else
|
---|
50 | system=other
|
---|
51 | if [ -d /var/run -a -w /var/run ]; then
|
---|
52 | PIDFILE="/var/run/vboxadd-service"
|
---|
53 | fi
|
---|
54 | fi
|
---|
55 |
|
---|
56 | if [ "$system" = "redhat" ]; then
|
---|
57 | . /etc/init.d/functions
|
---|
58 | fail_msg() {
|
---|
59 | echo_failure
|
---|
60 | echo
|
---|
61 | }
|
---|
62 |
|
---|
63 | succ_msg() {
|
---|
64 | echo_success
|
---|
65 | echo
|
---|
66 | }
|
---|
67 |
|
---|
68 | begin() {
|
---|
69 | echo -n "$1"
|
---|
70 | }
|
---|
71 | fi
|
---|
72 |
|
---|
73 | if [ "$system" = "suse" ]; then
|
---|
74 | . /etc/rc.status
|
---|
75 | daemon() {
|
---|
76 | startproc ${1+"$@"}
|
---|
77 | }
|
---|
78 |
|
---|
79 | fail_msg() {
|
---|
80 | rc_failed 1
|
---|
81 | rc_status -v
|
---|
82 | }
|
---|
83 |
|
---|
84 | succ_msg() {
|
---|
85 | rc_reset
|
---|
86 | rc_status -v
|
---|
87 | }
|
---|
88 |
|
---|
89 | begin() {
|
---|
90 | echo -n "$1"
|
---|
91 | }
|
---|
92 | fi
|
---|
93 |
|
---|
94 | if [ "$system" = "debian" ]; then
|
---|
95 | daemon() {
|
---|
96 | start-stop-daemon --start --exec $1 -- $2 $3
|
---|
97 | }
|
---|
98 |
|
---|
99 | killproc() {
|
---|
100 | start-stop-daemon --stop --retry 2 --exec $@
|
---|
101 | }
|
---|
102 |
|
---|
103 | fail_msg() {
|
---|
104 | echo " ...fail!"
|
---|
105 | }
|
---|
106 |
|
---|
107 | succ_msg() {
|
---|
108 | echo " ...done."
|
---|
109 | }
|
---|
110 |
|
---|
111 | begin() {
|
---|
112 | echo -n "$1"
|
---|
113 | }
|
---|
114 | fi
|
---|
115 |
|
---|
116 | if [ "$system" = "gentoo" ]; then
|
---|
117 | if [ -f /sbin/functions.sh ]; then
|
---|
118 | . /sbin/functions.sh
|
---|
119 | elif [ -f /etc/init.d/functions.sh ]; then
|
---|
120 | . /etc/init.d/functions.sh
|
---|
121 | fi
|
---|
122 | daemon() {
|
---|
123 | start-stop-daemon --start --exec $1 -- $2 $3
|
---|
124 | }
|
---|
125 |
|
---|
126 | killproc() {
|
---|
127 | start-stop-daemon --stop --retry 2 --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" = "slackware" -o "$system" = "other" ]; then
|
---|
148 | daemon() {
|
---|
149 | $1 $2 $3
|
---|
150 | }
|
---|
151 |
|
---|
152 | killproc() {
|
---|
153 | killall $1
|
---|
154 | rm -f $PIDFILE
|
---|
155 | }
|
---|
156 |
|
---|
157 | fail_msg() {
|
---|
158 | echo " ...fail!"
|
---|
159 | }
|
---|
160 |
|
---|
161 | succ_msg() {
|
---|
162 | echo " ...done."
|
---|
163 | }
|
---|
164 |
|
---|
165 | begin() {
|
---|
166 | echo -n "$1"
|
---|
167 | }
|
---|
168 |
|
---|
169 | fi
|
---|
170 |
|
---|
171 | if [ "$system" = "lfs" ]; then
|
---|
172 | . /etc/rc.d/init.d/functions
|
---|
173 | daemon() {
|
---|
174 | loadproc $1 $2 $3
|
---|
175 | }
|
---|
176 |
|
---|
177 | fail_msg() {
|
---|
178 | echo_failure
|
---|
179 | }
|
---|
180 |
|
---|
181 | succ_msg() {
|
---|
182 | echo_ok
|
---|
183 | }
|
---|
184 |
|
---|
185 | begin() {
|
---|
186 | echo $1
|
---|
187 | }
|
---|
188 |
|
---|
189 | status() {
|
---|
190 | statusproc $1
|
---|
191 | }
|
---|
192 | fi
|
---|
193 |
|
---|
194 | binary=/usr/sbin/VBoxService
|
---|
195 |
|
---|
196 | testbinary() {
|
---|
197 | test -x "$binary" || {
|
---|
198 | echo "Cannot run $binary"
|
---|
199 | exit 1
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | vboxaddrunning() {
|
---|
204 | lsmod | grep -q "vboxguest[^_-]"
|
---|
205 | }
|
---|
206 |
|
---|
207 | start() {
|
---|
208 | if ! test -f $PIDFILE; then
|
---|
209 | begin "Starting VirtualBox Guest Addition service ";
|
---|
210 | vboxaddrunning || {
|
---|
211 | echo "VirtualBox Additions module not loaded!"
|
---|
212 | exit 1
|
---|
213 | }
|
---|
214 | testbinary
|
---|
215 | daemon $binary --pidfile $PIDFILE > /dev/null
|
---|
216 | RETVAL=$?
|
---|
217 | succ_msg
|
---|
218 | fi
|
---|
219 | return $RETVAL
|
---|
220 | }
|
---|
221 |
|
---|
222 | stop() {
|
---|
223 | if test -f $PIDFILE; then
|
---|
224 | begin "Stopping VirtualBox Guest Addition service ";
|
---|
225 | killproc $binary
|
---|
226 | RETVAL=$?
|
---|
227 | if ! pidof VBoxService > /dev/null 2>&1; then
|
---|
228 | rm -f $PIDFILE
|
---|
229 | succ_msg
|
---|
230 | else
|
---|
231 | fail_msg
|
---|
232 | fi
|
---|
233 | fi
|
---|
234 | return $RETVAL
|
---|
235 | }
|
---|
236 |
|
---|
237 | restart() {
|
---|
238 | stop && start
|
---|
239 | }
|
---|
240 |
|
---|
241 | status() {
|
---|
242 | echo -n "Checking for VBoxService"
|
---|
243 | if [ -f $PIDFILE ]; then
|
---|
244 | echo " ...running"
|
---|
245 | else
|
---|
246 | echo " ...not running"
|
---|
247 | fi
|
---|
248 | }
|
---|
249 |
|
---|
250 | case "$1" in
|
---|
251 | start)
|
---|
252 | start
|
---|
253 | ;;
|
---|
254 | stop)
|
---|
255 | stop
|
---|
256 | ;;
|
---|
257 | restart)
|
---|
258 | restart
|
---|
259 | ;;
|
---|
260 | status)
|
---|
261 | status
|
---|
262 | ;;
|
---|
263 | setup)
|
---|
264 | ;;
|
---|
265 | cleanup)
|
---|
266 | ;;
|
---|
267 | *)
|
---|
268 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
269 | exit 1
|
---|
270 | esac
|
---|
271 |
|
---|
272 | exit $RETVAL
|
---|