From 2871ace66555265669971b027b8ec833007be4e9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 10 Sep 2015 19:10:54 -0400 Subject: [PATCH] debian/ubuntu: add systemd support Prefer systemd over upstart if present (for newer ubuntu) Signed-off-by: Sage Weil --- ceph_deploy/hosts/debian/__init__.py | 3 ++ ceph_deploy/hosts/debian/mon/create.py | 65 ++++++++++++++++++-------- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/ceph_deploy/hosts/debian/__init__.py b/ceph_deploy/hosts/debian/__init__.py index 2c087dd..b2ece01 100644 --- a/ceph_deploy/hosts/debian/__init__.py +++ b/ceph_deploy/hosts/debian/__init__.py @@ -16,8 +16,11 @@ def choose_init(module): Returns the name of a init system (upstart, sysvinit ...). """ + # fixme: newer ubuntu runs systemd if distro.lower() == 'ubuntu': return 'upstart' + if module.conn.remote_module.path_exists("/lib/systemd/system/ceph.target"): + return 'systemd' return 'sysvinit' diff --git a/ceph_deploy/hosts/debian/mon/create.py b/ceph_deploy/hosts/debian/mon/create.py index 93d4393..2a4d41d 100644 --- a/ceph_deploy/hosts/debian/mon/create.py +++ b/ceph_deploy/hosts/debian/mon/create.py @@ -1,42 +1,69 @@ from ceph_deploy.hosts import common +from ceph_deploy.util import system from ceph_deploy.lib import remoto def create(distro, args, monitor_keyring): - logger = distro.conn.logger hostname = distro.conn.remote_module.shortname() common.mon_create(distro, args, monitor_keyring, hostname) - service = distro.conn.remote_module.which_service() - if not service: - logger.warning('could not find `service` executable') - - if distro.init == 'upstart': # Ubuntu uses upstart + if distro.init == 'sysvinit': + service = distro.conn.remote_module.which_service() remoto.process.run( distro.conn, [ - 'initctl', - 'emit', - 'ceph-mon', - 'cluster={cluster}'.format(cluster=args.cluster), - 'id={hostname}'.format(hostname=hostname), + service, + 'ceph', + '-c', + '/etc/ceph/{cluster}.conf'.format(cluster=args.cluster), + 'start', + 'mon.{hostname}'.format(hostname=hostname) ], timeout=7, ) - elif distro.init == 'sysvinit': # Debian uses sysvinit + system.enable_service(distro.conn) + elif distro.init == 'upstart': + remoto.process.run( + distro.conn, + [ + 'initctl', + 'emit', + 'ceph-mon', + 'cluster={cluster}'.format(cluster=args.cluster), + 'id={hostname}'.format(hostname=hostname), + ], + timeout=7, + ) + elif distro.init == 'systemd': + # enable ceph target for this host (in case it isn't already enabled) remoto.process.run( distro.conn, [ - service, - 'ceph', - '-c', - '/etc/ceph/{cluster}.conf'.format(cluster=args.cluster), + 'systemctl', + 'enable', + 'ceph.target' + ], + timeout=7, + ) + + # enable and start this mon instance + remoto.process.run( + distro.conn, + [ + 'systemctl', + 'enable', + 'ceph-mon@{hostname}'.format(hostname=hostname), + ], + timeout=7, + ) + remoto.process.run( + distro.conn, + [ + 'systemctl', 'start', - 'mon.{hostname}'.format(hostname=hostname) + 'ceph-mon@{hostname}'.format(hostname=hostname), ], timeout=7, ) - else: - raise RuntimeError('create cannot use init %s' % distro.init) -- 2.47.3