-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🥅 Catch HAProxy errors, Better HAProxy config
Signed-off-by: Muhammed Hussein Karimi <[email protected]>
- Loading branch information
1 parent
e611e74
commit 55d920c
Showing
5 changed files
with
111 additions
and
80 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 |
---|---|---|
|
@@ -7,3 +7,5 @@ frontend redis_master | |
default_backend redis_master | ||
|
||
backend redis_master | ||
balance source | ||
hash-type consistent |
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,32 @@ | ||
from datetime import datetime | ||
import typer | ||
|
||
|
||
def log_prefix() -> str: | ||
return f"{datetime.now().strftime("%c")} " | ||
|
||
|
||
def info(msg): | ||
typer.echo( | ||
log_prefix() + typer.style( | ||
msg, | ||
fg=typer.colors.GREEN, | ||
bold=True | ||
), | ||
err=False | ||
) | ||
|
||
|
||
def error(msg: str): | ||
typer.echo( | ||
log_prefix() + typer.style( | ||
msg, | ||
fg=typer.colors.WHITE, | ||
bg=typer.colors.RED, | ||
bold=True | ||
), | ||
err=True | ||
) | ||
|
||
|
||
__all__ = ["info", "error"] |
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,36 @@ | ||
import socket | ||
|
||
__all__ = ["send_command"] | ||
|
||
|
||
def encode_command(command: str) -> bytes: | ||
return f"{command};\n".encode("utf-8") | ||
|
||
|
||
def recvall(sock: socket.socket): | ||
BUFF_SIZE = 1024 | ||
data = b'' | ||
while True: | ||
part = sock.recv(BUFF_SIZE) | ||
data += part | ||
if len(part) < BUFF_SIZE: | ||
# either 0 or end of data | ||
break | ||
return data | ||
|
||
|
||
def send_command(addr: str, command: str) -> str: | ||
if len(addr.split(":")) == 2: | ||
addr_parts = addr.split(":") | ||
a = (addr_parts[0], int(addr_parts[1])) | ||
family = socket.AF_INET | ||
else: | ||
a = addr | ||
family = socket.AF_UNIX | ||
unix_socket = socket.socket(family, socket.SOCK_STREAM) | ||
unix_socket.settimeout(10) | ||
unix_socket.connect(a) | ||
|
||
unix_socket.send(encode_command(command)) | ||
|
||
return recvall(unix_socket).decode("utf-8").strip() |