# HG changeset patch # User Goffi # Date 1705250882 -3600 # Node ID b263393430767b6e9141e4d8809e18736f2fe130 # Parent 6a8cc6d668a4b5d99767f39870e2e2c1fc2ae717 core: use a user specific directory for PID file: default location of pid file is now specific to logged user, this allow to run several instances of Libervia by different users on the same machine without PID conflicts. diff -r 6a8cc6d668a4 -r b26339343076 libervia/backend/core/constants.py --- a/libervia/backend/core/constants.py Thu Dec 14 09:19:32 2023 +0100 +++ b/libervia/backend/core/constants.py Sun Jan 14 17:48:02 2024 +0100 @@ -21,12 +21,19 @@ from os.path import expanduser, realpath except ImportError: BaseDirectory = None -from os.path import dirname +from os.path import dirname, join import tempfile from typing import Final from libervia import backend +try: + from getpass import getuser +except ImportError: + logged_user = "unkonwn" +else: + logged_user = getuser() + class Const(object): @@ -458,7 +465,6 @@ return cls.BOOL_TRUE if value else cls.BOOL_FALSE - ## Configuration ## if ( BaseDirectory @@ -489,7 +495,7 @@ ).getAbsolutePath(), Const.APP_NAME_FILE, ), - "pid_dir": tempfile.gettempdir(), + "pid_dir": join(tempfile.gettempdir(), Const.APP_NAME_FILE, logged_user), "log_dir": "%(local_dir)s", } Const.CONFIG_FILES = [ @@ -532,7 +538,7 @@ "media_dir": "/usr/share/" + Const.APP_NAME_FILE + "/media", "local_dir": BaseDirectory.save_data_path(Const.APP_NAME_FILE), "downloads_dir": "~/Downloads/" + Const.APP_NAME_FILE, - "pid_dir": tempfile.gettempdir(), + "pid_dir": join(tempfile.gettempdir(), Const.APP_NAME_FILE, logged_user), "log_dir": "%(local_dir)s", } diff -r 6a8cc6d668a4 -r b26339343076 libervia/backend/core/launcher.py --- a/libervia/backend/core/launcher.py Thu Dec 14 09:19:32 2023 +0100 +++ b/libervia/backend/core/launcher.py Sun Jan 14 17:48:02 2024 +0100 @@ -197,6 +197,7 @@ def get_pid_file(self, config): pid_dir = Path(config.get("DEFAULT", "pid_dir")).expanduser() + pid_dir.mkdir(parents=True, exist_ok=True) return pid_dir / f"{self.APP_NAME_FILE}.pid" def wait_for_service(