Skip to content

Commit

Permalink
Merge pull request #122 from natefoo/user-mode-flag
Browse files Browse the repository at this point in the history
Add a command line flag for controlling systemd user mode
  • Loading branch information
natefoo authored Jan 2, 2025
2 parents e61c14b + da3b99c commit 51735b2
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.11']
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@v3
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Precreate virtualenv
Expand Down
4 changes: 3 additions & 1 deletion gravity/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
7 changes: 4 additions & 3 deletions gravity/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@


@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):
galaxy_server_config_section = "galaxy"
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}")

Expand Down
8 changes: 8 additions & 0 deletions gravity/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 depending 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"
Expand Down
8 changes: 4 additions & 4 deletions gravity/process_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion gravity/process_manager/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 51735b2

Please sign in to comment.