-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from reef-technologies/gunicorn-unix
Use unix domain socket for gunicorn
- Loading branch information
Showing
7 changed files
with
59 additions
and
12 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
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,33 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import socket | ||
import sys | ||
|
||
|
||
def healthcheck(socket_path: str, url: str): | ||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: | ||
s.settimeout(1) | ||
s.connect(socket_path) | ||
req = f"GET {url} HTTP/1.1\r\n\r\n" | ||
s.sendall(req.encode()) | ||
response = s.recv(64) | ||
assert response, "No response received" | ||
|
||
status_code = int(response.decode().split()[1]) | ||
assert status_code == 200, f"Unexpected status code: {status_code}" | ||
|
||
sys.stdout.write("OK\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("socket_path", type=str, help="Path to the socket file") | ||
parser.add_argument("--url", type=str, required=False, default="/admin/login/", help="URL to check") | ||
args = parser.parse_args() | ||
|
||
try: | ||
healthcheck(args.socket_path, args.url) | ||
except Exception as e: | ||
sys.stderr.write(f"Error: {e}\n") | ||
sys.exit(1) |
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