-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle dynamic IP address for Vast.ai
- Loading branch information
1 parent
29d5c99
commit edee568
Showing
10 changed files
with
109 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
external-ip-address.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
current_time=$(date +%s) | ||
cache_file="/tmp/external_ip_address" | ||
cache_max_age=${EXTERNAL_IP_CACHE_SECS:-900} | ||
|
||
if [[ -f $cache_file ]]; then | ||
file_mod_time=$(stat -c %Y "$cache_file") | ||
if [[ $((current_time - file_mod_time)) -lt $cache_max_age ]]; then | ||
ip=$(cat "$cache_file") | ||
if [[ $ip =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then | ||
echo "$ip" | ||
exit 0 | ||
fi | ||
fi | ||
fi | ||
|
||
# Fetch new IP address | ||
ip="$(dig whoami.cloudflare ch txt @1.1.1.1 +short | tr -d '"')" | ||
[[ $ip =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]] || ip="$(dig myip.opendns.com @resolver1.opendns.com +short)" | ||
[[ $ip =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]] || ip=$(curl -s ifconfig.me) | ||
|
||
# Cache the IP address | ||
echo "$ip" | tee "$cache_file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Loading...</title> | ||
<style> | ||
body { | ||
background-color: white; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
margin: 0; | ||
font-family: Arial, sans-serif; | ||
} | ||
.spinner { | ||
border: 8px solid #F2F2F2; /* Light grey */ | ||
border-top: 8px solid grey; /* Dark grey */ | ||
border-radius: 50%; | ||
width: 50px; | ||
height: 50px; | ||
animation: spin 1s linear infinite; | ||
} | ||
@keyframes spin { | ||
0% { transform: rotate(0deg); } | ||
100% { transform: rotate(360deg); } | ||
} | ||
.text { | ||
margin-top: 20px; | ||
color: #333; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="spinner"></div> | ||
<div class="text">Waiting for the service to respond</div> | ||
|
||
<script> | ||
// Function to check if the current page is up | ||
function checkService() { | ||
fetch(window.location.href, { method: 'HEAD' }) | ||
.then(response => { | ||
// If the response status is not a 5xx error | ||
if (response.status < 500 || response.status >= 600) { | ||
// Reload the page | ||
window.location.reload(); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Error checking service:', error); | ||
}); | ||
} | ||
|
||
// Check the current page every 5 seconds | ||
setInterval(checkService, 5000); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters