VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/vboxadd-service.sh@ 36197

Last change on this file since 36197 was 36197, checked in by vboxsync, 14 years ago

Additions/linux/vboxadd-service.sh: when terminating the service with start-stop-daemon, wait up to 2 seconds

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1#!/bin/sh
2#
3# Linux Additions Guest Additions service daemon init script.
4#
5# Copyright (C) 2006-2010 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: 35 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/lock/subsys/vboxadd-service"
37elif [ -f /etc/debian_version ]; then
38 system=debian
39 PIDFILE="/var/run/vboxadd-service"
40elif [ -f /etc/gentoo-release ]; then
41 system=gentoo
42 PIDFILE="/var/run/vboxadd-service"
43elif [ -f /etc/arch-release ]; then
44 system=arch
45 PIDFILE="/var/run/vboxadd-service"
46elif [ -f /etc/slackware-version ]; then
47 system=slackware
48 PIDFILE="/var/run/vboxadd-service"
49elif [ -f /etc/lfs-release ]; then
50 system=lfs
51 PIDFILE="/var/run/vboxadd-service.pid"
52else
53 system=other
54 if [ -d /var/run -a -w /var/run ]; then
55 PIDFILE="/var/run/vboxadd-service"
56 fi
57fi
58
59if [ "$system" = "redhat" ]; then
60 . /etc/init.d/functions
61 fail_msg() {
62 echo_failure
63 echo
64 }
65
66 succ_msg() {
67 echo_success
68 echo
69 }
70
71 begin() {
72 echo -n "$1"
73 }
74fi
75
76if [ "$system" = "suse" ]; then
77 . /etc/rc.status
78 daemon() {
79 startproc ${1+"$@"}
80 }
81
82 fail_msg() {
83 rc_failed 1
84 rc_status -v
85 }
86
87 succ_msg() {
88 rc_reset
89 rc_status -v
90 }
91
92 begin() {
93 echo -n "$1"
94 }
95fi
96
97if [ "$system" = "debian" ]; then
98 daemon() {
99 start-stop-daemon --start --exec $1 -- $2
100 }
101
102 killproc() {
103 start-stop-daemon --stop --retry 2 --exec $@
104 }
105
106 fail_msg() {
107 echo " ...fail!"
108 }
109
110 succ_msg() {
111 echo " ...done."
112 }
113
114 begin() {
115 echo -n "$1"
116 }
117fi
118
119if [ "$system" = "gentoo" ]; then
120 . /sbin/functions.sh
121 daemon() {
122 start-stop-daemon --start --exec $1 -- $2
123 }
124
125 killproc() {
126 start-stop-daemon --stop --retry 2 --exec $@
127 }
128
129 fail_msg() {
130 echo " ...fail!"
131 }
132
133 succ_msg() {
134 echo " ...done."
135 }
136
137 begin() {
138 echo -n "$1"
139 }
140
141 if [ "`which $0`" = "/sbin/rc" ]; then
142 shift
143 fi
144fi
145
146if [ "$system" = "arch" ]; then
147 USECOLOR=yes
148 . /etc/rc.d/functions
149 daemon() {
150 $@
151 test $? -eq 0 && add_daemon rc.`basename $1`
152 }
153
154 killproc() {
155 killall $@
156 rm_daemon `basename $@`
157 }
158
159 fail_msg() {
160 stat_fail
161 }
162
163 succ_msg() {
164 stat_done
165 }
166
167 begin() {
168 stat_busy "$1"
169 }
170
171fi
172
173if [ "$system" = "slackware" ]; then
174 daemon() {
175 $1 $2
176 }
177
178 killproc() {
179 killall $1
180 rm -f $PIDFILE
181 }
182
183 fail_msg() {
184 echo " ...fail!"
185 }
186
187 succ_msg() {
188 echo " ...done."
189 }
190
191 begin() {
192 echo -n "$1"
193 }
194
195fi
196
197if [ "$system" = "lfs" ]; then
198 . /etc/rc.d/init.d/functions
199 daemon() {
200 loadproc $1 $2
201 }
202
203 fail_msg() {
204 echo_failure
205 }
206
207 succ_msg() {
208 echo_ok
209 }
210
211 begin() {
212 echo $1
213 }
214
215 status() {
216 statusproc $1
217 }
218fi
219
220if [ "$system" = "other" ]; then
221 fail_msg() {
222 echo " ...fail!"
223 }
224
225 succ_msg() {
226 echo " ...done."
227 }
228
229 begin() {
230 echo -n "$1"
231 }
232fi
233
234binary=/usr/sbin/VBoxService
235
236testbinary() {
237 test -x "$binary" || {
238 echo "Cannot run $binary"
239 exit 1
240 }
241}
242
243vboxaddrunning() {
244 lsmod | grep -q "vboxguest[^_-]"
245}
246
247start() {
248 if ! test -f $PIDFILE; then
249 begin "Starting VirtualBox Guest Addition service ";
250 vboxaddrunning || {
251 echo "VirtualBox Additions module not loaded!"
252 exit 1
253 }
254 testbinary
255 daemon $binary > /dev/null
256 RETVAL=$?
257 test $RETVAL -eq 0 && echo `pidof VBoxService` > $PIDFILE
258 succ_msg
259 fi
260 return $RETVAL
261}
262
263stop() {
264 if test -f $PIDFILE; then
265 begin "Stopping VirtualBox Guest Addition service ";
266 killproc $binary
267 RETVAL=$?
268 if ! pidof VBoxService > /dev/null 2>&1; then
269 rm -f $PIDFILE
270 succ_msg
271 else
272 fail_msg
273 fi
274 fi
275 return $RETVAL
276}
277
278restart() {
279 stop && start
280}
281
282status() {
283 echo -n "Checking for VBoxService"
284 if [ -f $PIDFILE ]; then
285 echo " ...running"
286 else
287 echo " ...not running"
288 fi
289}
290
291case "$1" in
292start)
293 start
294 ;;
295stop)
296 stop
297 ;;
298restart)
299 restart
300 ;;
301status)
302 status
303 ;;
304setup)
305 ;;
306cleanup)
307 ;;
308*)
309 echo "Usage: $0 {start|stop|restart|status}"
310 exit 1
311esac
312
313exit $RETVAL
Note: See TracBrowser for help on using the repository browser.

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