If you try to run a command on a remote alias such as sql-cli, the command will hang as no terminal is allocated by SSH. I don't see any reason to ever *not* allocate a terminal, so it makes sense to allocate one by default.

CommentFileSizeAuthor
drush-allocate-terminal.patch1.38 KBdeviantintegral

Comments

greg.1.anderson’s picture

Status: Active » Needs work

With this patch, non-interactive commands now say:

Connection to [servername] closed.

It can also get worse; for example, on one site, I get this with the patch above applied:

Drush command terminated abnormally due to an unrecoverable error.
Error: syntax error, unexpected T_STRING in
.../drush_deploy/deploy.drush.inc,
line 40
Connection to [servername] closed.

The same command works fine without this patch (no -t option passed to ssh).

Basically, what is going on above is that allocating the terminal causes the initialization of the shell to be done differently; even though Drush is working fine with a regular ssh session, and even though it works without this patch, with the terminal allocated, the wrong version (an older version) of PHP is selected, and some class-related code in Drush Deploy is reported as a syntax error. While this is essentially a problem with the configuration of my one host, it is not evidenced under normal circumstances, and the cause is subtle.

For both of these reasons, I think this is not a desirable change. We should find a way to allocate a termi
nal conditionally, only if the remote command needs it (i.e., is interactive).

I will introduce conditional use of -t in #1982274: Allow cd root first for the ssh command, and we can continue here for other interactive commands.

greg.1.anderson’s picture

I have not tried this yet, but it looks like if you put a command-specific option 'tty' in your site alias (e.g. for sql-cli), then the -t will be added.

greg.1.anderson’s picture

Version: 7.x-5.x-dev » 8.x-6.x-dev

To determine whether a command should get a tty or not, you'd have to parse the arguments of the drush ssh command. This isn't really convenient.

Folks who want -t to be the default can set $command_specific['ssh']['tty'] = TRUE; in a drushrc.php file.

A patch to add this functionality to _drush_backend_generate_command would be welcome, if it is needed. Any ideas on how to determine when to allocate a tty would also be welcome.

deviantintegral’s picture

-q looks to hide that message.

I'm thinking instead of trying to parse the string (which gets hairy with command flags), I wonder if we could add something to hook_drush_commands() that indicates the command needs a TTY. If that's set, whenever a command is piped through SSH we add -tq to the command. Thoughts?

greg.1.anderson’s picture

The thing is, if you are running an ssh command, the final target command appears only in the command args to ssh; hook_drush_commands is not involved until after you have dispatched through ssh (that is, the hook that you want to run executes on the remote target machine, not your local machine).

greg.1.anderson’s picture

Status: Needs work » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.