Skip to content

Commit

Permalink
fix: gracefully shutdown auto_update
Browse files Browse the repository at this point in the history
  • Loading branch information
codebender37 committed Oct 18, 2024
1 parent 0d20bd4 commit 40240cd
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions auto_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def stash_changes():

def pull_latest_changes():
logger.info("Pulling latest changes from the main branch.")
subprocess.run(["git", "pull", "origin", "main"], check=True)
# subprocess.run(["git", "pull", "origin", "main"], check=True)
subprocess.run(["git", "fetch", "--tags"], check=True)


Expand Down Expand Up @@ -224,7 +224,7 @@ def get_current_version():


def update_repo():
logger.info("Updating the script and its submodules.")
logger.info("Updating the repository..")
stash_changes()
pull_latest_changes()
pop_stash()
Expand All @@ -245,21 +245,27 @@ def main(service_name):
pull_docker_images(config["images"])
restart_docker(service_name)

# Start the periodic check loop
while True:
logger.info("Checking for updates...")
has_image_updates = check_for_image_updates(config["images"])

if current_dojo_version != new_dojo_version:
logger.info("Repository has changed. Updating...")
update_repo()
current_dojo_version = new_dojo_version

if current_dojo_version != new_dojo_version or has_image_updates:
restart_docker(service_name)

logger.info(f"Sleeping for {CHECK_INTERVAL} seconds.")
time.sleep(CHECK_INTERVAL)
try:
# Start the periodic check loop
while True:
logger.info("Checking for updates...")
has_image_updates = check_for_image_updates(config["images"])

if current_dojo_version != new_dojo_version:
logger.info("Repository has changed. Updating...")
update_repo()
current_dojo_version = new_dojo_version

if current_dojo_version != new_dojo_version or has_image_updates:
restart_docker(service_name)

logger.info(f"Sleeping for {CHECK_INTERVAL} seconds.")
time.sleep(CHECK_INTERVAL)
except KeyboardInterrupt:
logger.info("Graceful shutdown initiated.")
# Perform any cleanup here if necessary
subprocess.run(config["docker_compose_down"].split(), check=True)
logger.info("Shutdown complete.")


if __name__ == "__main__":
Expand Down

0 comments on commit 40240cd

Please sign in to comment.