fixed errors

This commit is contained in:
Mathieu Broillet 2024-10-11 20:23:26 +02:00
parent 11e364b9d8
commit d2afc0fdd2
Signed by: mathieu
GPG Key ID: A08E484FE95074C1
2 changed files with 10 additions and 7 deletions

View File

@ -36,7 +36,7 @@ class Screen:
os.system(f'screen -S {self.pid} -X stuff {command}{end}') os.system(f'screen -S {self.pid} -X stuff {command}{end}')
def create(name, shell=os.environ['SHELL'], logfile=None, title=None) -> Screen: def create(name, shell=os.environ['SHELL'], logfile=None, title=None, kill_on_exit=False) -> Screen:
command = ["screen", "-DmS", name, '-s', shell] command = ["screen", "-DmS", name, '-s', shell]
if logfile: if logfile:
command.append('-Logfile') command.append('-Logfile')
@ -46,7 +46,7 @@ def create(name, shell=os.environ['SHELL'], logfile=None, title=None) -> Screen:
command.append(title) command.append(title)
process = subprocess.Popen(command) process = subprocess.Popen(command)
while not process.pid: pass while not process.pid: pass
return Screen(process.pid) return Screen(process.pid, kill_on_exit)
def kill(pid): def kill(pid):

View File

@ -96,7 +96,7 @@ class Stack:
logger.info(f"Updating {self.name}") logger.info(f"Updating {self.name}")
symlinks = utils.find_symlink_in_folder(self.path) symlinks = utils.find_symlink_in_folder(self.path)
self.git_pull(folder) self.git_pull(self.path / folder)
self._update() self._update()
utils.create_symlinks(symlinks) utils.create_symlinks(symlinks)
@ -142,7 +142,10 @@ class Stack:
proc.wait(timeout=5) proc.wait(timeout=5)
except (psutil.NoSuchProcess, psutil.TimeoutExpired): except (psutil.NoSuchProcess, psutil.TimeoutExpired):
logger.warning(f"{self.name} did not terminate gracefully, forcing kill") logger.warning(f"{self.name} did not terminate gracefully, forcing kill")
try:
psutil.Process(self.pid).kill() psutil.Process(self.pid).kill()
except psutil.NoSuchProcess:
pass
self.remove_pid_file() self.remove_pid_file()
else: else:
logger.warning(f"{self.name} is not running") logger.warning(f"{self.name} is not running")
@ -229,7 +232,7 @@ class Stack:
# process = subprocess.Popen(full_cmd, shell=True, preexec_fn=os.setpgrp, # process = subprocess.Popen(full_cmd, shell=True, preexec_fn=os.setpgrp,
# stdout=config.open_file(f"{self.id}-stdout"), # stdout=config.open_file(f"{self.id}-stdout"),
# stderr=config.open_file(f"{self.id}-stderr")) # stderr=config.open_file(f"{self.id}-stderr"))
self.screen_session = screen.create(name=self.id) self.screen_session = screen.create(name=self.id, kill_on_exit=True)
self.screen_session.send(f"'{full_cmd} && screen -wipe'") self.screen_session.send(f"'{full_cmd} && screen -wipe'")
self.write_pid(self.screen_session.pid) self.write_pid(self.screen_session.pid)
return return
@ -250,9 +253,9 @@ class Stack:
logger.info(f"Cloning {url}") logger.info(f"Cloning {url}")
self.bash(f"git clone {f'-b {branch}' if branch else ''} {url} {dest or ''}") self.bash(f"git clone {f'-b {branch}' if branch else ''} {url} {dest or ''}")
def git_pull(self, repo_folder: str, force: bool = False) -> None: def git_pull(self, repo_folder: Path, force: bool = False) -> None:
"""Pull changes from a git repository.""" """Pull changes from a git repository."""
self.bash(f"git reset --hard HEAD {'&& git clean -f -d' if force else ''} && git pull", Path(repo_folder)) self.bash(f"git reset --hard HEAD {'&& git clean -f -d' if force else ''} && git pull", repo_folder)
def install_from_prebuilt(self, name): def install_from_prebuilt(self, name):
for prebuilt in utils.get_prebuilts(): for prebuilt in utils.get_prebuilts():