Skip to content

Commit

Permalink
Autoupdate with llm server
Browse files Browse the repository at this point in the history
  • Loading branch information
namoray committed Apr 9, 2024
1 parent 4c017ba commit deff62c
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 134 deletions.
File renamed without changes.
23 changes: 23 additions & 0 deletions llm_autoupdate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

cleanup() {
echo "Stopping the LLM_SERVER_PID server..."
kill $LLM_SERVER_PID
wait $LLM_SERVER_PID 2>/dev/null
echo "Stopped"
}


original_dir=$(pwd)

# Change Directory to 'llm_server' and run the entrypoint script in the background
cd llm_server
./entrypoint.sh &
LLM_SERVER_PID=$!
cd "$original_dir"

# Run the llm_autoupdate script
python run_autoupdater.py --restart_script autoupdate_llm.sh --process_pid $LLM_SERVER_PID


cleanup()
55 changes: 55 additions & 0 deletions run_autoupdater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import subprocess
import time


def should_update_local(local_tag, remote_tag):
if remote_tag[0] == local_tag[0]:
return remote_tag != local_tag
return False


def run_autoupdate(restart_script: str, process_pid: int):
branch_name = subprocess.getoutput("git rev-parse --abbrev-ref HEAD")

while True:
local_tag = subprocess.getoutput("git describe --abbrev=0 --tags")
os.system(f"git fetch origin {branch_name}")
remote_tag = subprocess.getoutput(
f"git describe --tags `git rev-list --tags=origin/{branch_name} --max-count=1`"
)

if should_update_local(local_tag, remote_tag):
print("Local repo is not up-to-date. Updating...")
reset_cmd = "git reset --hard " + remote_tag
process = subprocess.Popen(reset_cmd.split(), stdout=subprocess.PIPE)
output, error = process.communicate()

if error:
print("Error in updating:", error)
else:
print("Updated local repo to latest version: {}", format(remote_tag))

print("Running the autoupdate steps...")
# Trigger shell script. Make sure this file path starts from root
subprocess.run(["kill", f"{process_pid}"], shell=True)
subprocess.run(["wait", f"{process_pid}", "2>/dev/null"], shell=True)
subprocess.call([f"./{restart_script}"], shell=True)
print("Finished running the autoupdate steps! Ready to go 😎")

else:
print("Repo is up-to-date.")

time.sleep(60)


if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--restart_script", type=str)
parser.add_argument("--process_pid", type=int)
args = parser.parse_args()
run_autoupdate(
restart_script=args.restart_script, process_pid=args.process_pid
)
39 changes: 0 additions & 39 deletions run_miner_image_auto_update.py

This file was deleted.

39 changes: 0 additions & 39 deletions run_miner_llm_auto_update.py

This file was deleted.

56 changes: 0 additions & 56 deletions run_validator_auto_update.py

This file was deleted.

0 comments on commit deff62c

Please sign in to comment.