fix: make semantic changes to commands
* add missing __main__ call to commands.py * remove unnecessary imports * fix backup WITH_FILES logic * follow python semantics (?) Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import socket, os, json, time
|
||||
import socket
|
||||
import json
|
||||
import time
|
||||
from six.moves.urllib.parse import urlparse
|
||||
|
||||
COMMON_SITE_CONFIG_FILE = 'common_site_config.json'
|
||||
@@ -8,6 +10,7 @@ REDIS_SOCKETIO_KEY = 'redis_socketio'
|
||||
DB_HOST_KEY = 'db_host'
|
||||
DB_PORT = 3306
|
||||
|
||||
|
||||
def is_open(ip, port, timeout=30):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(timeout)
|
||||
@@ -15,16 +18,17 @@ def is_open(ip, port, timeout=30):
|
||||
s.connect((ip, int(port)))
|
||||
s.shutdown(socket.SHUT_RDWR)
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
finally:
|
||||
s.close()
|
||||
|
||||
|
||||
def check_host(ip, port, retry=10, delay=3, print_attempt=True):
|
||||
ipup = False
|
||||
for i in range(retry):
|
||||
if print_attempt:
|
||||
print("Attempt {i} to connect to {ip}:{port}".format(ip=ip,port=port,i=i+1))
|
||||
print("Attempt {i} to connect to {ip}:{port}".format(ip=ip, port=port, i=i+1))
|
||||
if is_open(ip, port):
|
||||
ipup = True
|
||||
break
|
||||
@@ -32,6 +36,7 @@ def check_host(ip, port, retry=10, delay=3, print_attempt=True):
|
||||
time.sleep(delay)
|
||||
return ipup
|
||||
|
||||
|
||||
# Check connection to servers
|
||||
def get_config():
|
||||
config = None
|
||||
@@ -41,11 +46,12 @@ def get_config():
|
||||
except FileNotFoundError as exception:
|
||||
print(exception)
|
||||
exit(1)
|
||||
except:
|
||||
except Exception:
|
||||
print(COMMON_SITE_CONFIG_FILE+" is not valid")
|
||||
exit(1)
|
||||
return config
|
||||
|
||||
|
||||
# Check mariadb
|
||||
def check_mariadb(retry=10, delay=3, print_attempt=True):
|
||||
config = get_config()
|
||||
@@ -60,11 +66,12 @@ def check_mariadb(retry=10, delay=3, print_attempt=True):
|
||||
print("Connection to MariaDB timed out")
|
||||
exit(1)
|
||||
|
||||
|
||||
# Check redis queue
|
||||
def check_redis_queue(retry=10, delay=3, print_attempt=True):
|
||||
check_redis_queue = False
|
||||
config = get_config()
|
||||
redis_queue_url = urlparse(config.get(REDIS_QUEUE_KEY,"redis://redis-queue:6379")).netloc
|
||||
redis_queue_url = urlparse(config.get(REDIS_QUEUE_KEY, "redis://redis-queue:6379")).netloc
|
||||
redis_queue, redis_queue_port = redis_queue_url.split(":")
|
||||
check_redis_queue = check_host(
|
||||
redis_queue,
|
||||
@@ -76,11 +83,12 @@ def check_redis_queue(retry=10, delay=3, print_attempt=True):
|
||||
print("Connection to redis queue timed out")
|
||||
exit(1)
|
||||
|
||||
|
||||
# Check redis cache
|
||||
def check_redis_cache(retry=10, delay=3, print_attempt=True):
|
||||
check_redis_cache = False
|
||||
config = get_config()
|
||||
redis_cache_url = urlparse(config.get(REDIS_CACHE_KEY,"redis://redis-cache:6379")).netloc
|
||||
redis_cache_url = urlparse(config.get(REDIS_CACHE_KEY, "redis://redis-cache:6379")).netloc
|
||||
redis_cache, redis_cache_port = redis_cache_url.split(":")
|
||||
check_redis_cache = check_host(
|
||||
redis_cache,
|
||||
@@ -92,11 +100,12 @@ def check_redis_cache(retry=10, delay=3, print_attempt=True):
|
||||
print("Connection to redis cache timed out")
|
||||
exit(1)
|
||||
|
||||
|
||||
# Check redis socketio
|
||||
def check_redis_socketio(retry=10, delay=3, print_attempt=True):
|
||||
check_redis_socketio = False
|
||||
config = get_config()
|
||||
redis_socketio_url = urlparse(config.get(REDIS_SOCKETIO_KEY,"redis://redis-socketio:6379")).netloc
|
||||
redis_socketio_url = urlparse(config.get(REDIS_SOCKETIO_KEY, "redis://redis-socketio:6379")).netloc
|
||||
redis_socketio, redis_socketio_port = redis_socketio_url.split(":")
|
||||
check_redis_socketio = check_host(
|
||||
redis_socketio,
|
||||
@@ -108,6 +117,7 @@ def check_redis_socketio(retry=10, delay=3, print_attempt=True):
|
||||
print("Connection to redis socketio timed out")
|
||||
exit(1)
|
||||
|
||||
|
||||
# Get site_config.json
|
||||
def get_site_config(site_name):
|
||||
site_config = None
|
||||
@@ -115,6 +125,7 @@ def get_site_config(site_name):
|
||||
site_config = json.load(site_config_file)
|
||||
return site_config
|
||||
|
||||
|
||||
def main():
|
||||
check_mariadb()
|
||||
check_redis_queue()
|
||||
@@ -122,5 +133,6 @@ def main():
|
||||
check_redis_socketio()
|
||||
print('Connections OK')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user