]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-daemon: allow shell to take optional command
authorSage Weil <sage@redhat.com>
Wed, 23 Oct 2019 16:05:00 +0000 (11:05 -0500)
committerSage Weil <sage@redhat.com>
Wed, 23 Oct 2019 20:08:55 +0000 (15:08 -0500)
This is different from 'exec' in that it creates a new container instead
of entering an existing one.

Signed-off-by: Sage Weil <sage@redhat.com>
src/ceph-daemon

index c6b1ad183af1e9821e8b3df32fde6e708ff9b725..0f1a722a560a8e3769c7828c1f6cf470868e44b5 100755 (executable)
@@ -654,7 +654,7 @@ class CephContainer:
             self.image
         ] + self.args
 
-    def shell_cmd(self):
+    def shell_cmd(self, cmd):
         vols = sum(
             [['-v', f'{host_dir}:{container_dir}']
              for host_dir, container_dir in self.volume_mounts.items()], [])
@@ -662,6 +662,9 @@ class CephContainer:
             '-e', f'CONTAINER_IMAGE={self.image}',
             '-e', f'NODE_NAME={get_hostname()}',
         ]
+        cmd_args = []
+        if cmd:
+            cmd_args = ['-c'] + cmd
         return [
             podman_path,
             'run',
@@ -670,9 +673,9 @@ class CephContainer:
             '--privileged',
             '--env', 'LANG=C',
         ] + self.podman_args + envs + vols + [
-            '--entrypoint', '/bin/bash',
+            '--entrypoint', cmd[0],
             self.image
-        ]
+        ] + cmd[1:]
 
     def exec_cmd(self, cmd):
         return [
@@ -1094,7 +1097,7 @@ def command_shell():
         args=[],
         podman_args=['--privileged'],
         volume_mounts=mounts)
-    subprocess.call(c.shell_cmd())
+    subprocess.call(c.shell_cmd(args.command))
 
 ##################################
 
@@ -1438,6 +1441,10 @@ parser_shell.add_argument(
 parser_shell.add_argument(
     '--keyring', '-k',
     help='ceph.keyring to pass through to the container')
+parser_shell.add_argument(
+    'command', nargs='*',
+    default=['bash'],
+    help='command (optional)')
 
 parser_enter = subparsers.add_parser(
     'enter', help='run an interactive shell inside a running daemon container')