Skip to content

Use --ssh=<host>[:<path>] to run commands on remote servers#2755

Merged
danielbachhuber merged 3 commits into
masterfrom
2754-ssh
May 18, 2016
Merged

Use --ssh=<host>[:<path>] to run commands on remote servers#2755
danielbachhuber merged 3 commits into
masterfrom
2754-ssh

Conversation

@danielbachhuber
Copy link
Copy Markdown
Member

See #2754

Comment thread php/WP_CLI/Runner.php
WP_CLI::debug( 'SSH path: ' . $path, 'bootstrap' );

$is_tty = function_exists( 'posix_isatty' ) && posix_isatty( STDOUT );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter @jonathanbardo In situations where wp is defined by an alias or addition to PATH in a .bash_profile, have you found a way to load this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/usr/bin/env wp ?
I haven't tested yet. 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielbachhuber That's a valid scenario and I don't think we ever faced that problematic while we developed wp-cli-ssh.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, not quite:

local ➜  wp-cli git:(2754-ssh) ✗ wp --ssh=hb
/usr/bin/env: wp: No such file or directory

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a valid scenario and I don't think we ever faced that problematic while we developed wp-cli-ssh.

Unfortunately, it's a problem with the first server I tested with :(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it looks difficult.

  • Place the ~/.ssh/environment into local machine.
  • Add PermitUserEnvironment yes in /etc/ssh/sshd_config on remote server.

http://stackoverflow.com/questions/216202/why-does-an-ssh-remote-command-get-fewer-environment-variables-then-when-run-man

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielbachhuber This is why there was recent support for a wpcli_command config to handle situations where wp isn't on the PATH: xwp/wp-cli-ssh#27

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why there was recent support for a wpcli_command config to handle situations where wp isn't on the PATH: xwp/wp-cli-ssh#27

@westonruter Did you explore trying to get the data out of .bash_profile ? I'd prefer to not have to institute a workaround...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't. Also, perhaps the PHAR isn't even aliased as wp on the target environment. I think that there will ultimately need to be a way to provide an alternate path.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't. Also, perhaps the PHAR isn't even aliased as wp on the target environment. I think that there will ultimately need to be a way to provide an alternate path.

I ended up creating a WP_CLI_PRE_SSH_CMD env variable, to offer a bit more flexibility:

WP_CLI::add_hook( 'before_ssh', function() {
    if ( $ssh = WP_CLI::get_runner()->config['ssh'] ) {
        list( $host, $path ) = explode( ':', $ssh );
        switch( $host ) {
            case 'hb':
                putenv( 'WP_CLI_SSH_PRE_CMD=export PATH=$HOME/bin:$PATH' );
                break;
        }
    }
});

@rmccue
Copy link
Copy Markdown
Contributor

rmccue commented May 17, 2016

I'm not sure I see the difference between wp --ssh=x ... and ssh x -c 'wp ...'? Seems a little bit like reinventing stuff just for the sake of it to me.

@danielbachhuber
Copy link
Copy Markdown
Member Author

I'm not sure I see the difference between wp --ssh=x ... and ssh x -c 'wp ...'? Seems a little bit like reinventing stuff just for the sake of it to me.

This PR is the first part of #2039. Think wp @all core update

There's not much difference between wp core download and wget https://wordpress.org/latest.zip... except for the differences there are, and they are quite useful.

```
WP_CLI::add_hook( 'before_ssh', function() {
	if ( $ssh = WP_CLI::get_runner()->config['ssh'] ) {
		list( $host, $path ) = explode( ':', $ssh );
		switch( $host ) {
			case 'hb':
				putenv( 'WP_CLI_SSH_PRE_CMD=export PATH=$HOME/bin:$PATH' );
				break;
		}
	}
});
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants