From 2485ac2726e81e5aa90ea6c900b9f455f1e1bbc6 Mon Sep 17 00:00:00 2001 From: Paul Cuzner Date: Mon, 14 Sep 2020 16:01:54 +1200 Subject: [PATCH] cephadm: Change location of cephadm daemon start up file The cephadm daemon now uses a unit.run file, mirroring the ceph daemons. Signed-off-by: Paul Cuzner --- src/cephadm/cephadm | 55 +++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index bde62848c240c..e119f67a87be4 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -4115,9 +4115,9 @@ def command_rm_daemon(): os.rename(data_dir, os.path.join(backup_dir, dirname)) else: - call_throws(['rm', '-rf', data_dir]) if daemon_type == CephadmDaemon.daemon_type: CephadmDaemon.uninstall(args.fsid, daemon_type, daemon_id) + call_throws(['rm', '-rf', data_dir]) ################################## @@ -5272,7 +5272,12 @@ def command_gather_facts(): class CephadmDaemonHandler(BaseHTTPRequestHandler): def do_GET(self): - # return the current state of the cache + """Handle *all* GET requests""" + + # we could wrap this to include some form of auth, but at this point the + # data is read only and we offer no means of remotely invoking a cephadm + # command - so auth is not required (we're basically in the same category + # as the prometheus node-exporter) self.send_response(200) self.send_header('Content-type','application/json') self.end_headers() @@ -5289,6 +5294,7 @@ class CephadmHTTPServer(ThreadingMixIn, HTTPServer): class CephadmDaemon(): + daemon_type = "cephadm" default_port = 5003 bin_name = 'cephadm' @@ -5321,13 +5327,21 @@ class CephadmDaemon(): # since that only expects daemons to be containers and cephadmd is not! return CephadmDaemon._unit_name(self.fsid, self.daemon_id) + @property + def daemon_path(self): + return os.path.join( + args.data_dir, + self.fsid, + f'cephadm.{self.daemon_id}' + ) + @property def binary_path(self): return os.path.join( - args.data_dir, - self.fsid, - f'cephadm.{self.daemon_id}', - CephadmDaemon.bin_name) + self.daemon_path, + CephadmDaemon.bin_name + ) + def _scrape_host_facts(self, refresh_interval=10): ctr = 0 @@ -5506,9 +5520,19 @@ class CephadmDaemon(): logger.info("Main http server thread stopped") + @property + def unit_run(self): + + return """set -e +{py3} {bin_path} cephadmd --fsid {fsid} --port {port}""".format( + py3 = shutil.which('python3'), + bin_path=self.binary_path, + fsid=self.fsid, + port=self.port + ) + @property def unit_file(self): - py3 = shutil.which('python3') return """#generated by cephadm [Unit] Description=cephadm data service (web interface) for cluster {fsid} @@ -5520,17 +5544,16 @@ Before=ceph-{fsid}.target [Service] Type=simple -ExecStart={py3} {bin_path} cephadmd --fsid {fsid} --port {port} +ExecStart=/bin/bash {daemon_path}/unit.run Restart=on-failure RestartSec=10s [Install] WantedBy=ceph-{fsid}.target """.format( - py3=py3, fsid=self.fsid, - bin_path=self.binary_path, - port=self.port) + daemon_path=self.daemon_path +) def deploy_daemon_unit(self): """deploy a specific unit file for cephadm @@ -5541,6 +5564,9 @@ WantedBy=ceph-{fsid}.target """ shutil.copy(__file__, self.binary_path) + + with open(os.path.join(self.daemon_path, 'unit.run'), "w") as f: + f.write(self.unit_run) with open(os.path.join(args.unit_dir, f"{self.unit_name}.new"), "w") as f: f.write(self.unit_file) @@ -5559,11 +5585,12 @@ WantedBy=ceph-{fsid}.target def uninstall(cls, fsid, daemon_type, daemon_id): unit_name = CephadmDaemon._unit_name(fsid, daemon_id) unit_path = os.path.join(args.unit_dir, unit_name) + unit_run = os.path.join(args.data_dir, fsid, f"{daemon_type}.{daemon_id}", "unit.run") try: - with open(unit_path, "r") as u: + with open(unit_run, "r") as u: contents = u.read().strip() except OSError: - logger.warning(f"Unable to access the systemd file @ {unit_path}") + logger.warning(f"Unable to access the unit.run file @ {unit_run}") return for line in contents.split('\n'): @@ -5571,7 +5598,7 @@ WantedBy=ceph-{fsid}.target try: port = int(line.split('--port ')[-1]) except ValueError: - logger.warning("Unexpected format in unit file: port is not numeric") + logger.warning("Unexpected format in unit.run file: port is not numeric") logger.warning("Unable to remove the systemd file and close the port") return break -- 2.39.5