From 458d76fe282467d99859652a737005b26e10ef43 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 26 Sep 2019 17:19:25 -0500 Subject: [PATCH] ceph-daemon: add ceph.target and ceph-$fsid.target units Signed-off-by: Sage Weil --- src/ceph-daemon | 33 +++++++++++++++++++++++++++++++-- test_ceph_daemon.sh | 3 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/ceph-daemon b/src/ceph-daemon index a8764d282e9..29ed19188b4 100755 --- a/src/ceph-daemon +++ b/src/ceph-daemon @@ -137,7 +137,8 @@ def deploy_daemon(daemon_type, daemon_id, c, config=None, keyring=None): f.write('#!/bin/sh\n' + ' '.join(c.run_cmd()) + '\n') os.fchmod(f.fileno(), 0o700) - # unit + # systemd + install_base_units() unit = get_unit_file() unit_file = 'ceph-%s@.service' % (args.fsid) with open(args.unit_dir + '/' + unit_file, 'w') as f: @@ -147,11 +148,39 @@ def deploy_daemon(daemon_type, daemon_id, c, config=None, keyring=None): check_output(['systemctl', 'enable', unit_name]) check_output(['systemctl', 'start', unit_name]) +def install_base_units(): + existed = os.path.exists(args.unit_dir + '/ceph.target') + with open(args.unit_dir + '/ceph.target', 'w') as f: + f.write('[Unit]\n' + 'Description=all ceph service\n' + '[Install]\n' + 'WantedBy=multi-user.target\n') + if not existed: + check_output(['systemctl', 'enable', 'ceph.target']) + check_output(['systemctl', 'start', 'ceph.target']) + + existed = os.path.exists(args.unit_dir + '/ceph-%s.target' % args.fsid) + with open(args.unit_dir + '/ceph-%s.target' % args.fsid, 'w') as f: + f.write('[Unit]\n' + 'Description=ceph cluster {fsid}\n' + 'PartOf=ceph.target\n' + 'Before=ceph.target\n' + '[Install]\n' + 'WantedBy=multi-user.target ceph.target\n'.format( + fsid=args.fsid) + ) + if not existed: + check_output(['systemctl', 'enable', 'ceph-%s.target' % args.fsid]) + check_output(['systemctl', 'start', 'ceph-%s.target' % args.fsid]) + def get_unit_file(): u = """[Unit] Description=Ceph daemon for {fsid} After=network.target +PartOf=ceph-{fsid}.target +Before=ceph-{fsid}.target + [Service] EnvironmentFile=-/etc/environment ExecStartPre=-/usr/bin/podman rm ceph-{fsid}-%i @@ -165,7 +194,7 @@ TimeoutStartSec=120 TimeoutStopSec=15 [Install] -WantedBy=multi-user.target +WantedBy=ceph-{fsid}.target """.format(fsid=args.fsid, data_dir=args.data_dir) return u diff --git a/test_ceph_daemon.sh b/test_ceph_daemon.sh index 705aa8c0aa1..cb01d1dfcf1 100755 --- a/test_ceph_daemon.sh +++ b/test_ceph_daemon.sh @@ -3,7 +3,10 @@ fsid=0a464092-dfd0-11e9-b903-002590e526e8 for f in `podman ps | awk '{print $1}' | grep -v CONT ` ; do podman kill $f ; done + for f in `systemctl | grep ceph | awk '{print $1}'` ; do systemctl stop $f ; systemctl disable $f ; done +rm /etc/systemd/system/ceph* +systemctl daemon-reload rm -rf /var/lib/ceph/$fsid/* rm -rf /var/log/ceph/$fsid/* -- 2.39.5