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):
address = f"http://{ip}:{port}/id"
logging.info(f"Checking {address} for response...")
try:
response = requests.get(f"http://{ip}:{port}/ts_id", timeout=5)
return response.status_code == 200 and response.text.strip() == ts_id
response = requests.get(address, timeout=5)
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:
logging.error(f"Error checking server {ts_id}: {str(e)}")
return False
@ -97,6 +101,8 @@ def start_remote_server(server):
finally:
ssh.close()
def main():
load_env()
config = load_config()
@ -108,7 +114,7 @@ def main():
if check_server(server['ts_ip'], server['app_port'], server['ts_id']):
logging.info(f"{server['ts_id']} is running and responding correctly.")
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:
start_local_server(server)
else:
@ -117,5 +123,6 @@ def main():
logging.info("Waiting 5 seconds before next check...")
time.sleep(5)
if __name__ == "__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