drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.33k stars 1.08k forks source link

Drush 9 run with systemd service fails #4457

Closed johnramsden closed 4 years ago

johnramsden commented 4 years ago

Describe the bug

Identical commands run via a systemd service, and on the command line, fail when run under systemd.

This does not occur with older versions of drush.

I'm not sure if it is for all drush commands or just specific ones.

To Reproduce

Create a simple systemd service, for example one to run a backup:

[Unit]
Description=Run backup test

[Service]
Type=oneshot
Environment="DRUSH_PHP=/usr/bin/php7.2"
ExecStart=/var/www/web/example.org/vendor/drush/drush/drush \
                --root=/var/www/web/example.org/web \
                --uri=https://example.org \
                sql-dump --structure-tables-key=common \
                --result-file=/var/data/backup/db/auto/example.org.sql.gz --yes --gzip

Expected behavior

The back-up should be produced.

Actual behavior

No backup was produced:

systemctl status drush-backup-test.service

Jul 03 19:37:16 sk1 systemd[1]: Starting Run prod-uschess backup test...
Jul 03 19:37:16 sk1 systemd[1]: drush-backup-test.service: Main process exited, code=exited, status=255/n/a
Jul 03 19:37:16 sk1 systemd[1]: drush-backup-test.service: Failed with result 'exit-code'.
Jul 03 19:37:16 sk1 systemd[1]: Failed to start Run backup test.

The Identical command run on the command line or from cron works.

Workaround

Run via cron

System Configuration

Q A
Drush version? 9.7.2
Drupal version? 8.8.8
PHP version 7.2
OS? Ubuntu 18.04 Linux

Additional information

I've also noticed failures with civicrm:api, when running it the same way. It just fails.

greg-1-anderson commented 4 years ago

Drush 8 and earlier had a shell script that took some effort to set up your environment for you; however, Drush 9 and later assume that you have PHP in your PATH (and mysql, and any other binaries you need), and your php.ini is correct and so on.

Make sure that your PATH and php.ini are correct in the context that you're trying to use Drush in. Also, Drush 9 is getting minimal / no support any more, so you should also update to Drush 10 while you are working on this.

johnramsden commented 4 years ago

I'm just getting a silent failure though. Is there any way to see what it would be having trouble finding? My binaries are all in the default PATH.

greg-1-anderson commented 4 years ago

Have you tried running with --debug?

johnramsden commented 4 years ago

@greg-1-anderson Yes, no output.

greg-1-anderson commented 4 years ago

Can you run a trivial PHP program using the same technique?

Also, I noticed you set the DRUSH_PHP environment variable, which is only used in Drush 8 and earlier.