-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add post script functionality #45
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,21 @@ Examples: | |
|
||
Additional details are available from [`ssh_config(5)`](https://linux.die.net/man/5/ssh_config) | ||
|
||
#### SSH_POST_SCRIPT | ||
|
||
When set, SSH_POST_SCRIPT will be the location of a shell script to execute after starting autossh. | ||
This is useful to send some details to the server about the autossh client. | ||
For example, if a random port is used, then it's useful for the server to know who is on this port. | ||
SSH_TUNNEL_PORT can be used in the post script like so: | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add another space, and don't forget to call out the specific language in the markdown. (e.g. |
||
FILE=/tmp/autossh.${SSH_CLIENT_ID} | ||
echo "${SSH_TUNNEL_PORT}" > ${FILE} | ||
scp ${FILE} ${SSH_REMOTE_USER}@${SSH_REMOTE_HOST}:/tmp | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add one blank line below codeblock. |
||
In this example SSH_CLIENT_ID is set to some identifier that represents the client and the port is | ||
set in a file. This could be useful when you have multiple client connections and you need to know | ||
on the server which client to connect to. Mount the shell script in a docker volume. | ||
|
||
#### Additional Environment variables | ||
|
||
- [`autossh(1)`](https://linux.die.net/man/1/autossh) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,5 +62,22 @@ COMMAND="autossh "\ | |
|
||
echo "[INFO ] # ${COMMAND}" | ||
|
||
# Run command | ||
exec ${COMMAND} | ||
# Run autossh command in background and save pid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please write a test for this in a new container, you may call it the The test container should exit with |
||
exec ${COMMAND} & | ||
pid=$! | ||
sleep 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we sleeping here? If we're just sleeping here to give time for the tunnel to instantiate, we should find a better way to confirm that. Also, if that fails, we should |
||
|
||
# Export the Tunnel Port for post script to use | ||
export SSH_TUNNEL_PORT=${SSH_TUNNEL_PORT} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any other interesting variables we can/should expose? |
||
|
||
if [[ -e /proc/$pid ]] && [[ -n "${SSH_POST_SCRIPT}" ]]; then | ||
if [[ -f "${SSH_POST_SCRIPT}" ]]; then | ||
# Execute Post Script | ||
echo "[INFO ] Executing ${SSH_POST_SCRIPT}" | ||
/bin/sh "${SSH_POST_SCRIPT}" | ||
else | ||
echo "[WARN ] ${SSH_POST_SCRIPT} was not found" | ||
fi | ||
fi | ||
|
||
wait $pid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not make sense just reading it.
Do you mean to say you can associate a specific container/instance of autossh is using a specific port remotely? I'm a bit confused as to the usecase.