paas-cf-conduit
paas-cf-conduit copied to clipboard
Feature request: Kill the app if no CF tunnel is present
In some circumstances the conduit
proxy app might remain running forever.
For instance, if the cf conduit
fails, or if the cf token expires or the user targets a different API endpoint or org or space.
If the application is running forever, it might happen that the user is billied for ever.
Proposed solution
One solution can run some kind of watchdog command in the app, that would fail if no SSH tunnel is created or if it stops. For example, dropping a safe-terminate.sh
#!/bin/bash
ssh_running() {
netstat -t | grep -q ":2222"
}
start_timeout=$(date -d "+1 min" +%s)
max_timeout=$(date -d "+7 days" +%s)
while ! ssh_running && [ "$(date +%s)" -lt "${start_timeout}" ] ; do
echo "Waiting for SSH session..."
sleep 5
done
while ssh_running && [ "$(date +%s)" -lt "${max_timeout}" ] ; do
echo "SSH session still running..."
sleep 600
done
echo "No more SSH sessions or timeout detected. Exitting in 10 seconds."
sleep 10
then, cf conduit
would push the static app as follows:
cf push -b staticfile_buildpack -m 64m -k 64m -i 1 --health-check-type none --no-route --no-manifest __conduit_12345__ -c 'bash $HOME/public/safe-terminate.sh'
The app would wait for a SSH to be present in 1 minute, and then wait until it is gone. Then it will terminate after 10 seconds. In normal operation, the flow would be as usual, the application would be deleted once conduit finished.
If instead the cf conduit
fails to delete the app, the SSH tunnel would eventually die. The script would detect that and terminate. CF would restart the application several times, but the script would fail after one minute because no SSH connection is done.