diff --git a/.chloggen/rpm_dont_start_service.yaml b/.chloggen/rpm_dont_start_service.yaml new file mode 100644 index 000000000..e25b82da1 --- /dev/null +++ b/.chloggen/rpm_dont_start_service.yaml @@ -0,0 +1,26 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: "breaking" + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +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" + +# One or more tracking issues or pull requests related to the change +issues: [1334] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: "This brings behaviour inline with usual expectations for rpm packages which usually leave this up to the system administrator." + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] + diff --git a/cmd/goreleaser/internal/builder.go b/cmd/goreleaser/internal/builder.go index e5f43e2dd..e67f7ba43 100644 --- a/cmd/goreleaser/internal/builder.go +++ b/cmd/goreleaser/internal/builder.go @@ -210,6 +210,9 @@ func (b *distributionBuilder) newNfpms(dist string) []config.NFPM { Overrides: map[string]config.NFPMOverridables{ "rpm": { Dependencies: []string{"/bin/sh"}, + Scripts: config.NFPMScripts{ + PostInstall: "postinstall-rpm.sh", + }, }, }, NFPMOverridables: config.NFPMOverridables{ diff --git a/cmd/goreleaser/internal/distro_opamp.go b/cmd/goreleaser/internal/distro_opamp.go index 1399061c7..e995fb2e1 100644 --- a/cmd/goreleaser/internal/distro_opamp.go +++ b/cmd/goreleaser/internal/distro_opamp.go @@ -46,6 +46,11 @@ var ( content.Source = path.Join("cmd", d.Name, content.Source) d.Nfpms[0].Contents[i] = content } + + rpm_overrides := d.Nfpms[0].Overrides["rpm"] + rpm_overrides.Scripts.PostInstall = path.Join("cmd", d.Name, d.Nfpms[0].Overrides["rpm"].Scripts.PostInstall) + d.Nfpms[0].Overrides["rpm"] = rpm_overrides + d.Nfpms[0].Scripts.PreInstall = path.Join("cmd", d.Name, d.Nfpms[0].Scripts.PreInstall) d.Nfpms[0].Scripts.PostInstall = path.Join("cmd", d.Name, d.Nfpms[0].Scripts.PostInstall) d.Nfpms[0].Scripts.PreRemove = path.Join("cmd", d.Name, d.Nfpms[0].Scripts.PreRemove) diff --git a/cmd/opampsupervisor/.goreleaser.yaml b/cmd/opampsupervisor/.goreleaser.yaml index 2c4a36af6..10aeb62e4 100644 --- a/cmd/opampsupervisor/.goreleaser.yaml +++ b/cmd/opampsupervisor/.goreleaser.yaml @@ -77,6 +77,8 @@ nfpms: rpm: dependencies: - /bin/sh + scripts: + postinstall: cmd/opampsupervisor/postinstall-rpm.sh id: opampsupervisor ids: - opampsupervisor-linux diff --git a/cmd/opampsupervisor/postinstall-rpm.sh b/cmd/opampsupervisor/postinstall-rpm.sh new file mode 100755 index 000000000..8c1837c21 --- /dev/null +++ b/cmd/opampsupervisor/postinstall-rpm.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +if command -v systemctl >/dev/null 2>&1; then + systemctl daemon-reload + systemctl try-restart opampsupervisor.service +fi diff --git a/distributions/otelcol-contrib/.goreleaser.yaml b/distributions/otelcol-contrib/.goreleaser.yaml index de46c3a22..d295ccc06 100644 --- a/distributions/otelcol-contrib/.goreleaser.yaml +++ b/distributions/otelcol-contrib/.goreleaser.yaml @@ -101,6 +101,8 @@ nfpms: rpm: dependencies: - /bin/sh + scripts: + postinstall: postinstall-rpm.sh id: otelcol-contrib ids: - otelcol-contrib-linux diff --git a/distributions/otelcol-contrib/postinstall-rpm.sh b/distributions/otelcol-contrib/postinstall-rpm.sh new file mode 100755 index 000000000..120fb6649 --- /dev/null +++ b/distributions/otelcol-contrib/postinstall-rpm.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +if command -v systemctl >/dev/null 2>&1; then + systemctl daemon-reload + systemctl try-restart otelcol-contrib.service +fi diff --git a/distributions/otelcol-otlp/.goreleaser.yaml b/distributions/otelcol-otlp/.goreleaser.yaml index 5bd2d9c99..738783126 100644 --- a/distributions/otelcol-otlp/.goreleaser.yaml +++ b/distributions/otelcol-otlp/.goreleaser.yaml @@ -92,6 +92,8 @@ nfpms: rpm: dependencies: - /bin/sh + scripts: + postinstall: postinstall-rpm.sh id: otelcol-otlp ids: - otelcol-otlp-linux diff --git a/distributions/otelcol-otlp/postinstall-rpm.sh b/distributions/otelcol-otlp/postinstall-rpm.sh new file mode 100755 index 000000000..619aed9c4 --- /dev/null +++ b/distributions/otelcol-otlp/postinstall-rpm.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +if command -v systemctl >/dev/null 2>&1; then + systemctl daemon-reload + systemctl try-restart otelcol-otlp.service +fi diff --git a/distributions/otelcol/.goreleaser.yaml b/distributions/otelcol/.goreleaser.yaml index c73e4e66e..cf9dbec9c 100644 --- a/distributions/otelcol/.goreleaser.yaml +++ b/distributions/otelcol/.goreleaser.yaml @@ -96,6 +96,8 @@ nfpms: rpm: dependencies: - /bin/sh + scripts: + postinstall: postinstall-rpm.sh id: otelcol ids: - otelcol-linux diff --git a/distributions/otelcol/postinstall-rpm.sh b/distributions/otelcol/postinstall-rpm.sh new file mode 100755 index 000000000..c29c1107f --- /dev/null +++ b/distributions/otelcol/postinstall-rpm.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +if command -v systemctl >/dev/null 2>&1; then + systemctl daemon-reload + systemctl try-restart otelcol.service +fi diff --git a/scripts/package-tests/package-tests.sh b/scripts/package-tests/package-tests.sh index ef8f14ada..eef6be262 100755 --- a/scripts/package-tests/package-tests.sh +++ b/scripts/package-tests/package-tests.sh @@ -81,6 +81,23 @@ podman run --name "$container_name" --privileged -v /sys/fs/cgroup:/sys/fs/cgrou install_pkg "$container_name" "$PKG_PATH" +if [[ "$pkg_type" == "rpm" ]]; then + echo "Checking $SERVICE_NAME service state after install ..." + if $container_exec systemctl is-active "$SERVICE_NAME"; then + echo "$SERVICE_NAME service running after rpm install" >&2 + exit 1 + fi + echo "$SERVICE_NAME service correctly not running after rpm install" + + if $container_exec systemctl is-enabled "$SERVICE_NAME"; then + echo "$SERVICE_NAME service enabled after rpm install" >&2 + exit 1 + fi + echo "$SERVICE_NAME service correctly not enabled after rpm install" + + $container_exec systemctl start "$SERVICE_NAME" +fi + # If we got to this point, we might need to check the logs of the systemd service # when it's not properly active. This is added as a trap because the check # for service status below will return an error exitcode if the service is