This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from moka-guys/development
Add ngrok startup script.
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
# ngrok_start.sh - A script to allow SSH access to the system by running ngrok as a background process | ||
# Prints SSH details if ngrok is already running. | ||
# Note: The ngrok process can be closed at anytime with `kill $(pidof ngrok)` | ||
|
||
# Get the process ID of ngrok if it is already running on the system | ||
EXISTING_PROCESS=$(pidof ngrok) | ||
|
||
if [ -z $EXISTING_PROCESS ] ;then | ||
# If ngrok is not running, start as a background process and print the url for SSH access | ||
# nohup [command] : Keep the process running the command even after you quit the session | ||
# ngrok tcp --region eu 22 : Open an connection to ngrok server on port 22 | ||
# &> /dev/null : Discard stdout and stderr to empty output stream | ||
# & : Run as a background process | ||
nohup ngrok tcp --region eu 22 &> /dev/null & | ||
# Pause for a few seconds to allow the connection to complete. | ||
sleep 3 | ||
# Write the ngrok public url for SSH access to the syslog. | ||
# Triggers alert in slack with ssh url details and writes to stderr. | ||
NGROK_URL=$(curl http://localhost:4040/api/tunnels 2>/dev/null | jq ".tunnels[0].public_url") | ||
logger -s "ngrok_start - new workstation host - $NGROK_URL" | ||
else | ||
# If ngrok is already running, print the public url for SSH access to stderr | ||
NGROK_URL=$(curl http://localhost:4040/api/tunnels 2>/dev/null | jq ".tunnels[0].public_url") | ||
echo "ngrok_start - $NGROK_URL" 1>&2 | ||
fi |