From b767deb78e6aea8024749b5684a202b304dcd8c3 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 6 Mar 2020 17:43:33 -0600 Subject: [PATCH] cephadm: update unit.* atomically Some of these are run as bash scripts, which means that updating them can lead to the running bash picking up at a weird position mid-script when it goes to the next command. This produces weird errors like bash[9321]: /var/lib/ceph/f1758250-639e-11ea-9a42-001a4aab830c/mon.c/unit.run: line 2: -to-stderr=true: command not found Signed-off-by: Sage Weil --- src/cephadm/cephadm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index b55e123adaf..bd2cf393da2 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -1355,7 +1355,7 @@ def deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c, # type: (str, int, int, str, Union[int, str], CephContainer, bool, bool, Optional[str]) -> None # cmd data_dir = get_data_dir(fsid, daemon_type, daemon_id) - with open(data_dir + '/unit.run', 'w') as f: + with open(data_dir + '/unit.run.new', 'w') as f: if daemon_type == 'osd': # osds have a pre-start step assert osd_fsid @@ -1374,7 +1374,9 @@ def deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c, f.write(' '.join(prestart.run_cmd()) + '\n') f.write(' '.join(c.run_cmd()) + '\n') os.fchmod(f.fileno(), 0o600) - with open(data_dir + '/unit.poststop', 'w') as f: + os.rename(data_dir + '/unit.run.new', + data_dir + '/unit.run') + with open(data_dir + '/unit.poststop.new', 'w') as f: if daemon_type == 'osd': assert osd_fsid poststop = CephContainer( @@ -1391,10 +1393,14 @@ def deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c, ) f.write(' '.join(poststop.run_cmd()) + '\n') os.fchmod(f.fileno(), 0o600) + os.rename(data_dir + '/unit.poststop.new', + data_dir + '/unit.poststop') - with open(data_dir + '/unit.image', 'w') as f: + with open(data_dir + '/unit.image.new', 'w') as f: f.write(c.image + '\n') os.fchmod(f.fileno(), 0o600) + os.rename(data_dir + '/unit.image.new', + data_dir + '/unit.image') # systemd install_base_units(fsid) -- 2.39.5