stechstudio / laravel-ssh-tunnel

Easy creation & maintenance of an SSH Tunnel for Laravel/Lumen
MIT License
191 stars 46 forks source link

Command seems to run manually but Laravel won't run it. #16

Closed AdrianwithaW closed 6 years ago

AdrianwithaW commented 6 years ago

Am getting the following error inside of Laravel:

Could Not Create SSH Tunnel with command: /usr/bin/ssh -N -i /Users/adrian/.ssh/key.pem -L 13306:127.0.0.1:3306 -p 22 name@server.com Check your configuration.

However when I copy and run the command manually it works fine - my SQL client then connects to the database at the other end of the tunnel.

If I run php artisan tunneler:activate then I get I have no idea how this happened. Let me know if you figure it out. followed by the same error message.

Not entirely sure where to start checking as I'm assuming it's configured fine. Using Laravel 5.5 with PHP 7.0.12. Any suggestions what might be the problem?

AdrianwithaW commented 6 years ago

DUH. Ignore me sorry, had misconfigured something in Homestead that was stopping it.

josephwallingford commented 6 years ago

@AdrianwithaW Care to elaborate on what was stopping it? I'm running into the same thing myself.

AdrianwithaW commented 6 years ago

No I never did quite figure it out. Started running it after connecting to vagrant box via ssh but it still doesn’t work. I just run the command manually and it works ¯_(ツ)_/¯

bubba-h57 commented 6 years ago

When the command works fine manually but does not work in the code, I would look at permissions. Probably the code is running under a different user than you run it as. It makes sense that a vagrant box would work because a lot of times jobs are just run as root or another very privileged account in vagrant.

josephwallingford commented 6 years ago

I did figure out what was going on. My issue was two things:

  1. According to the upgrade guide for Laravel 5.5 "If you would like to dispatch a job that runs immediately and returns a value from the handle method, you should use the dispatch_now or Bus::dispatchNow method to dispatch the job." After I made this change in the source code it would get an integer instead of the Job class object. This isn't backwards compatible with versions before 5.5 though.
  2. The default configuration of 0.5 seconds for TUNNELER_CONN_WAIT to check if the tunnel was already open was too short for me, upping it to 1 second did the trick.