Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]: Make slurmrestd deb package create slurmrestd system user rather than slurm_ops #39

Open
NucciTheBoss opened this issue Oct 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@NucciTheBoss
Copy link
Member

Per the slurmrestd manpage, the slurmrestd daemon cannot run as root or SlurmUser. This isn't an issue for the Slurm snap as we can create a dedicated user in the install hook, but this a problem for the Slurm Debian package as it does not create a dedicated user for slurmrestd; it only creates a slurm system user.

We can circumvent this issue by creating the user ourselves with slurm_ops using the following block of code:

try:
    subprocess.check_output(["groupadd", "--gid", 64031, "slurmrestd"])
except subprocess.CalledProcessError as e:
    if e.returncode == 9:
        _logger.debug("group 'slurmrestd' already exists")
    else:
        raise SlurmOpsError(f"failed to create group 'slurmrestd'. reason: {e}")

try:
    subprocess.check_output(
        [
            "adduser",
            "--system",
            "--gid",
            64031,
            "--uid",
            64031,
            "--no-create-home",
            "--home",
            "/nonexistent",
            "slurmrestd",
        ]
    )
except subprocess.CalledProcessError as e:
    if e.returncode == 9:
        _logger.debug("user 'slurmrestd' already exists")
    else:
        raise SlurmOpsError(f"failed to create user 'slurmrestd'. reason: {e}")

_logger.debug("replacing default slurmrestd service file")
override = Path("/usr/lib/systemd/system/slurmrestd.service")
override.write_text(
    textwrap.dedent(
        """
        [Unit]
        Description=Slurm REST daemon
        After=network.target munge.service slurmctld.service
        ConditionPathExists=/etc/slurm/slurm.conf
        Documentation=man:slurmrestd(8)

        [Service]
        Type=simple
        EnvironmentFile=-/etc/default/slurmrestd
        Environment="SLURM_JWT=daemon"
        ExecStart=/usr/sbin/slurmrestd $SLURMRESTD_OPTIONS -vv 0.0.0.0:6820
        ExecReload=/bin/kill -HUP $MAINPID
        User=slurmrestd
        Group=slurmrestd

        # Restart service if failed
        Restart=on-failure
        RestartSec=30s

        [Install]
        WantedBy=multi-user.target
        """
    )
)
_systemctl("daemon-reload")

However, this quick fix should really be upstreamed into the Debian package since not everyone using slurmrestd on Debian/Ubuntu is using the slurm_ops charm library.

@NucciTheBoss NucciTheBoss added the enhancement New feature or request label Oct 4, 2024
@NucciTheBoss NucciTheBoss changed the title [Enhancement]: Make slurmrestd deb package create slurmrestd system user rather slurm_ops [Enhancement]: Make slurmrestd deb package create slurmrestd system user rather than slurm_ops Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant