VirtualBox

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

Last change on this file since 57732 was 57732, checked in by vboxsync, 9 years ago

Additions/linux: add .pid extension to the PID file

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
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 . /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 }
192fi
193
194binary=/usr/sbin/VBoxService
195
196testbinary() {
197 test -x "$binary" || {
198 echo "Cannot run $binary"
199 exit 1
200 }
201}
202
203vboxaddrunning() {
204 lsmod | grep -q "vboxguest[^_-]"
205}
206
207start() {
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
222stop() {
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
237restart() {
238 stop && start
239}
240
241status() {
242 echo -n "Checking for VBoxService"
243 if [ -f $PIDFILE ]; then
244 echo " ...running"
245 else
246 echo " ...not running"
247 fi
248}
249
250case "$1" in
251start)
252 start
253 ;;
254stop)
255 stop
256 ;;
257restart)
258 restart
259 ;;
260status)
261 status
262 ;;
263setup)
264 ;;
265cleanup)
266 ;;
267*)
268 echo "Usage: $0 {start|stop|restart|status}"
269 exit 1
270esac
271
272exit $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