Skip to content

Commit

Permalink
CBG-4293 recognize alma/rocky and other rhel variants
Browse files Browse the repository at this point in the history
  • Loading branch information
torcolvin committed Oct 9, 2024
1 parent defcbec commit f4d334a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 138 deletions.
68 changes: 17 additions & 51 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 systemd or launchctl 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 All @@ -47,23 +47,17 @@ usage() {
}

ostype() {
if [ -x "$(command -v lsb_release)" ]; then
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/os-release ]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$(echo "${ID}")
if [ "${OS}" = "debian" ]; then
VER=$(cat /etc/debian_version)
if [ "${ID_LIKE##*rhel*}" != "${ID_LIKE}" ]; then
OS=rhel
else
VER=$VERSION_ID
OS=$(echo "${ID}")
fi
elif [ -f /etc/redhat-release ]; then
OS=rhel
VER=$(cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//)
elif [ -f /etc/system-release ]; then
OS=rhel
VER=5.0
VER=${VERSION_ID}
elif [ -x "$(command -v lsb_release)" ]; then
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
else
OS=$(uname -s)
VER=$(uname -r)
Expand Down Expand Up @@ -242,43 +236,15 @@ ubuntu)
;;
esac
;;
redhat* | rhel* | centos | ol)
case 1:${OS_MAJOR_VERSION:--} in
$((OS_MAJOR_VERSION >= 7))*)
if [ "$SERVICE_CMD_ONLY" = true ]; then
echo "systemctl start ${SERVICE_NAME}"
else
pre_install_actions
render_template script_templates/systemd_sync_gateway.tpl >/usr/lib/systemd/system/${SERVICE_NAME}.service
systemctl enable ${SERVICE_NAME}
systemctl start ${SERVICE_NAME}
fi
;;
*)
echo "ERROR: Unsupported RedHat/CentOS Version \"$VER\""
usage
exit 1
;;
esac
;;
amzn*)
case 1:${OS_MAJOR_VERSION:--} in
$((OS_MAJOR_VERSION >= 2))*)
rhel) # RHEL, Alma, Rocky, Amazon Linux and any derivatives
if [ "$SERVICE_CMD_ONLY" = true ]; then
echo "systemctl start ${SERVICE_NAME}"
else
pre_install_actions
render_template script_templates/systemd_sync_gateway.tpl >/usr/lib/systemd/system/${SERVICE_NAME}.service
systemctl enable ${SERVICE_NAME}
systemctl start ${SERVICE_NAME}
fi
;;
*)
echo "ERROR: Unsupported Amazon Linux Version \"$VER\""
usage
exit 1
;;
esac
echo "systemctl start ${SERVICE_NAME}"
else
pre_install_actions
render_template script_templates/systemd_sync_gateway.tpl >/usr/lib/systemd/system/${SERVICE_NAME}.service
systemctl enable ${SERVICE_NAME}
systemctl start ${SERVICE_NAME}
fi
;;
darwin)
if [ "$SERVICE_CMD_ONLY" = true ]; then
Expand Down
62 changes: 15 additions & 47 deletions service/sync_gateway_service_uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,21 @@ 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 systemd or launchctl service to run a sync_gateway instance."
}

ostype() {
if [ -x "$(command -v lsb_release)" ]; then
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/os-release ]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$(echo "${ID}")
if [ "${OS}" = "debian" ]; then
VER=$(cat /etc/debian_version)
if [ "${ID_LIKE##*rhel*}" != "${ID_LIKE}" ]; then
OS=rhel
else
VER=$VERSION_ID
OS=$(echo "${ID}")
fi
elif [ -f /etc/redhat-release ]; then
OS=rhel
VER=$(cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//)
elif [ -f /etc/system-release ]; then
OS=rhel
VER=5.0
VER=${VERSION_ID}
elif [ -x "$(command -v lsb_release)" ]; then
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
else
OS=$(uname -s)
VER=$(uname -r)
Expand Down Expand Up @@ -120,39 +114,13 @@ ubuntu)
;;
esac
;;
redhat* | rhel* | centos | ol)
case 1:${OS_MAJOR_VERSION:--} in
$((OS_MAJOR_VERSION >= 7))*)
systemctl stop ${SERVICE_NAME}
systemctl disable ${SERVICE_NAME}
rhel) # RHEL, Alma, Rocky, Amazon Linux and any derivatives
systemctl stop ${SERVICE_NAME}
systemctl disable ${SERVICE_NAME}

if [ -f /usr/lib/systemd/system/${SERVICE_NAME}.service ]; then
rm /usr/lib/systemd/system/${SERVICE_NAME}.service
fi
;;
*)
echo "ERROR: Unsupported RedHat/CentOS Version \"$VER\""
usage
exit 1
;;
esac
;;
amzn*)
case 1:${OS_MAJOR_VERSION:--} in
$((OS_MAJOR_VERSION >= 2))*)
systemctl stop ${SERVICE_NAME}
systemctl disable ${SERVICE_NAME}

if [ -f /lib/systemd/system/${SERVICE_NAME}.service ]; then
rm /lib/systemd/system/${SERVICE_NAME}.service
fi
;;
*)
echo "ERROR: Unsupported Amazon Linux Version \"$VER\""
usage
exit 1
;;
esac
if [ -f /usr/lib/systemd/system/${SERVICE_NAME}.service ]; then
rm /usr/lib/systemd/system/${SERVICE_NAME}.service
fi
;;
darwin)
launchctl unload /Library/LaunchDaemons/com.couchbase.mobile.sync_gateway.plist
Expand Down
52 changes: 12 additions & 40 deletions service/sync_gateway_service_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,21 @@ 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 systemd or launchctl service to run a sync_gateway instance."
}

ostype() {
if [ -x "$(command -v lsb_release)" ]; then
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/os-release ]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$(echo "${ID}")
if [ "${OS}" = "debian" ]; then
VER=$(cat /etc/debian_version)
if [ "${ID_LIKE##*rhel*}" != "${ID_LIKE}" ]; then
OS=rhel
else
VER=$VERSION_ID
OS=$(echo "${ID}")
fi
elif [ -f /etc/redhat-release ]; then
OS=rhel
VER=$(cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//)
elif [ -f /etc/system-release ]; then
OS=rhel
VER=5.0
VER=${VERSION_ID}
elif [ -x "$(command -v lsb_release)" ]; then
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
else
OS=$(uname -s)
VER=$(uname -r)
Expand Down Expand Up @@ -110,31 +104,9 @@ ubuntu)
;;
esac
;;
redhat* | rhel* | centos | ol)
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\""
usage
exit 1
;;
esac
;;
amzn*)
case 1:${OS_MAJOR_VERSION:--} in
$((OS_MAJOR_VERSION >= 2))*)
systemctl stop ${SERVICE_NAME}
systemctl start ${SERVICE_NAME}
;;
*)
echo "ERROR: Unsupported Amazon Linux Version \"$VER\""
usage
exit 1
;;
esac
rhel) # RHEL, Alma, Rocky, Amazon Linux and any derivatives
systemctl stop ${SERVICE_NAME}
systemctl start ${SERVICE_NAME}
;;
darwin)
launchctl unload /Library/LaunchDaemons/com.couchbase.mobile.sync_gateway.plist
Expand Down

0 comments on commit f4d334a

Please sign in to comment.