mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Configure location of lock files
Before this commit, moulinette was using lockfiles in /var/run. However this prevents it to run as non-root user. To allow this and to facilitate unit testing (typically run as regular user), this commit adds a MOULINETTE_RUN_DIR env variable.
This commit is contained in:
parent
ec36c8a579
commit
78d9301490
4 changed files with 6 additions and 3 deletions
|
@ -419,6 +419,7 @@ class ActionsMap(object):
|
||||||
moulinette_env = init_moulinette_env()
|
moulinette_env = init_moulinette_env()
|
||||||
DATA_DIR = moulinette_env["DATA_DIR"]
|
DATA_DIR = moulinette_env["DATA_DIR"]
|
||||||
CACHE_DIR = moulinette_env["CACHE_DIR"]
|
CACHE_DIR = moulinette_env["CACHE_DIR"]
|
||||||
|
self.run_dir = moulinette_env["RUN_DIR"]
|
||||||
|
|
||||||
if len(namespaces) == 0:
|
if len(namespaces) == 0:
|
||||||
namespaces = self.get_namespaces()
|
namespaces = self.get_namespaces()
|
||||||
|
@ -545,7 +546,7 @@ class ActionsMap(object):
|
||||||
full_action_name = "%s.%s.%s" % (namespace, category, action)
|
full_action_name = "%s.%s.%s" % (namespace, category, action)
|
||||||
|
|
||||||
# Lock the moulinette for the namespace
|
# Lock the moulinette for the namespace
|
||||||
with MoulinetteLock(namespace, timeout):
|
with MoulinetteLock(namespace, timeout, lock_dir=self.run_dir):
|
||||||
start = time()
|
start = time()
|
||||||
try:
|
try:
|
||||||
mod = __import__(
|
mod = __import__(
|
||||||
|
|
|
@ -454,12 +454,12 @@ class MoulinetteLock(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, namespace, timeout=None, interval=0.5):
|
def __init__(self, namespace, timeout=None, interval=0.5, lock_dir="/var/run"):
|
||||||
self.namespace = namespace
|
self.namespace = namespace
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
|
|
||||||
self._lockfile = "/var/run/moulinette_%s.lock" % namespace
|
self._lockfile = "{}/moulinette_{}.lock".format(lock_dir, namespace)
|
||||||
self._stale_checked = False
|
self._stale_checked = False
|
||||||
self._locked = False
|
self._locked = False
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,5 @@ def init_moulinette_env():
|
||||||
"MOULINETTE_LOCALES_DIR", "/usr/share/moulinette/locale"
|
"MOULINETTE_LOCALES_DIR", "/usr/share/moulinette/locale"
|
||||||
),
|
),
|
||||||
"CACHE_DIR": environ.get("MOULINETTE_CACHE_DIR", "/var/cache/moulinette"),
|
"CACHE_DIR": environ.get("MOULINETTE_CACHE_DIR", "/var/cache/moulinette"),
|
||||||
|
"RUN_DIR": environ.get("MOULINETTE_RUN_DIR", "/var/run")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,3 +5,4 @@ testpaths = test/
|
||||||
env =
|
env =
|
||||||
MOULINETTE_LOCALES_DIR = {PWD}/locales
|
MOULINETTE_LOCALES_DIR = {PWD}/locales
|
||||||
TESTS_RUN = True
|
TESTS_RUN = True
|
||||||
|
MOULINETTE_RUN_DIR=.
|
||||||
|
|
Loading…
Add table
Reference in a new issue