I am trying to make reverse ssh tunnels to my clients using upstart. I have many clients and they obviously come on and off line at times. This is what I have now, but it won't work because the env stanza does not support running the command.
description "Upstart Script to run sonarr as a service on Ubuntu/Debian based systems" start on runlevel  stop on runlevel  env PORT=$(curl http://ipvr.japayton.com/port.php) env API=(sudo cat /home/kodi/IPVR/api) respawn exec autossh -nNT -i /home/root/.ssh/sshkeys -o ServerAliveInterval=15 -R $PORT:localhost:443 email@example.com post-start exec ssh firstname.lastname@example.org 'sqlite3 /home/client/clients.db "UPDATE clients SET port = '$PORT' WHERE api = $API;"'
The API and post-start are not that important. I can put this into an external script since I think I am going to build an API for these updates rather than using ssh. The port.php returns an available port for the reverse tunnel.
I need that port at the time of the execution of autossh. I know I could make a script stanza and set it like a regular variable but the upstart would monitor the PID of curl instead of autossh. I don't know if using an external bash script would work. I want to avoid writing anything to the file system.