1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # InnoTek VirtualBox
|
---|
4 | #
|
---|
5 | # Linux Additions timesync daemon init script
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
8 | #
|
---|
9 | # Use only with permission.
|
---|
10 | #
|
---|
11 |
|
---|
12 | # chkconfig: 35 35 56
|
---|
13 | # description: VirtualBox Additions timesync
|
---|
14 | #
|
---|
15 | ### BEGIN INIT INFO
|
---|
16 | # Provides: vboxadd-timesync
|
---|
17 | # Required-Start: vboxadd
|
---|
18 | # Required-Stop: vboxadd
|
---|
19 | # Default-Start: 3 5
|
---|
20 | # Default-Stop:
|
---|
21 | # Description: VirtualBox Additions timesync
|
---|
22 | ### END INIT INFO
|
---|
23 |
|
---|
24 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
25 |
|
---|
26 | system=unknown
|
---|
27 | if [ -f /etc/redhat-release ]; then
|
---|
28 | system=redhat
|
---|
29 | PIDFILE="/var/lock/subsys/vboxadd-timesync"
|
---|
30 | elif [ -f /etc/SuSE-release ]; then
|
---|
31 | system=suse
|
---|
32 | PIDFILE="/var/lock/subsys/vboxadd-timesync"
|
---|
33 | elif [ -f /etc/debian_version ]; then
|
---|
34 | system=debian
|
---|
35 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
36 | elif [ -f /etc/gentoo-release ]; then
|
---|
37 | system=gentoo
|
---|
38 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
39 | else
|
---|
40 | system=other
|
---|
41 | if [ -d /var/run -a -w /var/run ]; then
|
---|
42 | PIDFILE="/var/run/vboxadd-timesync"
|
---|
43 | fi
|
---|
44 | fi
|
---|
45 |
|
---|
46 | if [ "$system" = "redhat" ]; then
|
---|
47 | . /etc/init.d/functions
|
---|
48 | fail_msg() {
|
---|
49 | echo_failure
|
---|
50 | echo
|
---|
51 | }
|
---|
52 |
|
---|
53 | succ_msg() {
|
---|
54 | echo_success
|
---|
55 | echo
|
---|
56 | }
|
---|
57 | fi
|
---|
58 |
|
---|
59 | if [ "$system" = "suse" ]; then
|
---|
60 | . /etc/rc.status
|
---|
61 | daemon() {
|
---|
62 | startproc ${1+"$@"}
|
---|
63 | }
|
---|
64 |
|
---|
65 | fail_msg() {
|
---|
66 | rc_failed 1
|
---|
67 | rc_status -v
|
---|
68 | }
|
---|
69 |
|
---|
70 | succ_msg() {
|
---|
71 | rc_reset
|
---|
72 | rc_status -v
|
---|
73 | }
|
---|
74 | fi
|
---|
75 |
|
---|
76 | if [ "$system" = "debian" ]; then
|
---|
77 | daemon() {
|
---|
78 | start-stop-daemon --start --exec $1 -- $2
|
---|
79 | }
|
---|
80 |
|
---|
81 | killproc() {
|
---|
82 | start-stop-daemon --stop --exec $@
|
---|
83 | }
|
---|
84 |
|
---|
85 | fail_msg() {
|
---|
86 | echo " ...fail!"
|
---|
87 | }
|
---|
88 |
|
---|
89 | succ_msg() {
|
---|
90 | echo " ...done."
|
---|
91 | }
|
---|
92 | fi
|
---|
93 |
|
---|
94 | if [ "$system" = "gentoo" ]; then
|
---|
95 | . /sbin/functions.sh
|
---|
96 | daemon() {
|
---|
97 | start-stop-daemon --start --exec $1 -- $2
|
---|
98 | }
|
---|
99 |
|
---|
100 | killproc() {
|
---|
101 | start-stop-daemon --stop --exec $@
|
---|
102 | }
|
---|
103 |
|
---|
104 | fail_msg() {
|
---|
105 | echo " ...fail!"
|
---|
106 | }
|
---|
107 |
|
---|
108 | succ_msg() {
|
---|
109 | echo " ...done."
|
---|
110 | }
|
---|
111 |
|
---|
112 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
113 | shift
|
---|
114 | fi
|
---|
115 | fi
|
---|
116 |
|
---|
117 | if [ "$system" = "other" ]; then
|
---|
118 | fail_msg() {
|
---|
119 | echo " ...fail!"
|
---|
120 | }
|
---|
121 |
|
---|
122 | succ_msg() {
|
---|
123 | echo " ...done."
|
---|
124 | }
|
---|
125 |
|
---|
126 | begin() {
|
---|
127 | echo -n "$1"
|
---|
128 | }
|
---|
129 | fi
|
---|
130 |
|
---|
131 | binary=/usr/sbin/vboxadd-timesync
|
---|
132 |
|
---|
133 | test -x "$binary" || {
|
---|
134 | echo "Cannot run $binary"
|
---|
135 | exit 1
|
---|
136 | }
|
---|
137 |
|
---|
138 | vboxaddrunning() {
|
---|
139 | lsmod | grep -q vboxadd[^_-]
|
---|
140 | }
|
---|
141 |
|
---|
142 | start() {
|
---|
143 | if ! test -f $PIDFILE; then
|
---|
144 | echo -n "Starting VirtualBox host to guest time synchronisation ";
|
---|
145 | vboxaddrunning || {
|
---|
146 | echo "VirtualBox Additions module not loaded!"
|
---|
147 | exit 1
|
---|
148 | }
|
---|
149 | daemon $binary --daemonize
|
---|
150 | RETVAL=$?
|
---|
151 | test $RETVAL -eq 0 && touch $PIDFILE
|
---|
152 | succ_msg
|
---|
153 | fi
|
---|
154 | return $RETVAL
|
---|
155 | }
|
---|
156 |
|
---|
157 | stop() {
|
---|
158 | if test -f $PIDFILE; then
|
---|
159 | echo -n "Stopping VirtualBox host to guest time synchronisation ";
|
---|
160 | vboxaddrunning || {
|
---|
161 | echo "VirtualBox Additions module not loaded!"
|
---|
162 | exit 1
|
---|
163 | }
|
---|
164 | killproc $binary
|
---|
165 | RETVAL=$?
|
---|
166 | test $RETVAL -eq 0 && rm -f $PIDFILE
|
---|
167 | succ_msg
|
---|
168 | fi
|
---|
169 | return $RETVAL
|
---|
170 | }
|
---|
171 |
|
---|
172 | restart() {
|
---|
173 | stop && start
|
---|
174 | }
|
---|
175 |
|
---|
176 | dmnstatus() {
|
---|
177 | status vboxadd-timesync
|
---|
178 | }
|
---|
179 |
|
---|
180 | case "$1" in
|
---|
181 | start)
|
---|
182 | start
|
---|
183 | ;;
|
---|
184 | stop)
|
---|
185 | stop
|
---|
186 | ;;
|
---|
187 | restart)
|
---|
188 | restart
|
---|
189 | ;;
|
---|
190 | status)
|
---|
191 | dmnstatus
|
---|
192 | ;;
|
---|
193 | *)
|
---|
194 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
195 | exit 1
|
---|
196 | esac
|
---|
197 |
|
---|
198 | exit $RETVAL
|
---|