Auto-update: Fri Aug 2 13:50:48 PDT 2024

This commit is contained in:
sanj 2024-08-02 13:50:48 -07:00
parent 89c88c9d25
commit 72c7777947
2 changed files with 29 additions and 3 deletions

View file

@ -29,9 +29,13 @@ def load_env():
def check_server(ip, port, ts_id): def check_server(ip, port, ts_id):
address = f"http://{ip}:{port}/id"
logging.info(f"Checking {address} for response...")
try: try:
response = requests.get(f"http://{ip}:{port}/ts_id", timeout=5) response = requests.get(address, timeout=5)
return response.status_code == 200 and response.text.strip() == ts_id response_text = response.text.strip().strip('"')
logging.info(f"{address} responded '{response_text}'")
return response.status_code == 200 and response_text == ts_id
except requests.RequestException as e: except requests.RequestException as e:
logging.error(f"Error checking server {ts_id}: {str(e)}") logging.error(f"Error checking server {ts_id}: {str(e)}")
return False return False
@ -97,6 +101,8 @@ def start_remote_server(server):
finally: finally:
ssh.close() ssh.close()
def main(): def main():
load_env() load_env()
config = load_config() config = load_config()
@ -108,7 +114,7 @@ def main():
if check_server(server['ts_ip'], server['app_port'], server['ts_id']): if check_server(server['ts_ip'], server['app_port'], server['ts_id']):
logging.info(f"{server['ts_id']} is running and responding correctly.") logging.info(f"{server['ts_id']} is running and responding correctly.")
else: else:
logging.info(f"{server['ts_id']} is not responding. Attempting to start...") logging.info(f"{server['ts_id']} is not responding correctly. Attempting to start...")
if server['ts_id'] == local_ts_id: if server['ts_id'] == local_ts_id:
start_local_server(server) start_local_server(server)
else: else:
@ -117,5 +123,6 @@ def main():
logging.info("Waiting 5 seconds before next check...") logging.info("Waiting 5 seconds before next check...")
time.sleep(5) time.sleep(5)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

19
start.sh Normal file
View file

@ -0,0 +1,19 @@
#!/bin/bash
# Set the path to the script
SCRIPT_PATH="./sijapi/helpers/start.py"
# Check if the script exists
if [ ! -f "$SCRIPT_PATH" ]; then
echo "Error: Script not found at $SCRIPT_PATH"
exit 1
fi
# Set up the environment
source "./sijapi/config/.env"
# Run the Python script
python "$SCRIPT_PATH"
# Deactivate the conda environment
conda deactivate