Skip to content

Commit

Permalink
[3.2.1 backport] CBG-4294 recognize alma/rocky linux
Browse files Browse the repository at this point in the history
backports CBG-4293 recognize alma/rocky and other rhel variants (#7150)
  • Loading branch information
torcolvin committed Oct 14, 2024
1 parent 8d0bb46 commit 5412479
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 9 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2022-Present Couchbase, Inc.
#
# Use of this software is governed by the Business Source License included in
# the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that
# file, in accordance with the Business Source License, use of this software
# will be governed by the Apache License, Version 2.0, included in the file
# licenses/APL2.txt.

name: service

on:
push:
# Only run when we modify service files
paths:
- 'service/**'
- 'integration-test/**'
branches:
- 'main'
- 'release/*'
- 'feature/*'
- 'beryllium'
- 'CBG*'
- 'ci-*'
- 'api-ci-*'
pull_request:
# Only run when we modify service files
paths:
- 'service/**'
- 'integration-test/**'
branches:
- 'main'
- 'release/*'

jobs:
scripts:
runs-on: ubuntu-latest
name: Verify service script installation.
steps:
- uses: actions/checkout@v4
# build sync gateway since the executable is needed for service installation
- uses: actions/setup-go@v5
with:
go-version: 1.22.5
- name: "Build Sync Gateway"
run: mkdir -p ./bin && go build -o ./bin ./...
- name: "Run test scripts"
run: ./integration-test/service-install-tests.sh
42 changes: 42 additions & 0 deletions integration-test/service-install-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# Copyright 2024-Present Couchbase, Inc.
#
# Use of this software is governed by the Business Source License included
# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
# in that file, in accordance with the Business Source License, use of this
# software will be governed by the Apache License, Version 2.0, included in
# the file licenses/APL2.txt.

# This file is used by github CI or locally and runs a subset of test scripts to validate the service installation done by the package managers. This is intended to be run from Linux or Mac.

set -eux -o pipefail

IMAGES=(
"almalinux:9"
"amazonlinux:2"
"amazonlinux:2023"
"debian:10"
"debian:11"
"debian:12"
"redhat/ubi8"
"redhat/ubi9"
"rockylinux:9"
"ubuntu:20.04"
"ubuntu:22.04"
"ubuntu:24.04"

# not technically supported
"oraclelinux:9"
)

SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
SYNC_GATEWAY_DIR=$(realpath ${SCRIPT_DIR}/..)

if [ "$(uname)" == "Darwin" ]; then
sudo ${SYNC_GATEWAY_DIR}/integration-test/service-test.sh
fi

for IMAGE in "${IMAGES[@]}"; do
echo "Running tests for ${IMAGE}"
docker run --mount src=${SYNC_GATEWAY_DIR},target=/sync_gateway,type=bind ${IMAGE} /bin/bash -c "/sync_gateway/integration-test/service-test.sh"
done
70 changes: 70 additions & 0 deletions integration-test/service-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#/bin/sh

# Copyright 2024-Present Couchbase, Inc.
#
# Use of this software is governed by the Business Source License included
# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
# in that file, in accordance with the Business Source License, use of this
# software will be governed by the Apache License, Version 2.0, included in
# the file licenses/APL2.txt.

# This code is intneded to be run from within a docker container of a specific platform and runs a subset of the service scripts. The full service can not be validated since systemd does not work in docker contains. This is intended to run in /bin/sh to test dash environments on debian systems.

set -eux -o pipefail

SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")

cd ${SCRIPT_DIR}/../service

./sync_gateway_service_install.sh --servicecmd

# /etc/os-release doesn't exist on Darwin
if [ -f /etc/os-release ]; then
. /etc/os-release
case ${ID} in
amzn)
yum install -y shadow-utils systemd
;;
esac

groupadd -r sync_gateway
useradd -g sync_gateway sync_gateway

# bash would support export -f for a systemctl wrapper, but dash does not support exporting aliases or functions

mkdir -p /tmp/systemctl_wrapper

