Skip to content

Conversation

@sproberts92
Copy link

@sproberts92 sproberts92 commented Jan 7, 2026

This brings behaviour inline with usual expectations for rpm packages which usually leave this up to the system administrator.

Create a separate postinstall-rpm.sh specifically for rpms and set this as an override for the postinstall script for rpm packages.

This resolves #1334.

@sproberts92 sproberts92 requested a review from a team as a code owner January 7, 2026 12:21
@sproberts92 sproberts92 requested a review from codeboten January 7, 2026 12:21
@sproberts92
Copy link
Author

I am uncertain whether overrides will deep-merge the scripts block. Until I manage to get goreleaser to work locally I'm hoping a CI run can produce a package that I can inspect.

@sproberts92
Copy link
Author

sproberts92 commented Jan 7, 2026

Hmm this won't restart on an upgrade either. I will fix that tomorrow night. The original form of the script but using systemd try-restart instead should do the trick.

@sproberts92 sproberts92 force-pushed the sproberts92/rpm-dont-start-service branch from 57af489 to 6336052 Compare January 8, 2026 10:52
This brings behaviour inline with usual expectations for rpm packages
which usually leave this up to the system administrator.

Create a separate postinstall-rpm.sh specifically for rpms and set this
as an override for the postinstall script for rpm packages.
@sproberts92 sproberts92 force-pushed the sproberts92/rpm-dont-start-service branch from 6336052 to f47fdd0 Compare January 8, 2026 10:57
component: "packaging"

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Prevent service being started/enabled upon install for rpms"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this changelog doesn't reflect the changes. You seem to be checking for systemd presence in the system.
Please clarify this changelog.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is an accurate description of the change in behaviour for end users - please also refer to #1334 for more expansion on the motivation here.

All of the logic in the scripts that I am adding already exists in the base postinstall.sh scripts - my change merely creates specific versions with slightly different outcomes for rpms.

For example, for the plain otelcol distribution, the diff between the existing script and my rpm specific override:

--- a/distributions/otelcol/postinstall.sh
+++ b/distributions/otelcol/postinstall-rpm.sh
@@ -7,10 +7,9 @@ if command -v systemctl >/dev/null 2>&1; then
     if [ -d /run/systemd/system ]; then
         systemctl daemon-reload
     fi
-    systemctl enable otelcol.service
     if [ -f /etc/otelcol/config.yaml ]; then
         if [ -d /run/systemd/system ]; then
-            systemctl restart otelcol.service
+            systemctl try-restart otelcol.service
         fi
     fi
 fi

If you think there's a better approach then I'm happy to adjust.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I see. There is boilerplate on that script you can strip away imo ; remove the check for the config file presence. Is checking for /run/systemd/system presence even necessary?

@sproberts92 sproberts92 requested a review from atoulme January 9, 2026 10:51
@sproberts92
Copy link
Author

I am uncertain whether overrides will deep-merge the scripts block. Until I manage to get goreleaser to work locally I'm hoping a CI run can produce a package that I can inspect.

Figured out how to build the rpms locally now - so yes the config I've used here does deep merge the scripts block:

$ rpm -qlp --scripts otelcol_0.144.0-next_linux_amd64.rpm
preinstall scriptlet (using /bin/sh):
#!/bin/sh

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

getent passwd otel >/dev/null || useradd --system --user-group --no-create-home --shell /sbin/nologin otel

postinstall scriptlet (using /bin/sh):
#!/bin/sh

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

if command -v systemctl >/dev/null 2>&1; then
    if [ -d /run/systemd/system ]; then
        systemctl daemon-reload
    fi
    if [ -f /etc/otelcol/config.yaml ]; then
        if [ -d /run/systemd/system ]; then
            systemctl try-restart otelcol.service
        fi
    fi
fi

preuninstall scriptlet (using /bin/sh):
#!/bin/sh

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

if [ "$1" != "1" ]; then
    if command -v systemctl >/dev/null 2>&1; then
        systemctl stop otelcol.service
        systemctl disable otelcol.service
    fi
fi

/etc/otelcol/config.yaml
/etc/otelcol/otelcol.conf
/lib/systemd/system/otelcol.service
/usr/bin/otelcol

@sproberts92
Copy link
Author

The current CI failure looks unrelated to my change, and probably transient. @mowies, any chance you could please re-trigger?

@atoulme
Copy link
Contributor

atoulme commented Jan 24, 2026

I reran CI

@sproberts92
Copy link
Author

Looks better now, thanks 👍

if [ -d /run/systemd/system ]; then
systemctl daemon-reload
fi
if [ -f /etc/otelcol-contrib/config.yaml ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you checking for this file presence?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rpm package should not start or enable the service upon installation

2 participants