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.alldomusa.eu.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 | [ -f /lib/lsb/init-functions ] || NOLSB=yes
|
---|
36 |
|
---|
37 | if [ -f /etc/redhat-release ]; then
|
---|
38 | system=redhat
|
---|
39 | elif [ -f /etc/SuSE-release ]; then
|
---|
40 | system=suse
|
---|
41 | elif [ -f /etc/debian_version ]; then
|
---|
42 | system=debian
|
---|
43 | elif [ -f /etc/gentoo-release ]; then
|
---|
44 | system=gentoo
|
---|
45 | fi
|
---|
46 |
|
---|
47 | if [ -z "$NOLSB" ]; then
|
---|
48 | . /lib/lsb/init-functions
|
---|
49 | fail_msg() {
|
---|
50 | echo ""
|
---|
51 | log_failure_msg "$1"
|
---|
52 | }
|
---|
53 | succ_msg() {
|
---|
54 | log_end_msg 0
|
---|
55 | }
|
---|
56 | begin_msg() {
|
---|
57 | log_daemon_msg "$@"
|
---|
58 | }
|
---|
59 | else
|
---|
60 | if [ "$system" = "redhat" ]; then
|
---|
61 | . /etc/init.d/functions
|
---|
62 | fail_msg() {
|
---|
63 | echo -n " "
|
---|
64 | echo_failure
|
---|
65 | echo
|
---|
66 | echo " ($1)"
|
---|
67 | }
|
---|
68 | succ_msg() {
|
---|
69 | echo -n " "
|
---|
70 | echo_success
|
---|
71 | echo
|
---|
72 | }
|
---|
73 | elif [ "$system" = "suse" ]; then
|
---|
74 | . /etc/rc.status
|
---|
75 | fail_msg() {
|
---|
76 | rc_failed 1
|
---|
77 | rc_status -v
|
---|
78 | echo " ($1)"
|
---|
79 | }
|
---|
80 | succ_msg() {
|
---|
81 | rc_reset
|
---|
82 | rc_status -v
|
---|
83 | }
|
---|
84 | elif [ "$system" = "gentoo" ]; then
|
---|
85 | . /sbin/functions.sh
|
---|
86 | fail_msg() {
|
---|
87 | eerror "$1"
|
---|
88 | }
|
---|
89 | succ_msg() {
|
---|
90 | eend "$?"
|
---|
91 | }
|
---|
92 | begin_msg() {
|
---|
93 | ebegin "$1"
|
---|
94 | }
|
---|
95 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
96 | shift
|
---|
97 | fi
|
---|
98 | else
|
---|
99 | fail_msg() {
|
---|
100 | echo " ...failed!"
|
---|
101 | echo " ($1)"
|
---|
102 | }
|
---|
103 | succ_msg() {
|
---|
104 | echo " ...done."
|
---|
105 | }
|
---|
106 | fi
|
---|
107 | if [ "$system" != "gentoo" ]; then
|
---|
108 | begin_msg() {
|
---|
109 | [ -z "${1:-}" ] && return 1
|
---|
110 | if [ -z "${2:-}" ]; then
|
---|
111 | echo -n "$1"
|
---|
112 | else
|
---|
113 | echo -n "$1: $2"
|
---|
114 | fi
|
---|
115 | }
|
---|
116 | fi
|
---|
117 | fi
|
---|
118 |
|
---|
119 | if [ "$system" = "redhat" ]; then
|
---|
120 | PIDFILE="/var/lock/subsys/vboxadd-timesync"
|
---|
121 | elif [ "$system" = "suse" ]; then
|
---|
122 | PIDFILE="/var/lock/subsys/vboxadd-timesync"
|
---|
123 | daemon() {
|
---|
124 | startproc ${1+"$@"}
|
---|
125 | }
|
---|
126 | elif [ "$system" = "debian" ]; then
|
---|
127 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
128 | daemon() {
|
---|
129 | start-stop-daemon --start --exec $1 -- $2
|
---|
130 | }
|
---|
131 | killproc() {
|
---|
132 | start-stop-daemon --stop --exec $@
|
---|
133 | }
|
---|
134 | elif [ "$system" = "gentoo" ]; then
|
---|
135 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
136 | daemon() {
|
---|
137 | start-stop-daemon --start --exec $1 -- $2
|
---|
138 | }
|
---|
139 | killproc() {
|
---|
140 | start-stop-daemon --stop --exec $@
|
---|
141 | }
|
---|
142 | else
|
---|
143 | if [ -d /var/run -a -w /var/run ]; then
|
---|
144 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
145 | fi
|
---|
146 | fi
|
---|
147 |
|
---|
148 | binary=/usr/sbin/vboxadd-timesync
|
---|
149 |
|
---|
150 | test -x "$binary" || {
|
---|
151 | echo "Cannot run $binary"
|
---|
152 | exit 1
|
---|
153 | }
|
---|
154 |
|
---|
155 | vboxaddrunning() {
|
---|
156 | lsmod | grep -q "vboxadd[^_-]"
|
---|
157 | }
|
---|
158 |
|
---|
159 | start() {
|
---|
160 | if ! test -f $PIDFILE; then
|
---|
161 | begin_msg "Starting VirtualBox host to guest time synchronisation";
|
---|
162 | vboxaddrunning || {
|
---|
163 | failure "VirtualBox Additions module not loaded!"
|
---|
164 | }
|
---|
165 | daemon $binary --daemonize
|
---|
166 | RETVAL=$?
|
---|
167 | test $RETVAL -eq 0 && touch $PIDFILE
|
---|
168 | succ_msg
|
---|
169 | fi
|
---|
170 | return $RETVAL
|
---|
171 | }
|
---|
172 |
|
---|
173 | stop() {
|
---|
174 | if test -f $PIDFILE; then
|
---|
175 | begin_msg "Stopping VirtualBox host to guest time synchronisation";
|
---|
176 | vboxaddrunning || {
|
---|
177 | failure "VirtualBox Additions module not loaded!"
|
---|
178 | }
|
---|
179 | killproc $binary
|
---|
180 | RETVAL=$?
|
---|
181 | test $RETVAL -eq 0 && rm -f $PIDFILE
|
---|
182 | succ_msg
|
---|
183 | fi
|
---|
184 | return $RETVAL
|
---|
185 | }
|
---|
186 |
|
---|
187 | restart() {
|
---|
188 | stop && start
|
---|
189 | }
|
---|
190 |
|
---|
191 | dmnstatus() {
|
---|
192 | status vboxadd-timesync
|
---|
193 | }
|
---|
194 |
|
---|
195 | case "$1" in
|
---|
196 | start)
|
---|
197 | start
|
---|
198 | ;;
|
---|
199 | stop)
|
---|
200 | stop
|
---|
201 | ;;
|
---|
202 | restart)
|
---|
203 | restart
|
---|
204 | ;;
|
---|
205 | status)
|
---|
206 | dmnstatus
|
---|
207 | ;;
|
---|
208 | *)
|
---|
209 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
210 | exit 1
|
---|
211 | esac
|
---|
212 |
|
---|
213 | exit $RETVAL
|
---|