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.
This commit is contained in:
parent
00de7e0de0
commit
dc8078fe4c
2 changed files with 11 additions and 4 deletions
|
|
@ -21,12 +21,19 @@ try:
|
|||
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 @@ class Const(object):
|
|||
return cls.BOOL_TRUE if value else cls.BOOL_FALSE
|
||||
|
||||
|
||||
|
||||
## Configuration ##
|
||||
if (
|
||||
BaseDirectory
|
||||
|
|
@ -489,7 +495,7 @@ if (
|
|||
).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 @@ if (
|
|||
"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",
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -197,6 +197,7 @@ class Launcher:
|
|||
|
||||
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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue