From 05b137283bf04f93f6df2f48563eee1227fc380a Mon Sep 17 00:00:00 2001 From: Ansgar Schulte <1299623+ansgarschulte@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:05:20 +0200 Subject: [PATCH] build: add linux packages build --- .dockerignore | 4 + .github/workflows/ci.yml | 7 +- .gitignore | 4 + .goreleaser.yaml | 83 ++++++++++++++++ Dockerfile | 22 +---- Makefile | 10 +- go.mod | 6 +- go.sum | 8 ++ .../steadybit-extension-prometheus | 8 ++ .../config/steadybit/extension-prometheus | 3 + .../extensions.d/extension-prometheus.yaml | 4 + .../init.d/steadybit-extension-prometheus | 99 +++++++++++++++++++ linuxpkg/scripts/postinstall.sh | 85 ++++++++++++++++ linuxpkg/scripts/postremove.sh | 49 +++++++++ linuxpkg/scripts/preinstall.sh | 11 +++ linuxpkg/scripts/preremove.sh | 43 ++++++++ .../steadybit-extension-prometheus.service | 18 ++++ 17 files changed, 440 insertions(+), 24 deletions(-) create mode 100644 .dockerignore create mode 100644 .goreleaser.yaml create mode 100644 linuxpkg/config/logrotate.d/steadybit-extension-prometheus create mode 100644 linuxpkg/config/steadybit/extension-prometheus create mode 100644 linuxpkg/config/steadybit/extensions.d/extension-prometheus.yaml create mode 100755 linuxpkg/init.d/steadybit-extension-prometheus create mode 100755 linuxpkg/scripts/postinstall.sh create mode 100755 linuxpkg/scripts/postremove.sh create mode 100755 linuxpkg/scripts/preinstall.sh create mode 100755 linuxpkg/scripts/preremove.sh create mode 100644 linuxpkg/systemd/steadybit-extension-prometheus.service diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8c4b460 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +/dist +/coverageout +/.idea +*.iml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f46d5f..7084774 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,10 +19,15 @@ jobs: uses: steadybit/extension-kit/.github/workflows/reusable-extension-ci.yml@main with: go_version: '1.22' - build_linux_packages: false + build_linux_packages: true VERSION_BUMPER_APPID: ${{ vars.GH_APP_STEADYBIT_APP_ID }} secrets: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} PAT_TOKEN_EXTENSION_DEPLOYER: ${{ secrets.PAT_TOKEN_EXTENSION_DEPLOYER }} + MAVEN_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} + MAVEN_GPG_PRIVATE_KEY_PASSWORD: ${{ secrets.MAVEN_GPG_PRIVATE_KEY_PASSWORD }} + PAT_TOKEN_GORELEASER: ${{ secrets.PAT_TOKEN }} + STEADYBIT_ARTIFACT_SERVER_USERNAME: ${{ secrets.STEADYBIT_ARTIFACT_SERVER_USERNAME }} + STEADYBIT_ARTIFACT_SERVER_PASSWORD: ${{ secrets.STEADYBIT_ARTIFACT_SERVER_PASSWORD }} SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} VERSION_BUMPER_SECRET: ${{ secrets.GH_APP_STEADYBIT_PRIVATE_KEY }} diff --git a/.gitignore b/.gitignore index 47cc671..07c7d34 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ extension-prometheus.iml /e2e/e2e-coverage-docker.out /licenses /snyk.sarif +/gpg.key +/dist +/extension + diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..5e0dd70 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,83 @@ +project_name: steadybit-extension-prometheus +version: 2 +before: + hooks: + - go mod download + - make licenses-report + +release: + prerelease: "false" + +git: + ignore_tags: + - steadybit-extension-prometheus-* + +builds: + - binary: extension-prometheus + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + flags: + - -cover={{ if index .Env "BUILD_WITH_COVERAGE" }}{{ .Env.BUILD_WITH_COVERAGE }}{{ else }}false{{ end }} + - -covermode=atomic + ldflags: + - -s -w + - -X github.com/steadybit/extension-kit/extbuild.ExtensionName={{.ProjectName}} + - -X github.com/steadybit/extension-kit/extbuild.Version={{.Version}} + - -X github.com/steadybit/extension-kit/extbuild.Revision={{.Commit}} + +archives: + - name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" + +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +nfpms: + - package_name: "steadybit-extension-prometheus" + file_name_template: "{{ .ConventionalFileName }}" + formats: + - deb + - rpm + maintainer: "Johannes Edmeier " + description: | + Steadybit Extension Prometheus + vendor: "steadybit GmbH" + homepage: "https://steadybit.com" + license: "Steadybit license" + builds: + - steadybit-extension-prometheus + bindir: /opt/steadybit/extension-prometheus + contents: + - src: ./linuxpkg/systemd + dst: /usr/lib/systemd/system + - src: ./linuxpkg/init.d + dst: /etc/init.d + - src: ./linuxpkg/config + dst: /etc + type: config + - src: ./licenses + dst: /opt/steadybit/extension-prometheus/licenses + scripts: + preinstall: ./linuxpkg/scripts/preinstall.sh + postinstall: ./linuxpkg/scripts/postinstall.sh + preremove: ./linuxpkg/scripts/preremove.sh + postremove: ./linuxpkg/scripts/postremove.sh + + rpm: + signature: + key_file: ./gpg.key + deb: + signature: + key_file: ./gpg.key diff --git a/Dockerfile b/Dockerfile index 9673645..28633ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,33 +3,22 @@ ## ## Build ## -FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS build +FROM --platform=$BUILDPLATFORM goreleaser/goreleaser:v2.0.1 AS build ARG TARGETOS TARGETARCH -ARG NAME -ARG VERSION -ARG REVISION -ARG ADDITIONAL_BUILD_PARAMS +ARG BUILD_WITH_COVERAGE +ARG BUILD_SNAPSHOT=true ARG SKIP_LICENSES_REPORT=false WORKDIR /app -RUN apk add build-base COPY go.mod ./ COPY go.sum ./ RUN go mod download COPY . . -RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build \ - -ldflags="\ - -X 'github.com/steadybit/extension-kit/extbuild.ExtensionName=${NAME}' \ - -X 'github.com/steadybit/extension-kit/extbuild.Version=${VERSION}' \ - -X 'github.com/steadybit/extension-kit/extbuild.Revision=${REVISION}'" \ - -o ./extension \ - ${ADDITIONAL_BUILD_PARAMS} -RUN make licenses-report - +RUN GOOS=$TARGETOS GOARCH=$TARGETARCH goreleaser build --snapshot="${BUILD_SNAPSHOT}" --single-target -o extension ## ## Runtime ## @@ -49,7 +38,6 @@ WORKDIR / COPY --from=build /app/extension /extension COPY --from=build /app/licenses /licenses -EXPOSE 8087 -EXPOSE 8088 +EXPOSE 8087 8088 ENTRYPOINT ["/extension"] diff --git a/Makefile b/Makefile index 600bdc2..2517631 100755 --- a/Makefile +++ b/Makefile @@ -73,8 +73,7 @@ chart-bump-version: ## build: build the extension .PHONY: build build: - go mod verify - go build -o=./extension + goreleaser build --clean --snapshot --single-target -o extension ## run: run the extension .PHONY: run @@ -84,4 +83,9 @@ run: tidy build ## container: build the container image .PHONY: container container: - docker build --build-arg ADDITIONAL_BUILD_PARAMS="-cover -covermode=atomic" --build-arg SKIP_LICENSES_REPORT="true" -t extension-prometheus:latest . + docker buildx build --build-arg BUILD_WITH_COVERAGE="true" -t extension-prometheus:latest --output=type=docker . + +## linuxpkg: build the linux packages +.PHONY: linuxpkg +linuxpkg: + goreleaser release --clean --snapshot --skip=sign diff --git a/go.mod b/go.mod index 5b1913f..c063fb0 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( github.com/elastic/go-windows v1.0.1 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/getkin/kin-openapi v0.125.0 // indirect + github.com/getkin/kin-openapi v0.126.0 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.2.6 // indirect @@ -112,11 +112,11 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.24.0 // indirect - golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect + golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/sys v0.22.0 // indirect golang.org/x/term v0.21.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect diff --git a/go.sum b/go.sum index 07fe98d..1c53f80 100644 --- a/go.sum +++ b/go.sum @@ -24,6 +24,7 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cilium/ebpf v0.15.0 h1:7NxJhNiBT3NG8pZJ3c+yfrVdHY8ScgKD27sScgjLMMk= github.com/cilium/ebpf v0.15.0/go.mod h1:DHp1WyrLeiBh19Cf/tfiSMhqheEiK8fXFZ4No0P1Hso= +github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0= github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0= github.com/containerd/containerd v1.7.18 h1:jqjZTQNfXGoEaZdW1WwPU0RqSn1Bm2Ay/KJPUuO8nao= @@ -60,6 +61,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/getkin/kin-openapi v0.125.0 h1:jyQCyf2qXS1qvs2U00xQzkGCqYPhEhZDmSmVt65fXno= github.com/getkin/kin-openapi v0.125.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= +github.com/getkin/kin-openapi v0.126.0 h1:c2cSgLnAsS0xYfKsgt5oBV6MYRM/giU8/RtwUY4wyfY= +github.com/getkin/kin-openapi v0.126.0/go.mod h1:7mONz8IwmSRg6RttPu6v8U/OJ+gr+J99qSFNjPGSQqw= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -312,6 +315,8 @@ golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= +golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w= +golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -360,6 +365,8 @@ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -387,6 +394,7 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= +golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/linuxpkg/config/logrotate.d/steadybit-extension-prometheus b/linuxpkg/config/logrotate.d/steadybit-extension-prometheus new file mode 100644 index 0000000..5935737 --- /dev/null +++ b/linuxpkg/config/logrotate.d/steadybit-extension-prometheus @@ -0,0 +1,8 @@ +/var/log/steadybit-extension-prometheus.log { + copytruncate + size 10m + create 700 steadybit steadybit + dateext + rotate 5 + compress +} diff --git a/linuxpkg/config/steadybit/extension-prometheus b/linuxpkg/config/steadybit/extension-prometheus new file mode 100644 index 0000000..5448056 --- /dev/null +++ b/linuxpkg/config/steadybit/extension-prometheus @@ -0,0 +1,3 @@ +STEADYBIT_LOG_LEVEL=info +STEADYBIT_LOG_FORMAT=text +STEADYBIT_EXTENSION_UNIX_SOCKET=/run/steadybit/extension-prometheus.sock diff --git a/linuxpkg/config/steadybit/extensions.d/extension-prometheus.yaml b/linuxpkg/config/steadybit/extensions.d/extension-prometheus.yaml new file mode 100644 index 0000000..3885203 --- /dev/null +++ b/linuxpkg/config/steadybit/extensions.d/extension-prometheus.yaml @@ -0,0 +1,4 @@ +unixSocket: /run/steadybit/extension-prometheus.sock +types: + - ACTION + - DISCOVERY diff --git a/linuxpkg/init.d/steadybit-extension-prometheus b/linuxpkg/init.d/steadybit-extension-prometheus new file mode 100755 index 0000000..22cf8d3 --- /dev/null +++ b/linuxpkg/init.d/steadybit-extension-prometheus @@ -0,0 +1,99 @@ +#!/bin/sh +# +# Copyright 2024 steadybit GmbH. All rights reserved. +# + +### BEGIN INIT INFO +# Provides: steadybit-extension-prometheus +# Required-Start: $local_fs $network $named $time $syslog +# Required-Stop: $local_fs $network $named $time $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: Steadybit Extension Prometheus +# chkconfig: 2345 99 01 +### END INIT INFO + +SCRIPT=/opt/steadybit/extension-prometheus/extension-prometheus +RUNAS=steadybit + +PIDFILE=/var/run/steadybit-extension-prometheus.pid +LOGFILE=/var/log/steadybit-extension-prometheus.log +ENVFILE=/etc/steadybit/extension-prometheus + +start() { + if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then + echo 'Service already running' >&2 + return 1 + fi + echo 'Starting service...' >&2 + + if [ ! -e "$LOGFILE" ]; then + touch "$LOGFILE" + if [ -n "$RUNAS" ]; then + chown "$RUNAS" "$LOGFILE" + fi + fi + + if [ -f "$ENVFILE" ]; then + export $(grep -v "^#" "$ENVFILE" | xargs) + fi + + su -s /bin/sh -c "$SCRIPT > \"$LOGFILE\" 2>&1 & echo \$!" $RUNAS >"$PIDFILE" + PID=$(cat "$PIDFILE") + sleep 1 + + if [ -z "$PID" ] || ! kill -0 "$PID" 2>/dev/null; then + echo "Service failed to start" >&2 + tail -n 10 "$LOGFILE" + return 1 + fi + echo 'Service started' >&2 +} + +stop() { + if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then + echo 'Service not running' >&2 + return 1 + fi + echo 'Stopping service...' >&2 + kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE" + echo 'Service stopped' >&2 +} + +status() { + if [ ! -f "$PIDFILE" ]; then + echo 'Service not running'. >&2 + return 3 + fi + PID=$(cat "$PIDFILE") + if ! kill -0 "$PID" 2>/dev/null; then + echo "Service not running: process $PID not found." >&2 + return 1 + fi + + echo 'Service running'. >&2 + return 0 +} + +case "$1" in +start) + start + ;; +status) + status + ;; +stop) + stop + ;; +force-reload) + stop + start + ;; +restart) + stop + start + ;; +*) + echo "Usage: $0 {start|stop|status|restart}" + ;; +esac diff --git a/linuxpkg/scripts/postinstall.sh b/linuxpkg/scripts/postinstall.sh new file mode 100755 index 0000000..984b20b --- /dev/null +++ b/linuxpkg/scripts/postinstall.sh @@ -0,0 +1,85 @@ +#!/bin/sh -e + +# +# Copyright 2024 steadybit GmbH. All rights reserved. +# +service_name="steadybit-extension-prometheus" +env_file="/etc/steadybit/extension-prometheus" + +# decide if we should use SystemD or init/upstart +use_systemctl="True" +if ! command -V systemctl >/dev/null 2>&1; then + use_systemctl="False" +fi + +cleanup() { + # remove files that were not needed on this platform / system + if [ "${use_systemctl}" = "False" ]; then + rm -f "/usr/lib/systemd/system/$service_name.service" + else + rm -f "/etc/chkconfig/$service_name" + rm -f "/etc/init.d/$service_name" + fi +} + +cleanInstall() { + if [ -n "$STEADYBIT_LOG_LEVEL" ]; then + sed -i "s/^STEADYBIT_LOG_LEVEL=.*/STEADYBIT_LOG_LEVEL=$(echo "$STEADYBIT_LOG_LEVEL" | sed 's,/,\\/,g')/" "$env_file" + fi + + # enable the service in the proper way for this platform + if [ "${use_systemctl}" = "False" ]; then + if command -V chkconfig >/dev/null 2>&1; then + chkconfig --add "$service_name" + fi + + service "$service_name" restart || : + else + systemctl daemon-reload || : + systemctl unmask "$service_name" || : + systemctl preset "$service_name" || : + systemctl enable "$service_name" || : + systemctl restart "$service_name" || : + fi + +} + +upgrade() { + if [ "${use_systemctl}" = "False" ]; then + if service "$service_name" status 2>/dev/null; then + service "$service_name" restart || : + fi + else + systemctl daemon-reload + if systemctl is-active --quiet "$service_name"; then + systemctl restart "$service_name" || : + else + systemctl start "$service_name" || : + fi + fi +} + +#check if this is a clean install or an upgrade +action="$1" +if [ "$1" = "configure" ] && [ -z "$2" ]; then + # Alpine linux does not pass args, and deb passes $1=configure + action="install" +elif [ "$1" = "configure" ] && [ -n "$2" ]; then + # deb passes $1=configure $2= + action="upgrade" +fi + +case "$action" in +"1" | "install") + cleanInstall + ;; +"2" | "upgrade") + upgrade + ;; +*) + # $1 == version being installed on Alpine + cleanInstall + ;; +esac + +cleanup diff --git a/linuxpkg/scripts/postremove.sh b/linuxpkg/scripts/postremove.sh new file mode 100755 index 0000000..4196b33 --- /dev/null +++ b/linuxpkg/scripts/postremove.sh @@ -0,0 +1,49 @@ +#!/bin/sh -e + +# +# Copyright 2024 steadybit GmbH. All rights reserved. +# + +service_name="steadybit-extension-prometheus" +# decide if we should use SystemD or init/upstart +use_systemctl="True" +if ! command -V systemctl >/dev/null 2>&1; then + use_systemctl="False" +fi + +remove() { + if [ "${use_systemctl}" = "True" ]; then + systemctl mask "$service_name" || : + fi +} + +purge() { + if [ "${use_systemctl}" = "True" ]; then + if systemctl is-enabled --quiet "$service_name"; then + systemctl disable "$service_name" || : + fi + systemctl unmask "$service_name" || : + fi +} + +upgrade() { + : +} + +action="$1" + +case "$action" in +"0" | "purge") + purge + ;; +"remove") + remove + ;; +"1" | "upgrade") + upgrade + ;; +*) + # $1 == version being installed on Alpine + remove + ;; +esac diff --git a/linuxpkg/scripts/preinstall.sh b/linuxpkg/scripts/preinstall.sh new file mode 100755 index 0000000..9a187fb --- /dev/null +++ b/linuxpkg/scripts/preinstall.sh @@ -0,0 +1,11 @@ +#!/bin/sh -e + +# +# Copyright 2024 steadybit GmbH. All rights reserved. +# + +if ! getent passwd steadybit >/dev/null 2>&1; then + useradd --system steadybit + printf "created user: steadybit\n" +fi + diff --git a/linuxpkg/scripts/preremove.sh b/linuxpkg/scripts/preremove.sh new file mode 100755 index 0000000..1c0ec20 --- /dev/null +++ b/linuxpkg/scripts/preremove.sh @@ -0,0 +1,43 @@ +#!/bin/sh -e + +# +# Copyright 2024 steadybit GmbH. All rights reserved. +# + +service_name="steadybit-extension-prometheus" +# decide if we should use SystemD or init/upstart +use_systemctl="True" +if ! command -V systemctl >/dev/null 2>&1; then + use_systemctl="False" +fi + +remove() { + if [ "${use_systemctl}" = "False" ]; then + if service "$service_name" status 2>/dev/null; then + service "$service_name" stop || : + fi + else + if systemctl is-active --quiet "$service_name"; then + systemctl stop "$service_name" || : + fi + fi +} + +upgrade() { + : +} + +action="$1" + +case "$action" in +"0" | "remove") + remove + ;; +"1" | "upgrade") + upgrade + ;; +*) + # $1 == version being installed on Alpine + remove + ;; +esac diff --git a/linuxpkg/systemd/steadybit-extension-prometheus.service b/linuxpkg/systemd/steadybit-extension-prometheus.service new file mode 100644 index 0000000..cbdcf2e --- /dev/null +++ b/linuxpkg/systemd/steadybit-extension-prometheus.service @@ -0,0 +1,18 @@ +[Unit] +Description="steadybit extension prometheus" +After=syslog.target + +[Service] +Type=simple +ExecStart=/opt/steadybit/extension-prometheus/extension-prometheus +EnvironmentFile=/etc/steadybit/extension-prometheus +User=steadybit +Group=steadybit +SuccessExitStatus=0 143 +Restart=on-failure +RestartSec=5s +StandardOutput=append:/var/log/steadybit-extension-prometheus.log +StandardError=append:/var/log/steadybit-extension-prometheus.log + +[Install] +WantedBy=multi-user.target