(self, username=None, command=None)
Opens a new interactive shell in the container.
Opens a new interactive shell in the container.
Opens a new interactive shell in the container .
def shell(self, username=None, command=None):
        """ Opens a new interactive shell in the container. """
        # We run this in case our lxdock.yml config was modified since our last `lxdock up`.
        self._setup_env()

        # For now, it's much easier to call `lxc`, but eventually, we might want to contribute
        # to pylxd so it supports `interactive = True` in `exec()`.
        shellcfg = self.options.get('shell', {})
        shelluser = username or shellcfg.get('user')
        if shelluser:
            cmd = 'lxc exec {} -- su -l {}'.format(self.lxd_name, shelluser)
        else:
            cmd = 'lxc exec {} -- su -l root'.format(self.lxd_name)

        # Optionally run a command and exit.
        # For multiple commands use: lxdock shell -c "command1; command2"
        if command:
            # Again, a bit of trial-and-error.
            # 1. Using `su -s SCRIPT_FILE` instead of `su -c COMMAND` because `su -c` cannot
            #    receive SIGINT (Ctrl-C).
            #    Ref: //sethmiller.org/it/su-forking-and-the-incorrect-trapping-of-sigint-ctrl-c/
            #    See also: //github.com/lxdock/lxdock/pull/67#issuecomment-299755944

            self._guest.run(['mkdir', '-p',
                             str(PurePosixPath(self._guest_shell_script_file).parent)])
            self._container.files.put(self._guest_shell_script_file, textwrap.dedent(
                """\
                #!/bin/sh
                export SHELL=/bin/sh
                {}
                """.format(command)))
            self._guest.run(['chmod', 'a+rx', self._guest_shell_script_file])
            cmd += ' -s {}'.format(self._guest_shell_script_file)

        subprocess.call(cmd, shell=True)
def shell ( self , username = None , command = None ) : # We run this in case our lxdock.yml config was modified since our last `lxdock up`. self . _setup_env ( ) # For now, it's much easier to call `lxc`, but eventually, we might want to contribute # to pylxd so it supports `interactive = True` in `exec()`. shellcfg = self . options . get ( 'shell' , { } ) shelluser = username or shellcfg . get ( 'user' ) if shelluser : cmd = 'lxc exec {} -- su -l {}' . format ( self . lxd_name , shelluser ) else : cmd = 'lxc exec {} -- su -l root' . format ( self . lxd_name ) # Optionally run a command and exit. # For multiple commands use: lxdock shell -c "command1; command2" if command : # Again, a bit of trial-and-error. # 1. Using `su -s SCRIPT_FILE` instead of `su -c COMMAND` because `su -c` cannot #    receive SIGINT (Ctrl-C). #    Ref: //sethmiller.org/it/su-forking-and-the-incorrect-trapping-of-sigint-ctrl-c/ #    See also: //github.com/lxdock/lxdock/pull/67#issuecomment-299755944 self . _guest . run ( [ 'mkdir' , '-p' , str ( PurePosixPath ( self . _guest_shell_script_file ) . parent ) ] ) self . _container . files . put ( self . _guest_shell_script_file , textwrap . dedent ( """\
                #!/bin/sh
                export SHELL=/bin/sh
                {}
                """ . format ( command ) ) ) self . _guest . run ( [ 'chmod' , 'a+rx' , self . _guest_shell_script_file ] ) cmd += ' -s {}' . format ( self . _guest_shell_script_file ) subprocess . call ( cmd , shell = True )