Skip to content

Commit 4493ffc

Browse files
authored
Merge pull request #4 from CoMfUcIoS/check-n-restart
Check if service started and if not retry
2 parents d6e038d + 361422e commit 4493ffc

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

action.yml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,34 @@ runs:
2020
shell: bash
2121
run: |
2222
echo '${{ inputs.service-key }}' | sudo twingate setup --headless=-
23-
sudo twingate start
24-
TWINGATE_STATUS=$(sudo twingate status)
25-
if [[ "$TWINGATE_STATUS" != 'online' ]]; then
26-
echo "Exiting with error as Twingate is not connected"
23+
MAX_RETRIES=5
24+
WAIT_TIME=5
25+
n=0
26+
27+
while [ $n -lt $MAX_RETRIES ]; do
28+
echo "Starting Twingate service..."
29+
sudo twingate start
30+
31+
echo "Waiting $WAIT_TIME seconds for Twingate service to start..."
32+
sleep $WAIT_TIME
33+
34+
status=$(sudo twingate status)
35+
36+
if [ "$status" = "online" ]; then
37+
echo "Twingate service is connected."
38+
break
39+
else
40+
sudo twingate stop
41+
fi
42+
43+
# Increment the retry counter and wait time
44+
n=$((n+1))
45+
WAIT_TIME=$((WAIT_TIME+5))
46+
47+
echo "Twingate service is not connected. Retrying ..."
48+
done
49+
50+
if [ $n -eq $MAX_RETRIES ]; then
51+
echo "Twingate service failed to connect."
2752
exit 1
28-
fi
53+
fi

0 commit comments

Comments
 (0)