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

Commit

Permalink
Merge pull request #27 from moka-guys/development
Browse files Browse the repository at this point in the history
Add ngrok startup script.
  • Loading branch information
Aled Jones authored May 20, 2020
2 parents bb8c7c9 + 09c91dc commit f0f31e3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
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

0 comments on commit f0f31e3

Please sign in to comment.