4

I'm building a site which is using laravel envoy to run commands on a remote server. When a button is clicked to run a task then it is added to the Queue (I'm using redis and horizon) so that it is processed in the background and doesn't slow the site at all. I initially had issues with ssh access and public keys but that is sorted now, but the one remaining issue of it is the inconsistency with which the jobs run.

Let me start by saying that isn't an issue on my macbook pro and works reliably every time. Sometimes on my debian VPS, usually about 1 in 5 times, it will work fine, but then others it will not run the script at all. I'm checking in horizon and the job is definitely dispatched correctly every time but a job which is supposed to take about 40 seconds to complete is being finished in less than a second and I'm seeing nothing in my output (I've got a tracking system for the jobs so the user can see their status and the log after its run).

The code I'm using to run the envoy task is

exec('cd ' . base_path() . ' && /home/admin/.composer/vendor/bin/envoy run ' . $this->task . $this->query, $this->result);

$this->result is used to store the output of the envoy task and is coming back entirely empty when the task is not run correctly.

One other this is that I have tried it simply running exec('whoami') and received nothing back. On the ones where it was working correctly I received root.

I did have the thought that maybe the different queue workers are using different system users and therefore different public keys to try and connect but I can't find any information to back this up but it would explain the irregularity of it.

Any insight or help would be much appreciated!

Angus Allman
  • 511
  • 1
  • 6
  • 10
  • PHP's `exec()` doesn't capture the output to STDERR from the external program. To handle these on the PHP side, we need to redirect them to STDOUT: `exec('.../envoy/run ' . $this->task . $this->query . ' 2>&1', ...);` The external process runs under the same user account as the queue worker process, so check that keys are set up for that user. PHP on the VPS may be configured in [Safe Mode](https://secure.php.net/manual/en/ini.sect.safe-mode.php#ini.safe-mode-exec-dir) which limits which external programs we can call. For a more robust approach, try restructuring Envoy's `RunCommand` as a job. – Cy Rossignol Feb 15 '19 at 19:36

0 Answers0