Skip to content

Commit

Permalink
Tidy startup scripts and service portal list ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Jan 23, 2024
1 parent d4785c3 commit 8db83d3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
5 changes: 2 additions & 3 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-caddy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
trap cleanup EXIT

function cleanup() {
kill $(jobs -p) >/dev/null 2>&1
rm -f /opt/caddy/etc/Caddyfile >/dev/null 2>&1
}

function start() {
cleanup
source /opt/ai-dock/etc/environment.sh

if [[ ${SERVERLESS,,} = "true" ]]; then
printf "Refusing to start Caddy service in serverless mode\n"
sleep 5
exit 0
exec sleep 5
fi

# Give processes time to register their ports
Expand Down
10 changes: 7 additions & 3 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-cloudflared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

trap cleanup EXIT

METRICS_PORT=2999

function cleanup() {
kill $(jobs -p) > /dev/null 2>&1
kill $(lsof -t -i:${METRICS_PORT}) > /dev/null 2>&1 &
wait -n
}

function start() {
cleanup
source /opt/ai-dock/etc/environment.sh

if [[ -z $CF_TUNNEL_TOKEN ]]; then
printf "Skipping Cloudflare daemon: No token\n"
# No error - Supervisor will not atempt restart
exec sleep 10
exec sleep 5
fi

printf "Starting Cloudflare daemon...\n"
cloudflared tunnel --metrics localhost:2999 run --token "${CF_TUNNEL_TOKEN}"
cloudflared tunnel --metrics localhost:"${METRICS_PORT}" run --token "${CF_TUNNEL_TOKEN}"
}

start 2>&1
8 changes: 6 additions & 2 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-quicktunnel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function start() {

if [[ -z $PROC_NUM ]]; then
# Something has gone awry, but no retry
exit 0
exec sleep 6
fi

# Give processes time to register their ports
Expand All @@ -28,7 +28,11 @@ function start() {
tunnel="--url localhost:${proxy_port}"
metrics="--metrics localhost:${metrics_port}"
fi


# Ensure the port is available (kill stale for restart)
kill $(lsof -t -i:${metrics_port}) > /dev/null 2>&1 &
wait -n

cloudflared tunnel ${metrics} ${tunnel}
}

Expand Down
8 changes: 4 additions & 4 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-serviceportal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ PROXY_SECURE=true
SERVICE_NAME="Service Portal"

function cleanup() {
kill $(jobs -p) > /dev/null 2>&1
rm /run/http_ports/$PROXY_PORT > /dev/null 2>&1
kill $(lsof -t -i:$LISTEN_PORT) > /dev/null 2>&1 &
wait -n
}

function start() {
cleanup
source /opt/ai-dock/etc/environment.sh

if [[ ${SERVERLESS,,} = "true" ]]; then
printf "Refusing to start $SERVICE_NAME in serverless mode\n"
exec sleep 10
exec sleep 6
fi

file_content="$(
Expand All @@ -35,8 +37,6 @@ function start() {
printf "%s\n" "$file_content" > /run/http_ports/$PROXY_PORT

printf "Starting ${SERVICE_NAME}...\n"
kill $(lsof -t -i:$LISTEN_PORT) > /dev/null 2>&1 &
wait -n
/usr/bin/python3 /opt/ai-dock/fastapi/serviceportal/main.py \
-p $LISTEN_PORT
}
Expand Down
8 changes: 5 additions & 3 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-sshd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
trap cleanup EXIT

function cleanup() {
kill $(jobs -p) > /dev/null 2>&1
kill $(lsof -t -i:${SSH_PORT}) > /dev/null 2>&1 &
wait -n
}

function start() {
source /opt/ai-dock/etc/environment.sh

if [[ ${SERVERLESS,,} = "true" ]]; then
printf "Refusing to start SSH service in serverless mode\n"
exec sleep 10
exec sleep 6
fi

# Support previous config
Expand All @@ -23,7 +24,7 @@ function start() {
if [[ ! $(ssh-keygen -l -f $ak_file) ]]; then
printf "Skipping SSH server: No public key\n" 1>&2
# No error - Supervisor will not atempt restart
exec sleep 10
exec sleep 6
fi

# Dynamically check users - we might have a mounted /etc/passwd
Expand All @@ -32,6 +33,7 @@ function start() {
useradd -r -g sshd -s /usr/sbin/nologin sshd
fi

cleanup
printf "Starting SSH server on port ${SSH_PORT}...\n"
/usr/bin/ssh-keygen -A
/usr/sbin/sshd -D -p $SSH_PORT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def get_service_files():
file = os.path.join(dir, filename)
if os.path.isfile(file):
files.append(file)
files.sort()
return files

def get_services():
Expand Down

0 comments on commit 8db83d3

Please sign in to comment.