Skip to content

B1-2: Fix systemd template unit — correct ExecStart and ExecStop invocations #135

Closed

Description

@scttfrdmn

Context

configs/systemd/[email protected] has two problems:

  1. ExecStart calls objectfs mount --config ... --foreground with no mount point argument — the process would fail to mount anything
  2. ExecStop calls fusermount3 -u directly rather than using the objectfs unmount subcommand

Both issues mean systemctl start objectfs@mybucket silently fails or mounts incorrectly on every installed system.

What to implement

Update configs/systemd/[email protected]:

ExecStartPre=/usr/bin/objectfs version
ExecStart=/usr/bin/objectfs mount \
    --config ${OBJECTFS_CONFIG:-/etc/objectfs/%i.yaml} \
    --mount-point /mnt/objectfs/%i \
    --foreground
ExecStop=/usr/bin/objectfs unmount /mnt/objectfs/%i

Also add/verify:

  • After=network-online.target (S3 access requires network)
  • Wants=network-online.target
  • ExecStartPre=/usr/bin/mkdir -p /mnt/objectfs/%i (ensure mount point exists)
  • TimeoutStartSec=60 (S3 connectivity may take time)

Add a [Install] section if absent: WantedBy=multi-user.target

Acceptance criteria

  • systemd-analyze verify configs/systemd/[email protected] exits 0 (add to CI)
  • Manual test: systemctl start objectfs@test with a valid config at /etc/objectfs/test.yaml results in a live mount at /mnt/objectfs/test
  • systemctl stop objectfs@test cleanly unmounts
  • journalctl -u objectfs@test shows the mount process started in foreground mode

Sequencing

Depends on B1-1 (objectfs mount --foreground and objectfs unmount must exist first).

Activity

  1. added
    type: bug
    priority: critical
    area: config
    on Apr 7, 2026
  2. added
    effort: small
    on Aug 3, 2026
  3. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Landed in e8750eb on v0.11.0-cli-subcommands, in the same commit as #134 since the unit depends on the subcommands.

    configs/systemd/[email protected] now runs:

    ExecStart=/usr/bin/objectfs mount --config ${OBJECTFS_CONFIG} \
        --mount-point /mnt/objectfs/%i --foreground
    ExecStop=/usr/bin/objectfs unmount /mnt/objectfs/%i
    TimeoutStartSec=60
    TimeoutStopSec=90
    Restart=on-failure

    Two things beyond what the issue asked for, both found while writing the gate.

    RequiresMountsFor=/mnt/objectfs/%i is removed. It orders the unit after the mount units for the directory's parents, but /mnt/objectfs/%i is the mount this unit creates — so the line asks systemd to wait for the thing that is about to be started. The ExecStartPre that creates the directory is what actually has to happen first.

    TimeoutStopSec is now stated rather than inherited, because it is the flush window. SIGTERM makes the mount process unmount, which writes buffered ranges to S3, and its exit code reports whether that completed. A short value there is a SIGKILL through buffered data, and inheriting systemd's default leaves it changeable by a drop-in with no sign in this file.

    Two gates, and neither alone would have caught the old unit.

    TestSystemdUnit* in internal/config parses the unit's Exec* lines through the same parseInvocation the documentation gate uses, and checks every subcommand and flag against the sets scraped from cmd/objectfs/main.go. So a flag renamed in the binary breaks the unit's test, and no list is maintained by hand. It also asserts ExecStop does not call a FUSE helper directly and does not pass -z/-l/-f — adding one of those to make a stubborn stop succeed is a plausible edit that would detach the mount with writes in flight. This runs everywhere go test does, including macOS.

    A systemd-unit CI job runs systemd-analyze verify /etc/systemd/system/[email protected] for the half a Go test cannot check — instantiated, because %i has no value in the template and the uninstantiated form would be checked with unexpanded specifiers in ExecStart, ExecStop, and ReadWritePaths.

    The split matters: systemd-analyze passes the old unit — ExecStart=/usr/local/bin/objectfs s3://%i /mnt/objectfs/%i and ExecStop=/bin/fusermount3 -u are both perfectly valid systemd — and a Go test cannot tell whether RequiresMountsFor means what its author thought.

    Verified by mutation, six ways: ExecStop back to fusermount3 -u, the legacy bare form in ExecStart, --mount-point misspelled, --foreground misspelled, a typo'd ExecStartPre subcommand, and -z + Restart=always + no TimeoutStopSec together. The third of those initially did not fail, which found a real defect in the gate: the unit wraps ExecStart with a trailing backslash, and a loop over raw lines stops there and skips every flag after it. Joining continuations first is load-bearing, and that is now recorded in the test.

    OBJECTFS.md also carried a copyable unit, with ExecStart=/usr/local/bin/objectfs %i /mnt/objectfs/%i — the bare instance name where a storage URI belongs, so it has no scheme and could never have mounted anything. It now points at the shipped unit, which is the one under gate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: configeffort: smallpriority: criticaltype: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions