From: Redouane Kachach Date: Mon, 25 Apr 2022 15:43:57 +0000 (+0200) Subject: mgr/cephadm: fix unit.stop for ceph daemons X-Git-Tag: v17.2.1~48^2~29 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6e67962e95e6667debe5ed3dd161f45ec25e070a;p=ceph.git mgr/cephadm: fix unit.stop for ceph daemons Fixes: https://tracker.ceph.com/issues/55466 Signed-off-by: Redouane Kachach (cherry picked from commit be9b7819d7bde47c4fa5e7919a8d2973e222c055) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 1ff90e9b30c5..d55ff026ef2b 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -3350,8 +3350,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', @@ -3677,7 +3681,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 @@ -3689,8 +3693,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