2013-10-12 08:28:27 +00:00
|
|
|
"""
|
2014-05-09 20:50:22 +00:00
|
|
|
Clock synchronizer
|
2013-10-12 08:28:27 +00:00
|
|
|
"""
|
2011-06-16 21:37:52 +00:00
|
|
|
import logging
|
2012-07-18 20:44:59 +00:00
|
|
|
import contextlib
|
2011-06-16 21:37:52 +00:00
|
|
|
|
2011-09-13 21:53:02 +00:00
|
|
|
from ..orchestra import run
|
2011-06-16 21:37:52 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2012-07-18 20:44:59 +00:00
|
|
|
@contextlib.contextmanager
|
2011-06-16 21:37:52 +00:00
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Sync or skew clock
|
|
|
|
|
|
|
|
This will initially sync the clocks. Eventually it should let us also
|
|
|
|
skew by some number of seconds.
|
|
|
|
|
|
|
|
example:
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- clock:
|
|
|
|
- ceph:
|
|
|
|
- interactive:
|
|
|
|
|
|
|
|
to sync.
|
|
|
|
|
2013-10-12 08:28:27 +00:00
|
|
|
:param ctx: Context
|
|
|
|
:param config: Configuration
|
2011-06-16 21:37:52 +00:00
|
|
|
"""
|
|
|
|
|
2012-07-18 20:44:59 +00:00
|
|
|
log.info('Syncing clocks and checking initial clock skew...')
|
|
|
|
for rem in ctx.cluster.remotes.iterkeys():
|
|
|
|
rem.run(
|
|
|
|
args=[
|
|
|
|
'sudo',
|
|
|
|
'service', 'ntp', 'stop',
|
|
|
|
run.Raw(';'),
|
|
|
|
'sudo',
|
|
|
|
'ntpdate',
|
2012-09-09 21:23:12 +00:00
|
|
|
# 'clock1.dreamhost.com',
|
|
|
|
# 'clock2.dreamhost.com',
|
|
|
|
# 'clock3.dreamhost.com',
|
|
|
|
# 'time.apple.com',
|
|
|
|
'0.debian.pool.ntp.org',
|
|
|
|
'1.debian.pool.ntp.org',
|
|
|
|
'2.debian.pool.ntp.org',
|
|
|
|
'3.debian.pool.ntp.org',
|
2012-07-18 20:44:59 +00:00
|
|
|
run.Raw(';'),
|
|
|
|
'sudo',
|
|
|
|
'service', 'ntp', 'start',
|
|
|
|
run.Raw(';'),
|
2013-03-15 01:06:17 +00:00
|
|
|
'PATH=/usr/bin:/usr/sbin',
|
2012-07-18 20:44:59 +00:00
|
|
|
'ntpdc', '-p',
|
|
|
|
],
|
2011-06-16 21:37:52 +00:00
|
|
|
)
|
|
|
|
|
2012-07-18 20:44:59 +00:00
|
|
|
try:
|
|
|
|
yield
|
|
|
|
|
|
|
|
finally:
|
|
|
|
log.info('Checking final clock skew...')
|
|
|
|
for rem in ctx.cluster.remotes.iterkeys():
|
|
|
|
rem.run(
|
|
|
|
args=[
|
2013-03-15 01:06:17 +00:00
|
|
|
'PATH=/usr/bin:/usr/sbin',
|
2012-07-18 20:44:59 +00:00
|
|
|
'ntpdc', '-p',
|
|
|
|
],
|
|
|
|
)
|
2013-03-10 05:34:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def check(ctx, config):
|
2013-10-12 08:28:27 +00:00
|
|
|
"""
|
|
|
|
Run ntpdc at the start and the end of the task.
|
2014-05-09 20:50:22 +00:00
|
|
|
|
2013-10-12 08:28:27 +00:00
|
|
|
:param ctx: Context
|
|
|
|
:param config: Configuration
|
|
|
|
"""
|
2013-03-10 05:34:24 +00:00
|
|
|
log.info('Checking initial clock skew...')
|
|
|
|
for rem in ctx.cluster.remotes.iterkeys():
|
|
|
|
rem.run(
|
|
|
|
args=[
|
2013-03-15 01:06:17 +00:00
|
|
|
'PATH=/usr/bin:/usr/sbin',
|
2013-03-10 05:34:24 +00:00
|
|
|
'ntpdc', '-p',
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
|
|
|
|
finally:
|
|
|
|
log.info('Checking final clock skew...')
|
|
|
|
for rem in ctx.cluster.remotes.iterkeys():
|
|
|
|
rem.run(
|
|
|
|
args=[
|
2013-03-15 01:06:17 +00:00
|
|
|
'PATH=/usr/bin:/usr/sbin',
|
2013-03-10 05:34:24 +00:00
|
|
|
'ntpdc', '-p',
|
|
|
|
],
|
|
|
|
)
|