Problem/Motivation
I want to execute a command with 'drush ssh' inside the root of the site. But this is not allowed for the 'drush ssh' command. When looking at the core functions that run ssh it passes a 'cd = TRUE' to allow cd to root.
Proposed resolution
It was thinking of two solutions.
- One would be to add a --root options introducted for ssh. This does the same as when a command is run for drush.
- The other would be to allow the replacing of variables inside the command. For example: drush @dev ssh 'ls %root' would ls the root folder. Or drush @dev ssh 'ls %root/..' would list the parent folder of root. This last option is the most powerfull I think.
Remaining tasks
- Get agreement on the solution to choose or a implement both.
(reviews needed, tests to be written or run, documentation to be written, etc.)
API changes
The core API does not change but is extended. All other functionality keeps working the same I believe.
(A list of related issues.)
Comments
Comment #1
greg.1.anderson commentedI think it would be fair game to have the ssh command always cd to the root before running the user-provided command. See examples.bashrc (specifically, in the 'gitd' alias) for an example.
Patches welcome.
Comment #2
matglas86 commentedHaving ssh alway cd into root would break existing implementations I think for people. If you have build your script around the fact that ssh alway logs in to the root of the remote user and do actions there it breaks your script when we would cd 'automagicly' into the drupal root.
Comment #3
greg.1.anderson commentedIt is fair game to break backwards compatibility on major releases of Drush (e.g. Drush 6.x). I'd be fine with a flag to control the behavior, but I think that the default should be to cd to root. I'm not fond of doing replacements on the ssh command provided by the user.
Comment #4
moshe weitzman commentedI agree that the default should be to cd into drupal root.
Comment #5
matglas86 commentedMight it be an option to implement this as default behavior but backport it with a option?
Comment #6
greg.1.anderson commentedBy policy, default behavior in the 7.x-5.x branch must remain consistent, so yes.
Comment #7
greg.1.anderson commentedWorking on this; it's pretty useful. I'll put up a patch soon; need to add -t to ssh options when just doing a 'normal' ssh (interactive shell). See related issue, #1991126: Default SSH to include -t so sql-cli works on remote aliases.
Comment #8
greg.1.anderson commentedHere is a patch that adds the cd to the beginning of the commands. It also correctly handles interactive mode for simple ssh sessions with no command. Somehow, I like
drush @site ssh git pullbetter thangit @site pull. Even though the later is fewer keystrokes, the former just makes more intrinsic sense to me. Even though I wrote the bash function that makes the later possible, it still feels odd.Comment #9
matglas86 commentedThis looks great. I was just about to post a patch but this look even better.
Comment #10
greg.1.anderson commentedCommitted as 3e027bd, with the addition of a --cd option to specify which directory to cd to -- or use
--cd=0(or$options['cd'] = FALSE;) to disable. Docs included to show command-specific example in examples.drushrc.php.Comment #11
greg.1.anderson commentedFixed failing unit tests.