VirtualBox

Ticket #14733: vboxadd-service

File vboxadd-service, 5.1 KB (added by hykwok, 9 years ago)
Line 
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
28PATH=$PATH:/bin:/sbin:/usr/sbin
29
30system=unknown
31if [ -f /etc/redhat-release ]; then
32 system=redhat
33 PIDFILE="/var/lock/subsys/vboxadd-service"
34elif [ -f /etc/SuSE-release ]; then
35 system=suse
36 PIDFILE="/var/run/vboxadd-service"
37elif [ -f /etc/debian_version ]; then
38 system=debian
39 PIDFILE="/var/run/vboxadd-service.pid"
40elif [ -f /etc/gentoo-release ]; then
41 system=gentoo
42 PIDFILE="/var/run/vboxadd-service"
43elif [ -f /etc/slackware-version ]; then
44 system=slackware
45 PIDFILE="/var/run/vboxadd-service"
46elif [ -f /etc/lfs-release ]; then
47 system=lfs
48 PIDFILE="/var/run/vboxadd-service.pid"
49else
50 system=other
51 if [ -d /var/run -a -w /var/run ]; then
52 PIDFILE="/var/run/vboxadd-service"
53 fi
54fi
55
56if [ "$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 }
71fi
72
73if [ "$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 }
92fi
93
94if [ "$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 }
114fi
115
116if [ "$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
145fi
146
147if [ "$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
169fi
170
171if [ "$system" = "lfs" ]; then
172 if [ -f /lib/lsb/init-functions ]; then
173 . /lib/lsb/init-functions
174 daemon() {
175 start_daemon $1 $2 $3
176 }
177
178 fail_msg() {
179 log_failure_msg
180 }
181
182 succ_msg() {
183 log_success_msg
184 }
185 else
186 . /etc/rc.d/init.d/functions
187 daemon() {
188 loadproc $1 $2 $3
189 }
190
191 fail_msg() {
192 echo_failure
193 }
194
195 succ_msg() {
196 echo_ok
197 }
198 fi
199
200 begin() {
201 echo $1
202 }
203
204 status() {
205 statusproc $1
206 }
207fi
208
209binary=/usr/sbin/VBoxService
210
211testbinary() {
212 test -x "$binary" || {
213 echo "Cannot run $binary"
214 exit 1
215 }
216}
217
218vboxaddrunning() {
219 lsmod | grep -q "vboxguest[^_-]"
220}
221
222start() {
223 if ! test -f $PIDFILE; then
224 begin "Starting VirtualBox Guest Addition service ";
225 vboxaddrunning || {
226 echo "VirtualBox Additions module not loaded!"
227 exit 1
228 }
229 testbinary
230 daemon $binary --pidfile $PIDFILE > /dev/null
231 RETVAL=$?
232 succ_msg
233 fi
234 return $RETVAL
235}
236
237stop() {
238 if test -f $PIDFILE; then
239 begin "Stopping VirtualBox Guest Addition service ";
240 killproc $binary
241 RETVAL=$?
242 if ! pidof VBoxService > /dev/null 2>&1; then
243 rm -f $PIDFILE
244 succ_msg
245 else
246 fail_msg
247 fi
248 fi
249 return $RETVAL
250}
251
252restart() {
253 stop && start
254}
255
256status() {
257 echo -n "Checking for VBoxService"
258 if [ -f $PIDFILE ]; then
259 echo " ...running"
260 else
261 echo " ...not running"
262 fi
263}
264
265case "$1" in
266start)
267 start
268 ;;
269stop)
270 stop
271 ;;
272restart)
273 restart
274 ;;
275status)
276 status
277 ;;
278setup)
279 ;;
280cleanup)
281 ;;
282*)
283 echo "Usage: $0 {start|stop|restart|status}"
284 exit 1
285esac
286
287exit $RETVAL

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy