VirtualBox

Ticket #758: vboxadd-timesync

File vboxadd-timesync, 4.2 KB (added by John Gnew, 17 years ago)

vboxadd-timesync

Line 
1#!/bin/sh
2#
3# innotek VirtualBox
4#
5# Linux Additions timesync daemon init script
6#
7# Copyright (C) 2006-2007 innotek GmbH
8#
9# This file is part of VirtualBox Open Source Edition (OSE), as
10# available from http://www.virtualbox.org. This file is free software;
11# you can redistribute it and/or modify it under the terms of the GNU
12# General Public License as published by the Free Software Foundation,
13# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14# distribution. VirtualBox OSE is distributed in the hope that it will
15# be useful, but WITHOUT ANY WARRANTY of any kind.
16
17# chkconfig: 35 35 56
18# description: VirtualBox Additions timesync
19#
20### BEGIN INIT INFO
21# Provides: vboxadd-timesync
22# Required-Start: vboxadd
23# Required-Stop: vboxadd
24# Default-Start: 3 5
25# Default-Stop:
26# Description: VirtualBox Additions timesync
27### END INIT INFO
28
29PATH=$PATH:/bin:/sbin:/usr/sbin
30
31system=unknown
32if [ -f /etc/lfs-release ]; then
33 system=lfs
34 PIDFILE="/var/run/vboxadd-timesync.pid"
35elif [ -f /etc/redhat-release ]; then
36 system=redhat
37 PIDFILE="/var/lock/subsys/vboxadd-timesync"
38elif [ -f /etc/SuSE-release ]; then
39 system=suse
40 PIDFILE="/var/lock/subsys/vboxadd-timesync"
41elif [ -f /etc/debian_version ]; then
42 system=debian
43 PIDFILE="/var/run/vboxadd-timesync"
44elif [ -f /etc/gentoo-release ]; then
45 system=gentoo
46 PIDFILE="/var/run/vboxadd-timesync"
47else
48 system=other
49 if [ -d /var/run -a -w /var/run ]; then
50 PIDFILE="/var/run/vboxadd-timesync"
51 fi
52fi
53
54if [ "$system" = "lfs" ]; then
55 . /etc/rc.d/init.d/functions
56 daemon() {
57 loadproc $1 $2
58 ps -C vboxadd-timesync -o pid= > $PIDFILE
59 }
60
61 fail_msg() {
62 boot_mesg ""
63 echo_failure
64 }
65
66 succ_msg() {
67 boot_mesg ""
68 echo_ok
69 }
70fi
71
72if [ "$system" = "redhat" ]; then
73 . /etc/init.d/functions
74 fail_msg() {
75 echo_failure
76 echo
77 }
78
79 succ_msg() {
80 echo_success
81 echo
82 }
83fi
84
85if [ "$system" = "suse" ]; then
86 . /etc/rc.status
87 daemon() {
88 startproc ${1+"$@"}
89 }
90
91 fail_msg() {
92 rc_failed 1
93 rc_status -v
94 }
95
96 succ_msg() {
97 rc_reset
98 rc_status -v
99 }
100fi
101
102if [ "$system" = "debian" ]; then
103 daemon() {
104 start-stop-daemon --start --exec $1 -- $2
105 }
106
107 killproc() {
108 start-stop-daemon --stop --exec $@
109 }
110
111 fail_msg() {
112 echo " ...fail!"
113 }
114
115 succ_msg() {
116 echo " ...done."
117 }
118fi
119
120if [ "$system" = "gentoo" ]; then
121 . /sbin/functions.sh
122 daemon() {
123 start-stop-daemon --start --exec $1 -- $2
124 }
125
126 killproc() {
127 start-stop-daemon --stop --exec $@
128 }
129
130 fail_msg() {
131 echo " ...fail!"
132 }
133
134 succ_msg() {
135 echo " ...done."
136 }
137
138 if [ "`which $0`" = "/sbin/rc" ]; then
139 shift
140 fi
141fi
142
143if [ "$system" = "other" ]; then
144 fail_msg() {
145 echo " ...fail!"
146 }
147
148 succ_msg() {
149 echo " ...done."
150 }
151
152 begin() {
153 echo -n "$1"
154 }
155fi
156
157binary=/usr/sbin/vboxadd-timesync
158
159test -x "$binary" || {
160 echo "Cannot run $binary"
161 exit 1
162}
163
164vboxaddrunning() {
165 lsmod | grep -q vboxadd[^_-]
166}
167
168start() {
169 if ! test -f $PIDFILE; then
170 echo -n "Starting VirtualBox host to guest time synchronisation ";
171 vboxaddrunning || {
172 echo "VirtualBox Additions module not loaded!"
173 exit 1
174 }
175 daemon $binary --daemonize
176 RETVAL=$?
177 test $RETVAL -eq 0 && touch $PIDFILE
178 succ_msg
179 fi
180 return $RETVAL
181}
182
183stop() {
184 if test -f $PIDFILE; then
185 echo -n "Stopping VirtualBox host to guest time synchronisation ";
186 vboxaddrunning || {
187 echo "VirtualBox Additions module not loaded!"
188 exit 1
189 }
190# killproc $binary
191 killproc $PIDFILE
192 RETVAL=$?
193 test $RETVAL -eq 0 && rm -f $PIDFILE
194 succ_msg
195 fi
196 return $RETVAL
197}
198
199restart() {
200 stop && start
201}
202
203dmnstatus() {
204 status vboxadd-timesync
205}
206
207case "$1" in
208start)
209 start
210 ;;
211stop)
212 stop
213 ;;
214restart)
215 restart
216 ;;
217status)
218 dmnstatus
219 ;;
220*)
221 echo "Usage: $0 {start|stop|restart|status}"
222 exit 1
223esac
224
225exit $RETVAL

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette