askrobots / dbbasic-examples
Public
Example DBBasic apps (an API, a blog and a microblog) and a template for new DBBasic modules.
danq9
Add official module template for creating DBBasic packages
17cf88a
1 year, 1 month ago
History
healthcheck.py · 854 bytes · 29 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | Lightweight health check script for Coolify |
| 4 | Uses only Python standard library - no additional packages needed |
| 5 | """ |
| 6 | import sys |
| 7 | import urllib.request |
| 8 | import urllib.error |
| 9 | import os |
| 10 | |
| 11 | def check_health(): |
| 12 | # Get port from environment or use default |
| 13 | port = os.environ.get('PORT', '3000') |
| 14 | url = f'http://localhost:{port}/' |
| 15 | |
| 16 | try: |
| 17 | # Check the homepage |
| 18 | response = urllib.request.urlopen(url, timeout=10) |
| 19 | if response.getcode() == 200: |
| 20 | print(f"Health check passed: {url} returned 200 OK") |
| 21 | sys.exit(0) # Healthy |
| 22 | print(f"Health check failed: {url} returned {response.getcode()}") |
| 23 | sys.exit(1) # Unhealthy |
| 24 | except Exception as e: |
| 25 | print(f"Health check failed: {url} - {e}") |
| 26 | sys.exit(1) # Unhealthy |
| 27 | |
| 28 | if __name__ == '__main__': |
| 29 | check_health() |