ssh tunnel script hangs forever on beanstalk deployment

Viewed 147

I'm attempting to create a ssh tunnel, when deploying an application to aws beanstalk. I want to put the tunnel as a background process, that is always connected on application deploy. The script is hanging forever on the deployment and I can't see why.

"/home/ec2-user/eclair-ssh-tunnel.sh":
mode: "000500" # u+rx
owner: root
group: root
content: |
  cd /root
  eval $(ssh-agent -s)
  DISPLAY=":0.0" SSH_ASKPASS="./askpass_script" ssh-add eclair-test-key </dev/null
# we want this command to keep running in the backgriund
# so we add & at then end
nohup ssh -L 48682:localhost:8080 ubuntu@[host...] -N &

and here is the output I'm getting from /var/log/eb-activity.log:

[2019-06-14T14:53:23.268Z] INFO  [15615] - [Application update suredbits-api-root-0.37.0-testnet-ssh-tunnel-fix-port-9@30/AppDeployStage1/AppDeployPostHook/01_eclair-ssh-tunnel.sh] : Starting activity...

The ssh tunnel is spawned, and I can find it by doing:

[ec2-user@ip-172-31-25-154 ~]$ ps aux | grep 48682
root     16047  0.0  0.0 175560  6704 ?        S    14:53   0:00 ssh -L 48682:localhost:8080 ubuntu@ec2-34-221-186-19.us-west-2.compute.amazonaws.com -N

If I kill that process, the deployment continues as expected, which indicates that the bug is in the tunnel script. I can't seem to find out where though.

1 Answers

You need to add -n option to ssh when run it in background to avoid reading from stdin.

Related