cat << 'EOF' > /tmp/systemctl_wrapper/systemctl
#!/bin/bash
set -eu -o pipefail
case ${1:-} in
start)
echo "No-op systemctl start in docker, since we're not running systemd"
;;
stop)
echo "No-op systemctl stop in docker, since we're not running systemd"
;;
*)
echo "Running systemctl $@"
command /usr/bin/systemctl "$@"
;;
esac
EOF

chmod +x /tmp/systemctl_wrapper/systemctl

export PATH=/tmp/systemctl_wrapper:$PATH
fi

./sync_gateway_service_install.sh
./sync_gateway_service_upgrade.sh
./sync_gateway_service_uninstall.sh

# test again with runas option
./sync_gateway_service_install.sh --runas=root
./sync_gateway_service_upgrade.sh
./sync_gateway_service_uninstall.sh

echo "Successful service test"
6 changes: 3 additions & 3 deletions service/sync_gateway_service_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LOGS_TEMPLATE_VAR=${RUNBASE_TEMPLATE_VAR}/logs
SERVICE_CMD_ONLY=false

usage() {
echo "This script creates an init service to run a sync_gateway instance."
echo "This script creates a service to run a sync_gateway instance."
echo "If you want to install more than one service instance"
echo "create additional services with different names."
echo ""
Expand Down Expand Up @@ -242,7 +242,7 @@ ubuntu)
;;
esac
;;
redhat* | rhel* | centos | ol)
redhat* | rhel* | centos | ol | rocky | almalinux )
case 1:${OS_MAJOR_VERSION:--} in
$((OS_MAJOR_VERSION >= 7))*)
if [ "$SERVICE_CMD_ONLY" = true ]; then
Expand All @@ -255,7 +255,7 @@ redhat* | rhel* | centos | ol)
fi
;;
*)
echo "ERROR: Unsupported RedHat/CentOS Version \"$VER\""
echo "ERROR: Unsupported RedHat/CentOS/Rocky/Alma Version \"$VER\""
usage
exit 1
;;
Expand Down
6 changes: 3 additions & 3 deletions service/sync_gateway_service_uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LOGS_TEMPLATE_VAR=${RUNBASE_TEMPLATE_VAR}/logs
SERVICE_CMD_ONLY=false

usage() {
echo "This script removes an init service to run a sync_gateway instance."
echo "This script removes a service to run a sync_gateway instance."
}

ostype() {
Expand Down Expand Up @@ -120,7 +120,7 @@ ubuntu)
;;
esac
;;
redhat* | rhel* | centos | ol)
redhat* | rhel* | centos | ol | rocky | almalinux )
case 1:${OS_MAJOR_VERSION:--} in
$((OS_MAJOR_VERSION >= 7))*)
systemctl stop ${SERVICE_NAME}
Expand All @@ -131,7 +131,7 @@ redhat* | rhel* | centos | ol)
fi
;;
*)
echo "ERROR: Unsupported RedHat/CentOS Version \"$VER\""
echo "ERROR: Unsupported RedHat/CentOS/Rocky/Alma Version \"$VER\""
usage
exit 1
;;
Expand Down
6 changes: 3 additions & 3 deletions service/sync_gateway_service_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LOGS_TEMPLATE_VAR=${RUNBASE_TEMPLATE_VAR}/logs
SERVICE_CMD_ONLY=false

usage() {
echo "This script upgrades an init service to run a sync_gateway instance."
echo "This script upgrades a service to run a sync_gateway instance."
}

ostype() {
Expand Down Expand Up @@ -110,14 +110,14 @@ ubuntu)
;;
esac
;;
redhat* | rhel* | centos | ol)
redhat* | rhel* | centos | ol | rocky | almalinux )
case 1:${OS_MAJOR_VERSION:--} in
$((OS_MAJOR_VERSION >= 7))*)
systemctl stop ${SERVICE_NAME}
systemctl start ${SERVICE_NAME}
;;
*)
echo "ERROR: Unsupported RedHat/CentOS Version \"$VER\""
echo "ERROR: Unsupported RedHat/CentOS/Rocky/Alma Version \"$VER\""
usage
exit 1
;;
Expand Down

0 comments on commit 5412479

Please sign in to comment.