Set ProcessController's process file descriptors to None, and renamed START_COMMAND to START_COMMAND_FILE to load start command from a file
This commit is contained in:
parent
cd2eb8de9d
commit
c982968310
2 changed files with 12 additions and 7 deletions
|
|
@ -4,7 +4,7 @@ from dotenv import dotenv_values
|
||||||
class Config:
|
class Config:
|
||||||
data = dotenv_values()
|
data = dotenv_values()
|
||||||
MINECRAFTD_PASSWORD: str | None = data.get("MINECRAFTD_PASSWORD")
|
MINECRAFTD_PASSWORD: str | None = data.get("MINECRAFTD_PASSWORD")
|
||||||
START_COMMAND: str = data.get("START_COMMAND") or "python proc.py"
|
START_COMMAND_FILE: str = data.get("START_COMMAND_FILE") or "start.sh"
|
||||||
SERVER_HOST: str = data.get("SERVER_HOST") or "localhost"
|
SERVER_HOST: str = data.get("SERVER_HOST") or "localhost"
|
||||||
SERVER_PORT: int = int(data.get("SERVER_PORT") or 25565)
|
SERVER_PORT: int = int(data.get("SERVER_PORT") or 25565)
|
||||||
SERVER_RCON_PORT: int = int(data.get("SERVER_RCON_PORT") or 25575)
|
SERVER_RCON_PORT: int = int(data.get("SERVER_RCON_PORT") or 25575)
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,24 @@
|
||||||
import shlex
|
import shlex
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import PIPE, Popen
|
from subprocess import Popen
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
|
from mcrcon import MCRcon
|
||||||
|
from mcstatus import JavaServer
|
||||||
|
|
||||||
from classes import ProcessStatus, ServerStatus
|
from classes import ProcessStatus, ServerStatus
|
||||||
from config import Config
|
from config import Config
|
||||||
from logs import logger
|
from logs import logger
|
||||||
from mcrcon import MCRcon
|
|
||||||
from mcstatus import JavaServer
|
|
||||||
|
|
||||||
|
|
||||||
class ProcessController:
|
class ProcessController:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.start_command: list[str] = shlex.split(Config.START_COMMAND)
|
self.start_command: list[str] = shlex.split(
|
||||||
|
Path(Config.START_COMMAND_FILE).read_text()
|
||||||
|
)
|
||||||
self.process: Popen | None = None
|
self.process: Popen | None = None
|
||||||
self.last_status: Literal[ProcessStatus.STOPPED, ProcessStatus.CRASHED] = (
|
self.last_status: Literal[ProcessStatus.STOPPED, ProcessStatus.CRASHED] = (
|
||||||
ProcessStatus.STOPPED
|
ProcessStatus.STOPPED
|
||||||
|
|
@ -36,8 +39,10 @@ class ProcessController:
|
||||||
|
|
||||||
self.process = Popen(
|
self.process = Popen(
|
||||||
self.start_command,
|
self.start_command,
|
||||||
stdout=PIPE,
|
stdout=None,
|
||||||
stderr=PIPE,
|
stderr=None,
|
||||||
|
stdin=None,
|
||||||
|
start_new_session=True,
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
"ProcessController.start() - Started process with PID: %s",
|
"ProcessController.start() - Started process with PID: %s",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue