From 49762a909cc5d3e9a7c82e9bb16e54e432d5dbad Mon Sep 17 00:00:00 2001 From: Nana Mensah Date: Tue, 19 May 2020 12:31:31 +0100 Subject: [PATCH 1/5] Add ngrok startup script --- ngrok_start.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 ngrok_start.sh diff --git a/ngrok_start.sh b/ngrok_start.sh new file mode 100644 index 0000000..af8c67b --- /dev/null +++ b/ngrok_start.sh @@ -0,0 +1,17 @@ +#!/bin/bash + + +# 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 ngrok tcp --region eu 22 &> /dev/null & + sleep 3 + NGROK_URL=$(curl http://localhost:4040/api/tunnels 2>/dev/null | jq ".tunnels[0].public_url") + echo $NGROK_URL +else + # If ngrok is already running, print the url for SSH access + NGROK_URL=$(curl http://localhost:4040/api/tunnels 2>/dev/null | jq ".tunnels[0].public_url") + echo $NGROK_URL +fi From ffd8a691118cdc298aeb822e408f341f223f3ffe Mon Sep 17 00:00:00 2001 From: Nana Mensah Date: Tue, 19 May 2020 12:39:21 +0100 Subject: [PATCH 2/5] Update comments on ngrok start script --- ngrok_start.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ngrok_start.sh b/ngrok_start.sh index af8c67b..6d8d2c9 100644 --- a/ngrok_start.sh +++ b/ngrok_start.sh @@ -1,17 +1,25 @@ #!/bin/bash - +# ngrok_start.sh - A script to start ngrok as a background process on the system. +# 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 + # 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 & + # Print the url for the ngrok server for SSH access. + # We pause for a few seconds to allow the connection to complete. sleep 3 NGROK_URL=$(curl http://localhost:4040/api/tunnels 2>/dev/null | jq ".tunnels[0].public_url") echo $NGROK_URL else - # If ngrok is already running, print the url for SSH access + # If ngrok is already running, print the url to the ngrok server for SSH access NGROK_URL=$(curl http://localhost:4040/api/tunnels 2>/dev/null | jq ".tunnels[0].public_url") echo $NGROK_URL fi From 97645117132941c8f4b16964ea7aafc76ef8195c Mon Sep 17 00:00:00 2001 From: Nana Mensah Date: Tue, 19 May 2020 12:40:01 +0100 Subject: [PATCH 3/5] Fix typo in ngrok definition --- ngrok_start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngrok_start.sh b/ngrok_start.sh index 6d8d2c9..43ff9eb 100644 --- a/ngrok_start.sh +++ b/ngrok_start.sh @@ -1,5 +1,5 @@ #!/bin/bash -# ngrok_start.sh - A script to start ngrok as a background process on the system. +# 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)` From 3dffec5badfb4e984137c1be0bb0afba6beb6e40 Mon Sep 17 00:00:00 2001 From: Nana Mensah Date: Tue, 19 May 2020 12:43:17 +0100 Subject: [PATCH 4/5] Udpate readme --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5329d94..6ac22ac 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Workstation Housekeeping v1.8 +# Workstation Housekeeping v1.9 Scripts to manage data on the NGS workstation @@ -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" +``` + +--- From 09c91dc0bbf20b316fa77256b78fd49b199606f3 Mon Sep 17 00:00:00 2001 From: Aledj2 Date: Tue, 19 May 2020 19:07:07 +0100 Subject: [PATCH 5/5] Update script to write ngrok url to syslog --- ngrok_start.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) mode change 100644 => 100755 ngrok_start.sh diff --git a/ngrok_start.sh b/ngrok_start.sh old mode 100644 new mode 100755 index 43ff9eb..8372572 --- a/ngrok_start.sh +++ b/ngrok_start.sh @@ -13,13 +13,14 @@ if [ -z $EXISTING_PROCESS ] ;then # &> /dev/null : Discard stdout and stderr to empty output stream # & : Run as a background process nohup ngrok tcp --region eu 22 &> /dev/null & - # Print the url for the ngrok server for SSH access. - # We pause for a few seconds to allow the connection to complete. + # 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") - echo $NGROK_URL + logger -s "ngrok_start - new workstation host - $NGROK_URL" else - # If ngrok is already running, print the url to the ngrok server for SSH access + # 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_URL + echo "ngrok_start - $NGROK_URL" 1>&2 fi