new --force option for qvm-sync-clock to be able to bypass time sync errors
This commit is contained in:
parent
ae848d5369
commit
2fcd3c6832
@ -22,6 +22,7 @@
|
|||||||
#
|
#
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
|
from optparse import OptionParser
|
||||||
from qubes.qubes import QubesVmCollection
|
from qubes.qubes import QubesVmCollection
|
||||||
import os.path
|
import os.path
|
||||||
import os
|
import os
|
||||||
@ -41,9 +42,11 @@ def get_netvm_of_vm(vm):
|
|||||||
return netvm
|
return netvm
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
verbose = False
|
parser = OptionParser()
|
||||||
if len(sys.argv) > 1 and sys.argv[1] in [ '--verbose', '-v' ]:
|
parser.add_option ("-v", "--verbose", action="store_true", dest="verbose", default=False)
|
||||||
verbose = True
|
parser.add_option ("-f", "--force", action="store_true", dest="force", default=False)
|
||||||
|
|
||||||
|
(options, args) = parser.parse_args ()
|
||||||
|
|
||||||
lockfile_name = "/var/run/qubes/qvm-sync-clock.lock"
|
lockfile_name = "/var/run/qubes/qvm-sync-clock.lock"
|
||||||
if os.path.exists(lockfile_name):
|
if os.path.exists(lockfile_name):
|
||||||
@ -74,23 +77,26 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
net_vm = get_netvm_of_vm(clock_vm)
|
net_vm = get_netvm_of_vm(clock_vm)
|
||||||
if verbose:
|
if options.verbose:
|
||||||
print >> sys.stderr, '--> Waiting for network for ClockVM.'
|
print >> sys.stderr, '--> Waiting for network for ClockVM.'
|
||||||
|
|
||||||
# Ignore retcode, try even if nm-online failed - user can setup network manually
|
# Ignore retcode, try even if nm-online failed - user can setup network manually
|
||||||
# on-online has timeout 30sec by default
|
# on-online has timeout 30sec by default
|
||||||
net_vm.run('nm-online -x', verbose=verbose, gui=False, wait=True,
|
net_vm.run('nm-online -x', verbose=options.verbose, gui=False, wait=True,
|
||||||
ignore_stderr=True)
|
ignore_stderr=True)
|
||||||
|
|
||||||
# Sync clock
|
# Sync clock
|
||||||
if clock_vm.run('QUBESRPC qubes.SyncNtpClock dom0', user="root",
|
if clock_vm.run('QUBESRPC qubes.SyncNtpClock dom0', user="root",
|
||||||
verbose=verbose, gui=False, wait=True, ignore_stderr=True) \
|
verbose=options.verbose, gui=False, wait=True, ignore_stderr=True) \
|
||||||
!= 0:
|
!= 0:
|
||||||
print >> sys.stderr, 'Time sync failed, aborting!'
|
if options.force:
|
||||||
sys.exit(1)
|
print >> sys.stderr, 'Time sync failed! - Sync forced'
|
||||||
|
else:
|
||||||
|
print >> sys.stderr, 'Time sync failed! - Exiting'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Use the date format based on RFC2822 to avoid localisation issues
|
# Use the date format based on RFC2822 to avoid localisation issues
|
||||||
p = clock_vm.run('date -u -Iseconds', verbose=verbose,
|
p = clock_vm.run('date -u -Iseconds', verbose=options.verbose,
|
||||||
gui=False, passio_popen=True, ignore_stderr=True)
|
gui=False, passio_popen=True, ignore_stderr=True)
|
||||||
date_out = p.stdout.read(100)
|
date_out = p.stdout.read(100)
|
||||||
date_out = date_out.strip()
|
date_out = date_out.strip()
|
||||||
@ -99,18 +105,18 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Sync dom0 time
|
# Sync dom0 time
|
||||||
if verbose:
|
if options.verbose:
|
||||||
print >> sys.stderr, '--> Syncing dom0 clock.'
|
print >> sys.stderr, '--> Syncing dom0 clock.'
|
||||||
|
|
||||||
subprocess.check_call(['sudo', 'date', '-u', '-Iseconds', '-s', date_out],
|
subprocess.check_call(['sudo', 'date', '-u', '-Iseconds', '-s', date_out],
|
||||||
stdout=None if verbose else open(os.devnull, 'w'))
|
stdout=None if options.verbose else open(os.devnull, 'w'))
|
||||||
subprocess.check_call(['sudo', 'hwclock', '--systohc'],
|
subprocess.check_call(['sudo', 'hwclock', '--systohc'],
|
||||||
stdout=None if verbose else open(os.devnull, 'w'))
|
stdout=None if options.verbose else open(os.devnull, 'w'))
|
||||||
|
|
||||||
# Sync other VMs clock
|
# Sync other VMs clock
|
||||||
for vm in qvm_collection.values():
|
for vm in qvm_collection.values():
|
||||||
if vm.is_running() and vm.qid != 0 and vm.qid != clock_vm.qid:
|
if vm.is_running() and vm.qid != 0 and vm.qid != clock_vm.qid:
|
||||||
if verbose:
|
if options.verbose:
|
||||||
print >> sys.stderr, '--> Syncing \'%s\' clock.' % vm.name
|
print >> sys.stderr, '--> Syncing \'%s\' clock.' % vm.name
|
||||||
try:
|
try:
|
||||||
vm.run_service("qubes.SetDateTime", user="root",
|
vm.run_service("qubes.SetDateTime", user="root",
|
||||||
|
Loading…
Reference in New Issue
Block a user