return 'ceph-%s@%s' % (fsid, daemon_type)
def check_unit(unit_name):
- # type: (str) -> Tuple[bool, str]
+ # type: (str) -> Tuple[bool, str, bool]
# NOTE: we ignore the exit code here because systemctl outputs
# various exit codes based on the state of the service, but the
# string result is more explicit (and sufficient).
enabled = False
+ installed = False
try:
out, err, code = call(['systemctl', 'is-enabled', unit_name],
verbose_on_failure=False)
if code == 0:
enabled = True
+ installed = True
+ elif "disabled" in out:
+ installed = True
except Exception as e:
logger.warning('unable to run systemctl: %s' % e)
enabled = False
+ installed = False
state = 'unknown'
try:
except Exception as e:
logger.warning('unable to run systemctl: %s' % e)
state = 'unknown'
- return (enabled, state)
+ return (enabled, state, installed)
def get_legacy_config_fsid(cluster, legacy_dir=None):
# type: (str, str) -> Optional[str]
if not cmd:
logger.debug('firewalld does not appear to be present')
return
- (enabled, state) = check_unit('firewalld.service')
+ (enabled, state, _) = check_unit('firewalld.service')
if not enabled:
logger.debug('firewalld.service is not enabled')
return
'fsid': fsid if fsid is not None else 'unknown',
}
if detail:
- (i['enabled'], i['state']) = check_unit(
+ (i['enabled'], i['state'], _) = check_unit(
'ceph-%s@%s' % (daemon_type, daemon_id))
if not host_version:
try:
}
if detail:
# get container id
- (i['enabled'], i['state']) = check_unit(unit_name)
+ (i['enabled'], i['state'], _) = check_unit(unit_name)
container_id = None
image_name = None
image_id = None
# cluster we are adopting based on the /etc/{defaults,sysconfig}/ceph
# CLUSTER field.
unit_name = 'ceph-%s@%s' % (daemon_type, daemon_id)
- (enabled, state) = check_unit(unit_name)
+ (enabled, state, _) = check_unit(unit_name)
if state == 'running':
logger.info('Stopping old systemd unit %s...' % unit_name)
##################################
-def check_time_sync():
+def check_time_sync(enabler=None):
+ # type: (Optional[Packager]) -> bool
units = [
'chrony.service', # 18.04 (at least)
- 'chronyd.service', # el
+ 'chronyd.service', # el / opensuse
'systemd-timesyncd.service',
'ntpd.service', # el7 (at least)
'ntp.service', # 18.04 (at least)
]
for u in units:
- (enabled, state) = check_unit(u)
+ (enabled, state, installed) = check_unit(u)
if enabled and state == 'running':
logger.info('Time sync unit %s is enabled and running' % u)
return True
+ if enabler is not None:
+ if not enabled and installed:
+ logger.info('Enabling time sync unit %s' % u)
+ enabler.enable_service(u)
logger.warning('No time sync service is running; checked for %s' % units)
return False
if not pkg:
pkg = create_packager()
pkg.install(['chrony'])
+ # check again, and this time try to enable
+ # the service
+ check_time_sync(enabler=pkg)
if 'expect_hostname' in args and args.expect_hostname and args.expect_hostname != get_hostname():
logger.warning('Adjusting hostname from %s -> %s...' % (get_hostname(), args.expect_hostname))
else:
return 'https://download.ceph.com/keys/autobuild.asc', 'autobuild'
+ def enable_service(self, service):
+ """
+ Start and enable the service (typically using systemd).
+ """
+ call_throws(['systemctl', 'enable', '--now', service])
+
+
class Apt(Packager):
DISTRO_NAMES = {
'ubuntu': 'ubuntu',
logger.info('Installing packages %s...' % ls)
call_throws([self.tool, 'in', '-y'] + ls)
- if 'chrony' in ls:
- # ensure chrony service is enabled/started
- call_throws(['systemctl', 'enable', '--now', 'chronyd'])
-
def install_podman(self):
self.install(['podman'])