Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Add ngrok startup script. #27

Merged
merged 5 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Workstation Housekeeping v1.8
# Workstation Housekeeping v1.9

Scripts to manage data on the NGS workstation

Expand Down Expand Up @@ -66,3 +66,20 @@ wscleaner ROOT_DIRECTORY --logfile LOGFILE_PATH
```

---

## ngrok_start.sh

Allow SSH access to the system by running ngrok as a background process.

### Installation

See knowledge base article for ngrok installation.

### Usage

```bash
$ ngrok_start.sh
"tcp://30.tcp.eu.ngrok.io:5555"
```

---
26 changes: 26 additions & 0 deletions ngrok_start.sh
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