From b3a408aa4e5076dd51d8e3dce4b3feac2616cfb5 Mon Sep 17 00:00:00 2001 From: Julio Martinez Date: Thu, 10 Nov 2022 11:13:06 -0800 Subject: [PATCH] Packaging improvements to improve mcloud updates (#2288) * Update package scripts so they restart services based on the operation (update vs install) Co-authored-by: Julio Martinez (cherry picked from commit e25e395bab57bfc290f03b455fcc953722da876c) --- install/postinstall.sh | 45 ++++++++++++++++++++++++++++++++++++++++-- install/postremove.sh | 34 +++++++++++++++++++++++++++++++ install/preinstall.sh | 44 ++++++++++++++++++++++++++++++++++++----- install/preremove.sh | 2 -- nfpm.yaml | 1 - 5 files changed, 116 insertions(+), 10 deletions(-) mode change 100644 => 100755 install/postinstall.sh create mode 100755 install/postremove.sh delete mode 100755 install/preremove.sh diff --git a/install/postinstall.sh b/install/postinstall.sh old mode 100644 new mode 100755 index d50279ee9..1f80d2be6 --- a/install/postinstall.sh +++ b/install/postinstall.sh @@ -1,2 +1,43 @@ -systemctl enable featurebase -systemctl start featurebase +#!/bin/sh + +cleanInstall() { + printf "\033[32m Reload the service unit from disk\033[0m\n" + systemctl daemon-reload ||: + printf "\033[32m Enable featurebase service\033[0m\n" + systemctl enable featurebase ||: +} + +upgrade() { + printf "\033[32m Reload the service unit from disk\033[0m\n" + systemctl daemon-reload ||: + + printf "\033[32m Enabling featurebase after upgrade\033[0m\n" + systemctl enable featurebase ||: + + printf "\033[32m Starting featurebase after upgrade\033[0m\n" + systemctl start featurebase ||: +} + +# Step 2, 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 + printf "\033[32m Alpine\033[0m" + cleanInstall + ;; +esac diff --git a/install/postremove.sh b/install/postremove.sh new file mode 100755 index 000000000..0785bd4ac --- /dev/null +++ b/install/postremove.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +remove() { + printf "\033[32m Post Remove of a normal remove\033[0m\n" + echo "Remove" > /tmp/postremove-proof +} + +purge() { + printf "\033[32m Post Remove purge, deb only\033[0m\n" + echo "Purge" > /tmp/postremove-proof +} + +upgrade() { + printf "\033[32m Post Remove of an upgrade\033[0m\n" + echo "Upgrade" > /tmp/postremove-proof +} + +action="$1" + +case "$action" in + "0" | "remove") + remove + ;; + "1" | "upgrade") + upgrade + ;; + "purge") + purge + ;; + *) + printf "\033[32m Alpine\033[0m" + remove + ;; +esac diff --git a/install/preinstall.sh b/install/preinstall.sh index 4f2e141cc..f2cce7b44 100755 --- a/install/preinstall.sh +++ b/install/preinstall.sh @@ -4,9 +4,43 @@ USERNAME=featurebase GROUPNAME=featurebase HOMEDIR=/var/lib/featurebase -getent group $GROUPNAME >/dev/null || groupadd -r $GROUPNAME -getent passwd $USERNAME >/dev/null || \ - useradd -r -g $GROUPNAME -d $HOMEDIR -s /sbin/nologin \ - -c "Featurebase Service Account" $USERNAME +cleanInstall() { + printf "\033[32m Adding featurebase user\033[0m\n" -exit 0 + getent group $GROUPNAME >/dev/null || groupadd -r $GROUPNAME + getent passwd $USERNAME >/dev/null || \ + useradd -r -g $GROUPNAME -d $HOMEDIR -s /sbin/nologin \ + -c "Featurebase Service Account" $USERNAME +} + +upgrade() { + printf "\033[32m Stopping featurebase service before upgrade\033[0m\n" + systemctl stop featurebase ||: + + printf "\033[32m Disabling featurebase service before upgrade\033[0m\n" + systemctl disable featurebase ||: +} + +# Step 2, 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 + printf "\033[32m Alpine\033[0m" + cleanInstall + ;; +esac diff --git a/install/preremove.sh b/install/preremove.sh deleted file mode 100755 index 0b9a0ea43..000000000 --- a/install/preremove.sh +++ /dev/null @@ -1,2 +0,0 @@ -systemctl stop featurebase -systemctl disable featurebase diff --git a/nfpm.yaml b/nfpm.yaml index d21291353..2c0c4d254 100644 --- a/nfpm.yaml +++ b/nfpm.yaml @@ -44,4 +44,3 @@ contents: scripts: preinstall: ./install/preinstall.sh postinstall: ./install/postinstall.sh - preremove: ./install/preremove.sh