From ebb17c41a30cb44de62c2d514feba4e996360693 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Fri, 20 Dec 2024 16:03:07 -0500 Subject: [PATCH 1/4] Add a command line flag for controlling systemd user mode --- gravity/cli.py | 4 +++- gravity/config_manager.py | 7 ++++--- gravity/options.py | 8 ++++++++ gravity/process_manager/__init__.py | 8 ++++---- gravity/process_manager/systemd.py | 4 +++- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/gravity/cli.py b/gravity/cli.py index aaf7257..af99aad 100644 --- a/gravity/cli.py +++ b/gravity/cli.py @@ -83,11 +83,13 @@ def galaxy(ctx, debug, config_file, state_dir, quiet): @options.debug_option() @options.config_file_option() @options.state_dir_option() +@options.user_mode_option() @click.pass_context -def galaxyctl(ctx, debug, config_file, state_dir): +def galaxyctl(ctx, debug, config_file, state_dir, user): """Manage Galaxy server configurations and processes.""" set_debug(debug) ctx.cm_kwargs = { "config_file": config_file, "state_dir": state_dir, + "user_mode": user, } diff --git a/gravity/config_manager.py b/gravity/config_manager.py index d202e82..1b26ece 100644 --- a/gravity/config_manager.py +++ b/gravity/config_manager.py @@ -35,8 +35,8 @@ @contextlib.contextmanager -def config_manager(config_file=None, state_dir=None): - yield ConfigManager(config_file=config_file, state_dir=state_dir) +def config_manager(config_file=None, state_dir=None, user_mode=None): + yield ConfigManager(config_file=config_file, state_dir=state_dir, user_mode=user_mode) class ConfigManager(object): @@ -44,12 +44,13 @@ class ConfigManager(object): gravity_config_section = "gravity" app_config_file_option = "galaxy_config_file" - def __init__(self, config_file=None, state_dir=None): + def __init__(self, config_file=None, state_dir=None, user_mode=None): self.__configs = {} self.state_dir = None if state_dir is not None: # convert from pathlib.Path self.state_dir = str(state_dir) + self.user_mode = user_mode gravity.io.debug(f"Gravity state dir: {state_dir}") diff --git a/gravity/options.py b/gravity/options.py index 1917672..edf9d69 100644 --- a/gravity/options.py +++ b/gravity/options.py @@ -23,6 +23,14 @@ def config_file_option(): ) +def user_mode_option(): + return click.option( + "--user/--no-user", + default=None, + help="Use `systemctl/journalctl --user` (default: automatic depeending on whether run as root)", + ) + + def no_log_option(): return click.option( '--quiet', is_flag=True, default=False, help="Only output supervisor logs, do not include process logs" diff --git a/gravity/process_manager/__init__.py b/gravity/process_manager/__init__.py index b07a3aa..f0fa7bd 100644 --- a/gravity/process_manager/__init__.py +++ b/gravity/process_manager/__init__.py @@ -65,8 +65,8 @@ def decorator(self, *args, instance_names=None, **kwargs): class BaseProcessExecutionEnvironment(metaclass=ABCMeta): - def __init__(self, state_dir=None, config_file=None, config_manager=None, **kwargs): - self.config_manager = config_manager or ConfigManager(state_dir=state_dir, config_file=config_file) + def __init__(self, state_dir=None, config_file=None, config_manager=None, user_mode=None): + self.config_manager = config_manager or ConfigManager(state_dir=state_dir, config_file=config_file, user_mode=user_mode) self.tail = which("tail") @abstractmethod @@ -291,8 +291,8 @@ def exec(self, config, service, service_instance_number=None, no_exec=False): class ProcessManagerRouter: - def __init__(self, state_dir=None, config_file=None, config_manager=None, **kwargs): - self.config_manager = config_manager or ConfigManager(state_dir=state_dir, config_file=config_file) + def __init__(self, state_dir=None, config_file=None, config_manager=None, user_mode=None, **kwargs): + self.config_manager = config_manager or ConfigManager(state_dir=state_dir, config_file=config_file, user_mode=user_mode) self._load_pm_modules(**kwargs) self._process_executor = ProcessExecutor(config_manager=self.config_manager) diff --git a/gravity/process_manager/systemd.py b/gravity/process_manager/systemd.py index efea36d..3d94fe2 100644 --- a/gravity/process_manager/systemd.py +++ b/gravity/process_manager/systemd.py @@ -110,7 +110,9 @@ class SystemdProcessManager(BaseProcessManager): def __init__(self, foreground=False, **kwargs): super(SystemdProcessManager, self).__init__(**kwargs) - self.user_mode = not self.config_manager.is_root + self.user_mode = self.config_manager.user_mode + if self.user_mode is None: + self.user_mode = not self.config_manager.is_root @property def __systemd_unit_dir(self): From 05d2fbd7936861c461c2b461eea30f7b929d3045 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Mon, 23 Dec 2024 09:27:28 -0500 Subject: [PATCH 2/4] Update GH action and Python versions --- .github/workflows/lint.yaml | 6 +++--- .github/workflows/package.yaml | 6 +++--- .github/workflows/publish.yaml | 4 ++-- .github/workflows/test.yaml | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 1140c97..396170a 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -9,10 +9,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.10'] + python-version: ['3.9', '3.13'] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install tox diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml index 38d6920..708472a 100644 --- a/.github/workflows/package.yaml +++ b/.github/workflows/package.yaml @@ -9,10 +9,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.10'] + python-version: ['3.9', '3.13'] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 9b5a3be..1ea24b6 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -10,9 +10,9 @@ jobs: name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: Set up Python 3.9 - uses: actions/setup-python@v1 + uses: actions/setup-python@v5 with: python-version: 3.9 - name: Install dependencies diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f3b2580..7fdf1ca 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,15 +10,15 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.8', '3.11'] + python-version: ['3.9', '3.11'] galaxy-branch: ['release_23.0', 'dev'] exclude: # this results in lengthy and expensive numpy wheel builds - python-version: '3.10' galaxy-branch: 'release_22.01' steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Precreate virtualenv From da0e5049fd30e3a69ae5106801ccb74af77f28a6 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Mon, 23 Dec 2024 17:35:02 -0500 Subject: [PATCH 3/4] Update .github/workflows/test.yaml Co-authored-by: Nicola Soranzo --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7fdf1ca..61efb37 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.9', '3.11'] + python-version: ['3.9', '3.13'] galaxy-branch: ['release_23.0', 'dev'] exclude: # this results in lengthy and expensive numpy wheel builds From 1e230297a223f4de34357efec8d00cfb362d6441 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Mon, 23 Dec 2024 17:42:31 -0500 Subject: [PATCH 4/4] Excluse 3.13 + release_23.0 tests --- .github/workflows/test.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 61efb37..133fa64 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,9 +13,10 @@ jobs: python-version: ['3.9', '3.13'] galaxy-branch: ['release_23.0', 'dev'] exclude: - # this results in lengthy and expensive numpy wheel builds - - python-version: '3.10' - galaxy-branch: 'release_22.01' + # either the release existed before the python release or some expensive-to-build wheels (e.g. numpy) don't + # exist for the pinned package version / python version combo + - python-version: '3.13' + galaxy-branch: 'release_23.0' steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5