#!/bin/bash
#
# Assumes this (sap-p1-2) has been switched from failover to primary master;
# We now need to map 5673 to the production RabbitMQ in the cloud
# (rabbit-eu-west-3.sapsailing.com). Furthermore, the reverse port forward
# for the cloud replicas to reach the on-site master must be established
# to sap-p1-2:8888.
# TracTrac is assumed to be running on "A" currently.
#
killall autossh
# Tunnel to cloud MongoDB on port 10203; reverse tunnel to localhost:10202 for MongoDB
AUTOSSH_LOGLEVEL=7 AUTOSSH_POLL=5 autossh -M 21504 -f -A -N \
  -L 22443:sapsailing.com:443 \
  -L 22222:sapsailing.com:22 \
  -R 9444:localhost:9443 \
  -R '*:8888:localhost:8888' \
  -L 443:security-service.sapsailing.com:443 \
  -R 10202:localhost:10202 \
  -L 10203:localhost:10203 \
  -L 5673:rabbit-eu-west-3.sapsailing.com:5672 \
  -L 15673:localhost:15673 \
  -L 5675:rabbit.internal.sapsailing.com:5672 \
  -L 15675:rabbit.internal.sapsailing.com:15672 \
  -R 18222:localhost:22 \
  -L 588:email-smtp.eu-west-1.amazonaws.com:587 \
  ec2-user@paris-ssh.sapsailing.com
# The tunnel connection to sap-p1-1 is expected to be established from the sap-p1-1 side by a reverse port forward
sleep 2
# Tunnel to localhost for TracTrac port forwards
tractrac-A
