1

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 [2345]
stop on runlevel [016]
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 protected]
post-start exec ssh [email protected] '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.

1 Answer 1

0

I don't think so. It sounds like most of this could (or should) be broken out into its own script so your upstart looks like:

description "Upstart Script to run sonarr as a service on Ubuntu/Debian based systems"
start on runlevel [2345]
stop on runlevel [016]

exec /usr/local/sbin/sonarr

And /usr/local/sbin/sonarr being:

#!/bin/sh
PORT=$(curl http://ipvr.japayton.com/port.php)
API=$(cat /home/kodi/IPVR/api)

# Do this first because it's non-blocking
# And take care with quotes.
ssh [email protected] 'sqlite3 /home/client/clients.db "UPDATE clients SET port = '"'$PORT'"' WHERE api = '"'$API'"';"'

autossh -nNT -i /home/root/.ssh/sshkeys -o ServerAliveInterval=15 -R $PORT:localhost:443 [email protected]

Note that there were a few syntax issues with the script so make sure you get that running before you start blaming Upstart for not launching it.

1
  • I would keep the ssh as it is because ordering is important. Also, he should exec the autossh in the script there. Jan 14, 2015 at 1:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .