1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Sun xVM VirtualBox
|
---|
4 | # Linux Additions timesync daemon init script
|
---|
5 | #
|
---|
6 | # Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
17 | # Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
18 | # additional information or have any questions.
|
---|
19 | #
|
---|
20 |
|
---|
21 | # chkconfig: 35 35 56
|
---|
22 | # description: VirtualBox Additions timesync
|
---|
23 | #
|
---|
24 | ### BEGIN INIT INFO
|
---|
25 | # Provides: vboxadd-timesync
|
---|
26 | # Required-Start: vboxadd
|
---|
27 | # Required-Stop: vboxadd
|
---|
28 | # Default-Start: 2 3 4 5
|
---|
29 | # Default-Stop: 0 1 6
|
---|
30 | # Description: VirtualBox Additions timesync
|
---|
31 | ### END INIT INFO
|
---|
32 |
|
---|
33 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
34 |
|
---|
35 | system=unknown
|
---|
36 | if [ -f /etc/redhat-release ]; then
|
---|
37 | system=redhat
|
---|
38 | PIDFILE="/var/lock/subsys/vboxadd-timesync"
|
---|
39 | elif [ -f /etc/SuSE-release ]; then
|
---|
40 | system=suse
|
---|
41 | PIDFILE="/var/lock/subsys/vboxadd-timesync"
|
---|
42 | elif [ -f /etc/debian_version ]; then
|
---|
43 | system=debian
|
---|
44 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
45 | elif [ -f /etc/gentoo-release ]; then
|
---|
46 | system=gentoo
|
---|
47 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
48 | elif [ -f /etc/arch-release ]; then
|
---|
49 | system=arch
|
---|
50 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
51 | elif [ -f /etc/slackware-version ]; then
|
---|
52 | system=slackware
|
---|
53 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
54 | else
|
---|
55 | system=other
|
---|
56 | if [ -d /var/run -a -w /var/run ]; then
|
---|
57 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
58 | fi
|
---|
59 | fi
|
---|
60 |
|
---|
61 | if [ "$system" = "redhat" ]; then
|
---|
62 | . /etc/init.d/functions
|
---|
63 | fail_msg() {
|
---|
64 | echo_failure
|
---|
65 | echo
|
---|
66 | }
|
---|
67 |
|
---|
68 | succ_msg() {
|
---|
69 | echo_success
|
---|
70 | echo
|
---|
71 | }
|
---|
72 |
|
---|
73 | begin() {
|
---|
74 | echo -n "$1"
|
---|
75 | }
|
---|
76 | fi
|
---|
77 |
|
---|
78 | if [ "$system" = "suse" ]; then
|
---|
79 | . /etc/rc.status
|
---|
80 | daemon() {
|
---|
81 | startproc ${1+"$@"}
|
---|
82 | }
|
---|
83 |
|
---|
84 | fail_msg() {
|
---|
85 | rc_failed 1
|
---|
86 | rc_status -v
|
---|
87 | }
|
---|
88 |
|
---|
89 | succ_msg() {
|
---|
90 | rc_reset
|
---|
91 | rc_status -v
|
---|
92 | }
|
---|
93 |
|
---|
94 | begin() {
|
---|
95 | echo -n "$1"
|
---|
96 | }
|
---|
97 | fi
|
---|
98 |
|
---|
99 | if [ "$system" = "debian" ]; then
|
---|
100 | daemon() {
|
---|
101 | start-stop-daemon --start --exec $1 -- $2
|
---|
102 | }
|
---|
103 |
|
---|
104 | killproc() {
|
---|
105 | start-stop-daemon --stop --exec $@
|
---|
106 | }
|
---|
107 |
|
---|
108 | fail_msg() {
|
---|
109 | echo " ...fail!"
|
---|
110 | }
|
---|
111 |
|
---|
112 | succ_msg() {
|
---|
113 | echo " ...done."
|
---|
114 | }
|
---|
115 |
|
---|
116 | begin() {
|
---|
117 | echo -n "$1"
|
---|
118 | }
|
---|
119 | fi
|
---|
120 |
|
---|
121 | if [ "$system" = "gentoo" ]; then
|
---|
122 | . /sbin/functions.sh
|
---|
123 | daemon() {
|
---|
124 | start-stop-daemon --start --exec $1 -- $2
|
---|
125 | }
|
---|
126 |
|
---|
127 | killproc() {
|
---|
128 | start-stop-daemon --stop --exec $@
|
---|
129 | }
|
---|
130 |
|
---|
131 | fail_msg() {
|
---|
132 | echo " ...fail!"
|
---|
133 | }
|
---|
134 |
|
---|
135 | succ_msg() {
|
---|
136 | echo " ...done."
|
---|
137 | }
|
---|
138 |
|
---|
139 | begin() {
|
---|
140 | echo -n "$1"
|
---|
141 | }
|
---|
142 |
|
---|
143 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
144 | shift
|
---|
145 | fi
|
---|
146 | fi
|
---|
147 |
|
---|
148 | if [ "$system" = "arch" ]; then
|
---|
149 | USECOLOR=yes
|
---|
150 | . /etc/rc.d/functions
|
---|
151 | daemon() {
|
---|
152 | $@
|
---|
153 | test $? -eq 0 && add_daemon `basename $1`
|
---|
154 | }
|
---|
155 |
|
---|
156 | killproc() {
|
---|
157 | killall $@
|
---|
158 | rm_daemon `basename $@`
|
---|
159 | }
|
---|
160 |
|
---|
161 | fail_msg() {
|
---|
162 | stat_fail
|
---|
163 | }
|
---|
164 |
|
---|
165 | succ_msg() {
|
---|
166 | stat_done
|
---|
167 | }
|
---|
168 | fi
|
---|
169 |
|
---|
170 | if [ "$system" = "slackware" ]; then
|
---|
171 | daemon() {
|
---|
172 | $1 $2
|
---|
173 | }
|
---|
174 |
|
---|
175 | killproc() {
|
---|
176 | killall $1
|
---|
177 | rm -f $PIDFILE
|
---|
178 | }
|
---|
179 |
|
---|
180 | fail_msg() {
|
---|
181 | echo " ...fail!"
|
---|
182 | }
|
---|
183 |
|
---|
184 | succ_msg() {
|
---|
185 | echo " ...done."
|
---|
186 | }
|
---|
187 |
|
---|
188 | status() {
|
---|
189 | echo -n "Checking for vboxadd-timesync"
|
---|
190 | if [ -f /var/run/$1 ]; then
|
---|
191 | echo " ...running"
|
---|
192 | else
|
---|
193 | echo " ...not running"
|
---|
194 | fi
|
---|
195 | }
|
---|
196 |
|
---|
197 | fi
|
---|
198 |
|
---|
199 | if [ "$system" = "other" ]; then
|
---|
200 | fail_msg() {
|
---|
201 | echo " ...fail!"
|
---|
202 | }
|
---|
203 |
|
---|
204 | succ_msg() {
|
---|
205 | echo " ...done."
|
---|
206 | }
|
---|
207 |
|
---|
208 | begin() {
|
---|
209 | echo -n "$1"
|
---|
210 | }
|
---|
211 | fi
|
---|
212 |
|
---|
213 | binary=/usr/sbin/vboxadd-timesync
|
---|
214 |
|
---|
215 | test -x "$binary" || {
|
---|
216 | echo "Cannot run $binary"
|
---|
217 | exit 1
|
---|
218 | }
|
---|
219 |
|
---|
220 | vboxaddrunning() {
|
---|
221 | lsmod | grep -q "vboxadd[^_-]"
|
---|
222 | }
|
---|
223 |
|
---|
224 | start() {
|
---|
225 | if ! test -f $PIDFILE; then
|
---|
226 | begin "Starting VirtualBox host to guest time synchronization ";
|
---|
227 | vboxaddrunning || {
|
---|
228 | echo "VirtualBox Additions module not loaded!"
|
---|
229 | exit 1
|
---|
230 | }
|
---|
231 | daemon $binary --daemonize
|
---|
232 | RETVAL=$?
|
---|
233 | test $RETVAL -eq 0 && touch $PIDFILE
|
---|
234 | succ_msg
|
---|
235 | fi
|
---|
236 | return $RETVAL
|
---|
237 | }
|
---|
238 |
|
---|
239 | stop() {
|
---|
240 | if test -f $PIDFILE; then
|
---|
241 | begin "Stopping VirtualBox host to guest time synchronisation ";
|
---|
242 | vboxaddrunning || {
|
---|
243 | echo "VirtualBox Additions module not loaded!"
|
---|
244 | exit 1
|
---|
245 | }
|
---|
246 | killproc $binary
|
---|
247 | RETVAL=$?
|
---|
248 | test $RETVAL -eq 0 && rm -f $PIDFILE
|
---|
249 | succ_msg
|
---|
250 | fi
|
---|
251 | return $RETVAL
|
---|
252 | }
|
---|
253 |
|
---|
254 | restart() {
|
---|
255 | stop && start
|
---|
256 | }
|
---|
257 |
|
---|
258 | dmnstatus() {
|
---|
259 | status vboxadd-timesync
|
---|
260 | }
|
---|
261 |
|
---|
262 | case "$1" in
|
---|
263 | start)
|
---|
264 | start
|
---|
265 | ;;
|
---|
266 | stop)
|
---|
267 | stop
|
---|
268 | ;;
|
---|
269 | restart)
|
---|
270 | restart
|
---|
271 | ;;
|
---|
272 | status)
|
---|
273 | dmnstatus
|
---|
274 | ;;
|
---|
275 | *)
|
---|
276 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
277 | exit 1
|
---|
278 | esac
|
---|
279 |
|
---|
280 | exit $RETVAL
|
---|