Trigger tunnel
Overview
Triggers are commands executed on a specific event. tuna supports two types of events:
- HTTP request (Webhook)
- Email (SMTP)
Creating a Trigger tunnel is only available with a subscription.
Example
You can see all current flags, hints and examples by calling the help:
tuna trigger --help
tuna trigger webhook --help
tuna trigger smtp --help
Almost all flags have corresponding environment variables.
Script to run
For example, create a script /tmp/trigger.sh that will create a file and write the phrase Hello tuna to it:
#!/bin/sh
set -xe
touch /tmp/test_file.txt
echo "Hello tuna" > /tmp/test_file.txt
Then make it executable with the command chmod +x /tmp/trigger.sh.
HTTP request (Webhook)
tuna trigger webhook /tmp/trigger.sh
tuna will generate a link:
INFO[13:00:00] Welcome to Tuna
INFO[13:00:00] Forwarding tcp://ru.tuna.am:16502 -> 127.0.0.1:35839
INFO[13:00:00] Send an HTTP request to http://ru.tuna.am:16502 to execute the command "/tmp/trigger.sh"
Now you can send a request to the specified address, and tuna will execute the specified script, for example:
curl -sSLf http://ru.tuna.am:16502
Email (SMTP)
tuna trigger smtp /tmp/trigger.sh
tuna will generate a link:
INFO[13:00:00] Welcome to Tuna
INFO[13:00:00] Forwarding tcp://ru.tuna.am:19284 -> 127.0.0.1:1025
INFO[13:00:00] Send a message to SMTP server ru.tuna.am:19284 to execute the command "/tmp/trigger.sh"
Now you can send an email to the specified address, and tuna will execute the specified script, for example:
curl -s \
--url "smtp://ru.tuna.am:19284" \
--mail-from "tuna@example.com" \
--mail-rcpt "tuna@example.com" \
--upload-file /tmp/trigger.sh
Specifying a token
You can specify a particular token using the --token flag or the TUNA_TOKEN environment variable. Overriding follows the configuration ordering policy.
tuna trigger webhook --token=tt_***
tuna trigger smtp --token=tt_***
Specifying a connection region
You can specify a particular region using the --location/-l flag or the TUNA_LOCATION environment variable. Overriding follows the configuration ordering policy.
tuna trigger webhook --location=nl
tuna trigger smtp --location=nl
Static port
The value of the --port/-p flag can be an alias or an assigned port.
You can reserve ports in the dashboard, and after restarting the tunnel the address will remain the same.
For more details about ports, see the dedicated guide.
tuna trigger webhook --port=postgres
tuna trigger webhook --port=35000
tuna trigger smtp --port=postgres
tuna trigger smtp --port=35000