From be9b7819d7bde47c4fa5e7919a8d2973e222c055 Mon Sep 17 00:00:00 2001 From: Redouane Kachach Date: Mon, 25 Apr 2022 17:43:57 +0200 Subject: [PATCH] mgr/cephadm: fix unit.stop for ceph daemons Fixes: https://tracker.ceph.com/issues/55466 Signed-off-by: Redouane Kachach --- src/cephadm/cephadm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 0de6dc4e523..4ec3cd74c23 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -3356,8 +3356,12 @@ def deploy_daemon_units( # post-stop command(s) with open(data_dir + '/unit.stop.new', 'w') as f: - f.write('! ' + ' '.join(c.stop_cmd()) + '\n') - f.write('! ' + ' '.join(c.stop_cmd(old_cname=True)) + '\n') + # following generated script basically checks if the container exists + # before stopping it. Exit code will be success either if it doesn't + # exist or if it exists and is stopped successfully. + container_exists = f'{ctx.container_engine.path} inspect %s &>/dev/null' + f.write(f'! {container_exists % c.old_cname} || {" ".join(c.stop_cmd(old_cname=True))} \n') + f.write(f'! {container_exists % c.cname} || {" ".join(c.stop_cmd())} \n') os.fchmod(f.fileno(), 0o600) os.rename(data_dir + '/unit.stop.new', @@ -3683,7 +3687,7 @@ LimitNOFILE=1048576 LimitNPROC=1048576 EnvironmentFile=-/etc/environment ExecStart=/bin/bash {data_dir}/{fsid}/%i/unit.run -ExecStop=-/bin/bash -c '{container_path} stop ceph-{fsid}-%i ; bash {data_dir}/{fsid}/%i/unit.stop' +ExecStop=-/bin/bash -c 'bash {data_dir}/{fsid}/%i/unit.stop' ExecStopPost=-/bin/bash {data_dir}/{fsid}/%i/unit.poststop KillMode=none Restart=on-failure @@ -3695,8 +3699,7 @@ StartLimitBurst=5 {extra_args} [Install] WantedBy=ceph-{fsid}.target -""".format(container_path=ctx.container_engine.path, - fsid=fsid, +""".format(fsid=fsid, data_dir=ctx.data_dir, extra_args=extra_args, # if docker, we depend on docker.service -- 2.47.3