fix screen alive status
This commit is contained in:
parent
5afec336cc
commit
11e364b9d8
@ -53,7 +53,7 @@ def kill(pid):
|
|||||||
os.kill(pid, signal.SIGTERM)
|
os.kill(pid, signal.SIGTERM)
|
||||||
|
|
||||||
|
|
||||||
def exists(pid: int) -> int:
|
def exists(pid: int) -> bool:
|
||||||
command = f"screen -S {str(pid)} -Q select .".split()
|
command = f"screen -S {str(pid)} -Q select .".split()
|
||||||
pop = subprocess.Popen(command, stdout=subprocess.DEVNULL)
|
pop = subprocess.Popen(command, stdout=subprocess.DEVNULL)
|
||||||
pop.wait()
|
pop.wait()
|
||||||
|
@ -7,6 +7,7 @@ from typing import Union, List, Optional
|
|||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
from core import utils, screen
|
from core import utils, screen
|
||||||
|
from core.screen import Screen
|
||||||
from core.vars import logger, PYTHON_EXEC
|
from core.vars import logger, PYTHON_EXEC
|
||||||
from ui import choices
|
from ui import choices
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ class Stack:
|
|||||||
self.port = port
|
self.port = port
|
||||||
self.pid_file = self.path / f".pid"
|
self.pid_file = self.path / f".pid"
|
||||||
self.pid = self.read_pid()
|
self.pid = self.read_pid()
|
||||||
|
self.screen_session: Screen = None
|
||||||
|
|
||||||
def read_pid(self) -> Optional[int]:
|
def read_pid(self) -> Optional[int]:
|
||||||
"""
|
"""
|
||||||
@ -156,6 +158,9 @@ class Stack:
|
|||||||
|
|
||||||
:return: True if the service is running, False otherwise.
|
:return: True if the service is running, False otherwise.
|
||||||
"""
|
"""
|
||||||
|
if self.screen_session and self.pid:
|
||||||
|
return screen.exists(self.screen_session.pid)
|
||||||
|
else:
|
||||||
return self.pid is not None and psutil.pid_exists(self.pid)
|
return self.pid is not None and psutil.pid_exists(self.pid)
|
||||||
|
|
||||||
def create_venv(self) -> None:
|
def create_venv(self) -> None:
|
||||||
@ -224,9 +229,9 @@ 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"))
|
||||||
screen_session = screen.create(name=self.id)
|
self.screen_session = screen.create(name=self.id)
|
||||||
screen_session.send(f"'{full_cmd}'")
|
self.screen_session.send(f"'{full_cmd} && screen -wipe'")
|
||||||
self.write_pid(screen_session.pid)
|
self.write_pid(self.screen_session.pid)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Running command: {full_cmd}")
|
logger.debug(f"Running command: {full_cmd}")
|
||||||
|
@ -15,6 +15,7 @@ def handle_services(action, service):
|
|||||||
clear_terminal()
|
clear_terminal()
|
||||||
|
|
||||||
if service == "back":
|
if service == "back":
|
||||||
|
update_choices()
|
||||||
return
|
return
|
||||||
|
|
||||||
service = loaded_services[service]
|
service = loaded_services[service]
|
||||||
@ -32,7 +33,8 @@ def handle_services(action, service):
|
|||||||
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 (or type cancel):")
|
type_confirmation = questionary.text(
|
||||||
|
f"Please type {service.id} to confirm uninstallation (or type cancel):")
|
||||||
|
|
||||||
value = type_confirmation.ask()
|
value = type_confirmation.ask()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user