terminus
terminus copied to clipboard
AL-1691: Not able to capture remote command output
Expected behavior
In our Behat test, we call Terminus 1.9.1 to generate the one time login URL for certain user:
$uli = shell_exec("terminus drush $project_name.$site_name uli $user_name");
Expect $uli to contain the login URL. Was working with earlier version of Terminus before the progress bar was added.
Actual behavior
$uli is always empty.
Steps to reproduce the behavior
In a Linux shell, this can be emulated by running PHP commands. With Terminus 1.9.1, run:
php -r 'echo shell_exec("terminus drush A_PROJECT_NAME.A_SITE_NAME uli A_USER_NAME");'
Also tried to append "2>&1" at the end of Terminus command to include stderr and stdout but no improvement.
Noticed that I cannot save the output of Drush commands into a file either:
# terminus drush $CIRCLE_PROJECT_REPONAME.$CIRCLE_BRANCH version > output
[warning] This environment is in read-only Git mode. If you want to make changes to the codebase of this site (e.g. updating modules or plugins), you will need to toggle into read/write SFTP mode first.
[>---------------------------]
[->--------------------------]
[-->-------------------------]
[--->------------------------]
[---->-----------------------]
[----->----------------------]
[------>---------------------]
[------->--------------------]
[-------->-------------------]
[--------->------------------]
[---------->-----------------]
[----------->----------------]
[------------>---------------]
[------------->--------------]
[-------------->-------------]
[--------------->------------]
[---------------->-----------]
[----------------->----------]
[------------------>---------]
[------------------->--------]
[-------------------->-------]
[--------------------->------]
[---------------------->-----]
[----------------------->----]
[------------------------>---]
[------------------------->--]
[-------------------------->-]
[--------------------------->]
[>---------------------------]
[->--------------------------]
[-->-------------------------]
[--->------------------------]
[---->-----------------------]
[----->----------------------]
[------>---------------------]
[------->--------------------]
[-------->-------------------]
[--------->------------------]
[---------->-----------------]
[----------->----------------]
[------------>---------------]
[------------->--------------] [notice] Command: PROJECT_NAME.SITE_NAME -- drush version [Exit: 0]
# cat output
#
Local command can be captured:
# terminus --version > output
# cat output
Terminus 1.9.1
This is being tracked internally as AL-1691
Hi - is this still being tracked? I have a situation where I'm not seeing any output from remote drush calls via Terminus, wondering if it's the same issue:
$ terminus remote:drush <project>.<env> -- status
[notice] Command: <project>.<env> -- drush status [Exit: 0]
$ terminus --version
Terminus 2.3.0
Happy to open a new issue if need be.
Hi, I'm also experiencing a similar issue. When running:
terminus drush <project>.<env> status
(or any other command)
terminus ends with no status info. On Drupal 8 sites, I just get:
"[notice] Command: <project>.<env> -- drush status [Exit: 0]"
on Drupal 7 sites, I get:
"printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}""
I'm using the default bash on Centos8, I also tested with zsh but I got the same results. This is my self:info:
terminus self:info:
PHP binary /usr/bin/php
PHP version 7.2.11
php.ini used /etc/php.ini
Terminus project config
Terminus root dir phar:///home/myuser/bin/terminus
Terminus version 2.3.0
Operating system #1 SMP Fri Jan 3 23:55:26 UTC 2020
I'm on CentOS 7, site is Drupal 8. My self:info
$ terminus self:info
------------------------- -------------------------------------
PHP binary /usr/bin/php
PHP version 7.3.17
php.ini used /etc/php.ini
Terminus project config
Terminus root dir phar:///usr/local/bin/terminus
Terminus version 2.3.0
Operating system #1 SMP Tue Mar 31 23:36:51 UTC 2020
------------------------- -------------------------------------
I did more sleuthing, the strace is interesting - it looks like terminus is getting data back from Pantheon, but is unable to output it. In this strace, I just ran "drush version". We can see the drush version coming back correctly as "Drush version : 9.7.2", bit it is unable to write to the TTYs. We then see the notice that the command was executed and exited with status 0.
Here's the relevant bits:
1379 <... select resumed>) = 0 (Timeout)
1379 select(12, [9 11], [], [], {tv_sec=0, tv_usec=200000} <unfinished ...>
1386 <... select resumed>) = 1 (in [3])
1386 clock_gettime(CLOCK_BOOTTIME, {tv_sec=16215, tv_nsec=221236203}) = 0
1386 read(3, "\rs\237\335a\225\36\27\321O\0\253\345\354\322(\241\246w6\315;\16\220\25567\34\345L\21\216\340\256y\335\3\211^\224\252\245>q\26\225\230`\336\222U\267@g)(h%\214O", 8192) = 60
1386 clock_gettime(CLOCK_BOOTTIME, {tv_sec=16215, tv_nsec=221383154}) = 0
1386 clock_gettime(CLOCK_BOOTTIME, {tv_sec=16215, tv_nsec=221443820}) = 0
1386 select(8, [3], [6], NULL, NULL) = 1 (out [6])
1386 clock_gettime(CLOCK_BOOTTIME, {tv_sec=16215, tv_nsec=221579044}) = 0
1386 write(6, " Drush version : 9.7.2 \n", 24) = 24
1379 <... select resumed>) = 1 (in [9], left {tv_sec=0, tv_usec=44199})
1386 clock_gettime(CLOCK_BOOTTIME, {tv_sec=16215, tv_nsec=221905855}) = 0
1386 clock_gettime(CLOCK_BOOTTIME, <unfinished ...>
1379 read(9, <unfinished ...>
1386 <... clock_gettime resumed>{tv_sec=16215, tv_nsec=221944231}) = 0
1379 <... read resumed>" Drush version : 9.7.2 \n", 8192) = 24
1386 select(8, [3], [], NULL, NULL <unfinished ...>
1379 read(9, 0x7fa39ba53000, 8192) = -1 EAGAIN (Resource temporarily unavailable)
1379 select(12, [9 11], [], [], {tv_sec=0, tv_usec=200000} <unfinished ...>
1386 <... select resumed>) = 1 (in [3])
1386 clock_gettime(CLOCK_BOOTTIME, {tv_sec=16215, tv_nsec=235546115}) = 0
1386 read(3, "\3&\22\220\222\352\321\204\272\231\37U\3310\362\335\272\322\231u\307qZt\0#\260\263{\231\1L\247\310\323p!\305\tR\0053\2231\4\227\342\344J\337\2 >\3\0#\236\273\216\264\6\\>\370,\327\353\\|\344\350A\35x\267\366o\216\24\\\7|]\16T\313\30.", 8192) = 88
1386 clock_gettime(CLOCK_BOOTTIME, {tv_sec=16215, tv_nsec=235699785}) = 0
1386 clock_gettime(CLOCK_BOOTTIME, {tv_sec=16215, tv_nsec=235758920}) = 0
1386 close(6) = 0
1386 close(7) = 0
1386 select(8, [3], [3], NULL, NULL) = 1 (out [3])
1386 clock_gettime(CLOCK_BOOTTIME, {tv_sec=16215, tv_nsec=236027801}) = 0
1386 write(3, "\326R\355\270Z\270\336vv\3048\252[^\31ZD\212\3\325\261K\303l\247\246\6\201\336C\204x)T\253!", 36) = 36
1386 rt_sigaction(SIGWINCH, NULL, {sa_handler=0x561f5cf6e040, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96ab307400}, 8) = 0
1386 rt_sigaction(SIGWINCH, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96ab307400}, NULL, 8) = 0
1386 write(3, "\337}\21\345\357\32486q\fC\355=\0333\367+*\207B\373h7\223\2778\26\360F%\300<'J\211\203\23\311kP\\\3\303\214\n\272\3457\370Ob\351\354\324\366\v//7\205", 60) = 60
1386 ioctl(0, TCGETS, 0x7ffdd49de4e0) = -1 ENOTTY (Inappropriate ioctl for device)
1386 fcntl(0, F_GETFL) = 0x800 (flags O_RDONLY|O_NONBLOCK)
1386 fcntl(0, F_SETFL, O_RDONLY) = 0
1386 ioctl(1, TCGETS, 0x7ffdd49de4e0) = -1 ENOTTY (Inappropriate ioctl for device)
1386 fcntl(1, F_GETFL) = 0x801 (flags O_WRONLY|O_NONBLOCK)
1386 fcntl(1, F_SETFL, O_WRONLY) = 0
1386 ioctl(2, TCGETS, 0x7ffdd49de4e0) = -1 ENOTTY (Inappropriate ioctl for device)
1386 fcntl(2, F_GETFL) = 0x801 (flags O_WRONLY|O_NONBLOCK)
1386 fcntl(2, F_SETFL, O_WRONLY) = 0
1386 shutdown(3, SHUT_RDWR) = 0
1386 close(3) = 0
1386 exit_group(0) = ?
1386 +++ exited with 0 +++
1379 <... select resumed>) = 2 (in [9 11], left {tv_sec=0, tv_usec=182969})
1379 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1386, si_uid=3020, si_status=0, si_utime=0, si_stime=1} ---
1379 read(9, "", 8192) = 0
1379 close(9) = 0
1379 read(11, "", 8192) = 0
1379 close(11) = 0
1379 wait4(1386, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WNOHANG|WSTOPPED, NULL) = 1386
1379 wait4(1386, 0x7ffc9ece0bc4, 0, NULL) = -1 ECHILD (No child processes)
1379 write(4, " \33[37;46;1m[notice]\33[39;49;22m Command: \33[32msed-cms1\33[39m.\33[32mtest\33[39m -- \33[32mdrush version\33[39m [Exit: 0]\n", 111) = 111
Hey @greg-1-anderson, could you weigh in on this?
This is reproducible in AWS - if you spin up a t3 instance with this ami -https://aws.amazon.com/marketplace/pp/B00O7WM7QW (the official CentOS 7 AMI), I’d expect you to see the same error.
Using the latest Terminus 2.3.1 dev:
php -r '$url = rtrim(shell_exec("terminus drush site.dev uli admin -- --browser=0")); print ">>> $url <<<";'
[notice] Command: site.dev -- drush uli admin [Exit: 0]
>>> http://dev-site.pantheonsite.io/user/reset/1/REDACTED/REDACTED/login?destination=admin <<<
Did this on MacOS Catalina.
Windows users can expect no output due to https://github.com/pantheon-systems/terminus/issues/1879, but I usually would expect Linux and MacOS to behave similarly.
You could try adding the Drush flag --no-browser and the Terminus flag -n and --no-ansi and see if any of those help. I get the same (correct) result with any permutation of those flags, though.
Do you have the POSIX extensions available in your PHP? Try:
php -r 'var_export(function_exists("posix_isatty"));'
If this returns false, try installing the POSIX extensions per https://www.php.net/manual/en/posix.installation.php
n.b. Posix should be available by default in most instances, but it's good to check. This is the reason that Windows doesn't work -- bugs in Terminus' non-POSIX handling.
Thanks @greg-1-anderson - the -n flag worked for me.
Additionally, it turned out that in my case, I hadn't installed php73-process.x86_64, which provides the POSIX functionality. Once I installed that, php -r 'var_export(function_exists("posix_isatty"));' returned true as expected, and my remote drush commands work now.
I'd humbly request that some sort of note be added to https://pantheon.io/docs/terminus/install ; it doesn't mention it there (which makes sense, since it isn't supported on Windows), but that would have saved me a whole heap of time and trouble.
@derytim looking for some clarity on this issue. Could you summarize what system you were using (where you installed php73-process.x86_64) and the specific steps you took that resolved your issue? It's not clear if you were on a Windows or Win10 machine using WSL Windows Subsystem Linux, or something else?
@carolyn-shannon sorry for the lag. This was on a CentOS 7 machine.
Once I installed php73-process.x86_64, my issue was resolved.
The install documentation at https://pantheon.io/docs/terminus/install doesn't say anything about needing package php73-process.x86_64; while you can run some Terminus commands without it, Terminus can't write out to the screen via PHP without it (which is the situation I was in).
@carolyn-shannon n.b. also that the package name php73-process.x86_64 will vary depending on your O.S. and PHP version.