hechoendrupal / drupal-console

The Drupal CLI. A tool to generate boilerplate code, interact with and debug Drupal.
http://drupalconsole.com
GNU General Public License v2.0
939 stars 559 forks source link

drupal: command errors when called from bash file #3892

Open arnaudom opened 6 years ago

arnaudom commented 6 years ago

drupal: command errors when called from bash file

I am trying to launch a custom command from bash file. The bash file (postfix.sh) is called by postfix when receiving email from multisites configuration and will run the following command:

[1] drupal --uri=${array[1]} custom:pipemail

where ${array[1]} is the target site.

When executing the command manually as test from console, drupal command is executed normally, i.e.:

cat ~/test_email.txt | /path/to/postfix.sh -d <from@email> <size> <to@email>

custom:pipemail is executed subsequently

However when postfix call the same bash file directly, as below example

hookTestPipe     unix  -       n       n       -       -       pipe
  flags=F user=ubuntu   argv=/path/to/postfix.sh   ${sender} ${size} ${recipient}

the command is not executed:

postfix/pipe: to=to@email, relay=hook, delay=1, delays=1/0/0/0.01, dsn=5.3.0, status=bounced (Command died with status 127: "/path/to/postfix.sh". Command output: /path/to/postfix.sh: line 55: drupal: command not found )

In both cases (manual or postfix) it is confirmed that the same server user is used and the command is called within the drupal installation folder;

When changing the path in [1] above with full path to drupal console: /path/to/vendor/drupal/console/bin/drupal, the command run, but will generate the following error:

Fatal error: Uncaught RuntimeException: Your environment or operation system isn't supported in /path/to/vendor/webmozart/path-util/src/Path.php:257
Stack trace:
#0 /path/to/vendor/drupal/console-core/src/Utils/ConfigurationManager.php(452): Webmozart\PathUtil\Path::getHomeDirectory()
#1 /path/to/vendor/drupal/console-core/src/Utils/ConfigurationManager.php(251): Drupal\Console\Core\Utils\ConfigurationManager->getHomeDirectory()
#2 /path/to/vendor/drupal/console-core/src/Utils/ConfigurationManager.php(323): Drupal\Console\Core\Utils\ConfigurationManager->getConsoleDirectory()
#3 /path/to/vendor/drupal/console-core/src/Utils/ConfigurationManager.php(48): Drupal\Console\Core\Utils\ConfigurationManager->locateConfigurationFiles()
#4 /path/to/vendor/drupal/console/bin/drupal.php(59): Drupal\Console\Core\Utils\ConfigurationManager->loadConfiguration('/path/to/App')
#5 /path/to/vendor/drupal/console/bin/drupal(4): require('/path/to/...')
#6 {main}
  thrown in /path/to/vendor/webmozart/path-util/src/Path.php on line 257

Question: what would be the way to simply run "drupal" in bash script with same result as when it is called from the console ?

Thank you in advance for support.

marcelovani commented 6 years ago

Try this: instead of cat ~/test_email.txt, use the full path i.e. cat /Users/root/test_email.txt

arnaudom commented 6 years ago

In the script file, console is triggered with full path : /var/www/App/vendor/drupal/console/bin/drupal . (~ is only use in the manual test to pickup the test file and pipe it to the script, which is working as expected).