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/slackware-version ]; then
|
---|
49 | system=slackware
|
---|
50 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
51 | else
|
---|
52 | system=other
|
---|
53 | if [ -d /var/run -a -w /var/run ]; then
|
---|
54 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
55 | fi
|
---|
56 | fi
|
---|
57 |
|
---|
58 | if [ "$system" = "redhat" ]; then
|
---|
59 | . /etc/init.d/functions
|
---|
60 | fail_msg() {
|
---|
61 | echo_failure
|
---|
62 | echo
|
---|
63 | }
|
---|
64 |
|
---|
65 | succ_msg() {
|
---|
66 | echo_success
|
---|
67 | echo
|
---|
68 | }
|
---|
69 | fi
|
---|
70 |
|
---|
71 | if [ "$system" = "suse" ]; then
|
---|
72 | . /etc/rc.status
|
---|
73 | daemon() {
|
---|
74 | startproc ${1+"$@"}
|
---|
75 | }
|
---|
76 |
|
---|
77 | fail_msg() {
|
---|
78 | rc_failed 1
|
---|
79 | rc_status -v
|
---|
80 | }
|
---|
81 |
|
---|
82 | succ_msg() {
|
---|
83 | rc_reset
|
---|
84 | rc_status -v
|
---|
85 | }
|
---|
86 | fi
|
---|
87 |
|
---|
88 | if [ "$system" = "debian" ]; then
|
---|
89 | daemon() {
|
---|
90 | start-stop-daemon --start --exec $1 -- $2
|
---|
91 | }
|
---|
92 |
|
---|
93 | killproc() {
|
---|
94 | start-stop-daemon --stop --exec $@
|
---|
95 | }
|
---|
96 |
|
---|
97 | fail_msg() {
|
---|
98 | echo " ...fail!"
|
---|
99 | }
|
---|
100 |
|
---|
101 | succ_msg() {
|
---|
102 | echo " ...done."
|
---|
103 | }
|
---|
104 | fi
|
---|
105 |
|
---|
106 | if [ "$system" = "gentoo" ]; then
|
---|
107 | . /sbin/functions.sh
|
---|
108 | daemon() {
|
---|
109 | start-stop-daemon --start --exec $1 -- $2
|
---|
110 | }
|
---|
111 |
|
---|
112 | killproc() {
|
---|
113 | start-stop-daemon --stop --exec $@
|
---|
114 | }
|
---|
115 |
|
---|
116 | fail_msg() {
|
---|
117 | echo " ...fail!"
|
---|
118 | }
|
---|
119 |
|
---|
120 | succ_msg() {
|
---|
121 | echo " ...done."
|
---|
122 | }
|
---|
123 |
|
---|
124 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
125 | shift
|
---|
126 | fi
|
---|
127 | fi
|
---|
128 |
|
---|
129 | if [ "$system" = "slackware" ]; then
|
---|
130 | daemon() {
|
---|
131 | $1 $2
|
---|
132 | }
|
---|
133 |
|
---|
134 | killproc() {
|
---|
135 | killall $1
|
---|
136 | rm -f $PIDFILE
|
---|
137 | }
|
---|
138 |
|
---|
139 | fail_msg() {
|
---|
140 | echo " ...fail!"
|
---|
141 | }
|
---|
142 |
|
---|
143 | succ_msg() {
|
---|
144 | echo " ...done."
|
---|
145 | }
|
---|
146 |
|
---|
147 | status() {
|
---|
148 | echo -n "Checking for vboxadd-timesync"
|
---|
149 | if [ -f /var/run/$1 ]; then
|
---|
150 | echo " ...running"
|
---|
151 | else
|
---|
152 | echo " ...not running"
|
---|
153 | fi
|
---|
154 | }
|
---|
155 |
|
---|
156 | fi
|
---|
157 |
|
---|
158 | if [ "$system" = "other" ]; then
|
---|
159 | fail_msg() {
|
---|
160 | echo " ...fail!"
|
---|
161 | }
|
---|
162 |
|
---|
163 | succ_msg() {
|
---|
164 | echo " ...done."
|
---|
165 | }
|
---|
166 |
|
---|
167 | begin() {
|
---|
168 | echo -n "$1"
|
---|
169 | }
|
---|
170 | fi
|
---|
171 |
|
---|
172 | binary=/usr/sbin/vboxadd-timesync
|
---|
173 |
|
---|
174 | test -x "$binary" || {
|
---|
175 | echo "Cannot run $binary"
|
---|
176 | exit 1
|
---|
177 | }
|
---|
178 |
|
---|
179 | vboxaddrunning() {
|
---|
180 | lsmod | grep -q "vboxadd[^_-]"
|
---|
181 | }
|
---|
182 |
|
---|
183 | start() {
|
---|
184 | if ! test -f $PIDFILE; then
|
---|
185 | echo -n "Starting VirtualBox host to guest time synchronisation ";
|
---|
186 | vboxaddrunning || {
|
---|
187 | echo "VirtualBox Additions module not loaded!"
|
---|
188 | exit 1
|
---|
189 | }
|
---|
190 | daemon $binary --daemonize
|
---|
191 | RETVAL=$?
|
---|
192 | test $RETVAL -eq 0 && touch $PIDFILE
|
---|
193 | succ_msg
|
---|
194 | fi
|
---|
195 | return $RETVAL
|
---|
196 | }
|
---|
197 |
|
---|
198 | stop() {
|
---|
199 | if test -f $PIDFILE; then
|
---|
200 | echo -n "Stopping VirtualBox host to guest time synchronisation ";
|
---|
201 | vboxaddrunning || {
|
---|
202 | echo "VirtualBox Additions module not loaded!"
|
---|
203 | exit 1
|
---|
204 | }
|
---|
205 | killproc $binary
|
---|
206 | RETVAL=$?
|
---|
207 | test $RETVAL -eq 0 && rm -f $PIDFILE
|
---|
208 | succ_msg
|
---|
209 | fi
|
---|
210 | return $RETVAL
|
---|
211 | }
|
---|
212 |
|
---|
213 | restart() {
|
---|
214 | stop && start
|
---|
215 | }
|
---|
216 |
|
---|
217 | dmnstatus() {
|
---|
218 | status vboxadd-timesync
|
---|
219 | }
|
---|
220 |
|
---|
221 | case "$1" in
|
---|
222 | start)
|
---|
223 | start
|
---|
224 | ;;
|
---|
225 | stop)
|
---|
226 | stop
|
---|
227 | ;;
|
---|
228 | restart)
|
---|
229 | restart
|
---|
230 | ;;
|
---|
231 | status)
|
---|
232 | dmnstatus
|
---|
233 | ;;
|
---|
234 | *)
|
---|
235 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
236 | exit 1
|
---|
237 | esac
|
---|
238 |
|
---|
239 | exit $RETVAL
|
---|