improve start/update/uninstall
This commit is contained in:
parent
33c7a0b674
commit
303f73433f
@ -41,6 +41,9 @@ class Stack:
|
|||||||
|
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
|
if self.is_installed():
|
||||||
|
self.update()
|
||||||
|
else:
|
||||||
self.check_for_broken_install()
|
self.check_for_broken_install()
|
||||||
self.create_venv()
|
self.create_venv()
|
||||||
self._install()
|
self._install()
|
||||||
@ -66,17 +69,33 @@ class Stack:
|
|||||||
|
|
||||||
def update(self, folder: str = 'webui'):
|
def update(self, folder: str = 'webui'):
|
||||||
if self.is_installed():
|
if self.is_installed():
|
||||||
|
status = self.status()
|
||||||
|
if status:
|
||||||
|
self.stop()
|
||||||
|
|
||||||
logger.info(f"Updating {self.name}")
|
logger.info(f"Updating {self.name}")
|
||||||
self.git_pull(folder)
|
self.git_pull(folder)
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
if status:
|
||||||
|
self.start()
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Could not update {self.name} as {self.name} is not installed")
|
logger.warning(f"Could not update {self.name} as {self.name} is not installed")
|
||||||
choices.any_key.ask()
|
choices.any_key.ask()
|
||||||
|
|
||||||
|
def _update(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def uninstall(self):
|
def uninstall(self):
|
||||||
logger.info(f"Uninstalling {self.name}")
|
logger.info(f"Uninstalling {self.name}")
|
||||||
|
if self.status():
|
||||||
|
self.stop()
|
||||||
self.bash(f"rm -rf {self.path}")
|
self.bash(f"rm -rf {self.path}")
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
if self.status():
|
||||||
|
logger.warning(f"{self.name} is already running")
|
||||||
|
|
||||||
if self.is_installed():
|
if self.is_installed():
|
||||||
self._start()
|
self._start()
|
||||||
else:
|
else:
|
||||||
@ -90,6 +109,8 @@ class Stack:
|
|||||||
if self.status():
|
if self.status():
|
||||||
logger.debug(f"Killing {self.name} with PID: {self.pid}")
|
logger.debug(f"Killing {self.name} with PID: {self.pid}")
|
||||||
psutil.Process(self.pid).kill()
|
psutil.Process(self.pid).kill()
|
||||||
|
else:
|
||||||
|
logger.warning(f"{self.name} is not running")
|
||||||
|
|
||||||
self.set_pid(None)
|
self.set_pid(None)
|
||||||
|
|
||||||
@ -158,7 +179,6 @@ class Stack:
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# TODO: attach to subprocess / redirect logs?
|
# TODO: attach to subprocess / redirect logs?
|
||||||
logger.info("Continuing without restarting...")
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Running command as daemon: {cmd}")
|
logger.debug(f"Running command as daemon: {cmd}")
|
||||||
|
2
main.py
2
main.py
@ -27,7 +27,7 @@ def load_services():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setup_logger(logging.DEBUG)
|
setup_logger(logging.INFO)
|
||||||
logger.info("Starting AI Suite for ROCM")
|
logger.info("Starting AI Suite for ROCM")
|
||||||
|
|
||||||
setup_config()
|
setup_config()
|
||||||
|
@ -19,22 +19,25 @@ def handle_services(action, service):
|
|||||||
|
|
||||||
service = loaded_services[service]
|
service = loaded_services[service]
|
||||||
if action == "start":
|
if action == "start":
|
||||||
logger.info(f"Starting service: {service.name}")
|
|
||||||
service.start()
|
service.start()
|
||||||
elif action == "stop":
|
elif action == "stop":
|
||||||
logger.info(f"Stopping service: {service.name}")
|
|
||||||
service.stop()
|
service.stop()
|
||||||
elif action == "install":
|
elif action == "install":
|
||||||
confirmation = choices.are_you_sure.ask()
|
confirmation = choices.are_you_sure.ask()
|
||||||
if confirmation:
|
if confirmation:
|
||||||
logger.info(f"Installing/updating service: {service.name}")
|
|
||||||
service.install()
|
service.install()
|
||||||
elif action == "uninstall":
|
elif action == "uninstall":
|
||||||
confirmation = choices.are_you_sure.ask()
|
confirmation = choices.are_you_sure.ask()
|
||||||
if confirmation:
|
if confirmation:
|
||||||
type_confirmation = questionary.text(f"Please type {service.id} to confirm uninstallation:")
|
type_confirmation = questionary.text(f"Please type {service.id} to confirm uninstallation (or type cancel):")
|
||||||
if type_confirmation.ask() == service.id:
|
|
||||||
logger.info(f"Uninstalling service: {service.name}")
|
value = type_confirmation.ask()
|
||||||
|
|
||||||
|
if value == "cancel":
|
||||||
|
questionary.print("Canceled", style="fg:ansired")
|
||||||
|
elif value != service.id:
|
||||||
|
questionary.print("Invalid input, please try again", style="fg:ansired")
|
||||||
|
elif value == service.id:
|
||||||
service.uninstall()
|
service.uninstall()
|
||||||
|
|
||||||
choices.any_key.ask()
|
choices.any_key.ask()
|
||||||
|
Loading…
Reference in New Issue
Block a user