rockstor / rockstor-rpmbuild

RPM build specifications used to create the distributed 'rockstor' package from rockstor-core and rockstor-jslibs GitHub releases.
GNU General Public License v3.0
2 stars 3 forks source link

(t) in wiping venv we need to restart all services #32

Closed phillxnet closed 1 year ago

phillxnet commented 1 year ago

Following our recent accommodation re venv python updating in-place via #31 brute force wipe, we are cutting our own python/django legs off. This leads to a requirement to command line reboot. We likely have refinement regarding our systemd service handling that can be approached to improve this user experience.

See:

https://github.com/rockstor/rockstor-rpmbuild/blob/7da0223b00ee74d4234c1e1a6bdfd589a773ebc1/rockstor.spec#L343-L345

phillxnet commented 1 year ago

It is further proposed that we re-examine our use of the %service* macros to help clarify exactly what happens when.

Their resulting raw scriptlet entries can be viewed in the resulting rpms via:

rpm -qi --scripts rockstor
phillxnet commented 1 year ago
rleap15-4:~ # rpm -qi --scripts rockstor
Name        : rockstor
Version     : 5.0.1
Release     : 0
Architecture: x86_64
Install Date: Mon 24 Jul 2023 20:10:33 WEST
Group       : Productivity/Networking/File-Sharing
Size        : 10054992
License     : GPL-3.0-or-later AND (MIT AND Apache-2.0 AND GPL-3.0-or-later AND LGPL-3.0-or-later AND ISC)
Signature   : RSA/SHA256, Mon 24 Jul 2023 20:10:15 WEST, Key ID 1c4262f25f043187
Source RPM  : rockstor-5.0.1-0.src.rpm
Build Date  : Mon 24 Jul 2023 20:10:07 WEST
Build Host  : rleap15-4.lan
Relocations : /opt 
Packager    : https://www.suse.com/
Vendor      : YewTreeApps
URL         : https://rockstor.com/
Summary     : Btrfs Network Attached Storage (NAS) Appliance.
Description :
Software raid, snapshot capable NAS solution with built-in file integrity protection.
Allows for file sharing between network attached devices.
Distribution: (none)
preinstall scriptlet (using /bin/sh):
# Before install/update
# $1 == 1 is before an install
# $1 == 2 is before an update
#
# Before we install, remove non-packaged rockstor legacy/development files:
rm --force /etc/systemd/system/rockstor*
systemctl daemon-reload
# remove legacy bin develop-eggs & eggs directories
rm --force /opt/rockstor/bin
rm --force /opt/rockstor/develop-eggs
rm --force /opt/rockstor/eggs
# https://en.opensuse.org/openSUSE:Systemd_packaging_guidelines#Unit_files
# See: /usr/lib/rpm/macros.d/macros.systemd from systemd-rpm-macros
# rpm --eval macro-name-here

if [ -x /usr/bin/systemctl ]; then
        test -n "$FIRST_ARG" || FIRST_ARG="$1"
        [ -d /var/lib/systemd/migrated ] || mkdir -p /var/lib/systemd/migrated || :

        for service in rockstor-pre.service rockstor.service rockstor-bootstrap.service ; do
                sysv_service=${service%.*}

                if [ ! -e /usr/lib/systemd/system/$service ] &&
                   [ ! -e /etc/init.d/$sysv_service ]; then
                        mkdir -p /run/systemd/rpm/needs-preset
                        touch /run/systemd/rpm/needs-preset/$service

                elif [ -e /etc/init.d/$sysv_service ] &&
                     [ ! -e /var/lib/systemd/migrated/$sysv_service ]; then
                        /usr/sbin/systemd-sysv-convert --save $sysv_service || :
                        mkdir -p /run/systemd/rpm/needs-sysv-convert
                        touch /run/systemd/rpm/needs-sysv-convert/$service
                fi
        done
fi

exit 0
postinstall scriptlet (using /bin/sh):
# After install/update
# $1 == 1 is after an install
# $1 == 2 is after an update
#
if [ "$1" = "2" ]; then  # update
    # Remove jslibs dir so build.sh (posttrans) will refresh from new rpm rockstor-jslibs.tar.gz
    rm -rf /opt/rockstor/jslibs
    # Remove collectstatic generated static dir as build.sh (posttrans) will regenerate.
    rm -rf /opt/rockstor/static
    # Remove our prior versions .venv dir as build.sh (posttrans) will regenerate.
    rm -rf /opt/rockstor/.venv
fi

if [ -x /usr/bin/systemctl ]; then
        test -n "$FIRST_ARG" || FIRST_ARG="$1"
        [ -d /var/lib/systemd/migrated ] || mkdir -p /var/lib/systemd/migrated || :

        if [ "$YAST_IS_RUNNING" != "instsys" ]; then
                /usr/bin/systemctl daemon-reload || :
        fi
        for service in rockstor-pre.service rockstor.service rockstor-bootstrap.service ; do
                sysv_service=${service%.*}

                if [ -e /run/systemd/rpm/needs-preset/$service ]; then
                        /usr/bin/systemctl preset $service || :
                        rm "/run/systemd/rpm/needs-preset/$service" || :

                elif [ -e /run/systemd/rpm/needs-sysv-convert/$service ]; then
                        /usr/sbin/systemd-sysv-convert --apply $sysv_service || :
                        rm "/run/systemd/rpm/needs-sysv-convert/$service" || :
                        touch /var/lib/systemd/migrated/$sysv_service || :
                fi
        done
fi

exit 0
preuninstall scriptlet (using /bin/sh):
# Before uninstall/update
# $1 == 0 is before an uninstall
# $1 == 1 is before an update
#

test -n "$FIRST_ARG" || FIRST_ARG="$1"
if [ "$FIRST_ARG" -eq 0 -a -x /usr/bin/systemctl ]; then
        # Package removal, not upgrade
        /usr/bin/systemctl --no-reload disable rockstor-pre.service rockstor.service rockstor-bootstrap.service || :
        (
                test "$YAST_IS_RUNNING" = instsys && exit 0
                test -f /etc/sysconfig/services -a \
                     -z "$DISABLE_STOP_ON_REMOVAL" && . /etc/sysconfig/services
                test "$DISABLE_STOP_ON_REMOVAL" = yes -o \
                     "$DISABLE_STOP_ON_REMOVAL" = 1 && exit 0
                /usr/bin/systemctl stop rockstor-pre.service rockstor.service rockstor-bootstrap.service
        ) || : 
fi

exit 0
postuninstall scriptlet (using /bin/sh):
#After uninstall/update
# $1 == 0 is after an uninstall
# $1 == 1 is after an update
#
# During package update, % service_del_postun restarts units.
# If units are not to be restarted, % service_del_postun_without_restart should be used instead.

if [ $1 -eq 0 ]; then
        # Package removal
        for service in rockstor-pre.service rockstor.service rockstor-bootstrap.service ; do
                sysv_service="${service%.*}"
                rm -f "/var/lib/systemd/migrated/$sysv_service" || :
        done
fi
if [ -x /usr/bin/systemctl ]; then
        /usr/bin/systemctl daemon-reload || :
fi

# We need to restart the nginx service as we removed our nginx override file.
if [ "$1" = "0" ]; then  # uninstall so clean up build.sh generated files and other dynamic files.
    systemctl restart nginx
    # Remove jslibs directory from rockstor-jslibs.tar.gz
    rm -rf /opt/rockstor/jslibs
    # remove collectstatic generated static dir
    rm -rf /opt/rockstor/static
    # remove Poetry installed .venv directory.
    rm -rf /opt/rockstor/.venv
    # remove poetry-install.txt
    rm -rf /opt/rockstor/poetry-install.txt
    # remove all pyc files (Python interpreter generated)
    find /opt/rockstor/src -name '*.pyc' -delete
    # remove all empty directories
    find /opt/rockstor/src -type d -empty -delete
    # remove Huey db file:
    rm /opt/rockstor/rockstor-tasks-huey.db
    # remove top level directory but only if empty
    rmdir /opt/rockstor
fi
exit 0
posttrans scriptlet (using /bin/sh):
# From: https://en.opensuse.org/openSUSE:Packaging_scriptlet_snippets
# the posttrans scriptlet is available form rpm version 4.4 onwards.
#
# Last scriptlet to execute from old or new package versions.
# Executed from new package version during install & upgrade similarly.
#
# Run build.sh
# 1. Install poerty to system.
# 2. Use it to populate/refresh .venv.
# 3. if no jslibs dir exists:
#        un-tar rockstor-jslibs.tar.gz
# 4. Regenerate static dir via collectstatic.
#
# We have a minimal path available so add system poetry explicitly.
PATH="$HOME/.local/bin:$PATH"
export LANG=C.UTF-8
cd /opt/rockstor
./build.sh
exit 0

# remove and reformat to rockstor.changes file as per:
# https://en.opensuse.org/openSUSE:Creating_a_changes_file_(RPM)
# https://github.com/openSUSE/obs-build/blob/master/changelog2spec
phillxnet commented 1 year ago

Proposed functional change is last line before "exit 0" in below excerpt of %posttrans

posttrans scriptlet (using /bin/sh):
---
cd /opt/rockstor
./build.sh
# We start/re-start our top-level systemd service,
# enabled already via systemd-presets-branding-rockstor - if installed.
# Required to enable/re-enable our Web-UI on install/update (.venv rebuild)
systemctl start rockstor-bootstrap.service
exit 0

It is not normally recommended that an rpm scriptlet starts a service that it has just installed. But in this case, if we have an existing running service, this is a null operation. But if we have a failed prior install - i.e. due to Poetry venv build issues, the single step of updating the rpm form the command line can re-establish Web-UI access.

We are also only starting our own service post rpm transaction. So the rpm install is essentically over - and we are doing our initial setup/update via build.sh to manage jslibs and venv assertion.

phillxnet commented 1 year ago

The proposal in the last comment may not be appropriate re rpm guidelines and likely not required if our advised, and pre-installed in our installers OBS package is in place. I have been unable to reproduce this issue when using a rockstor installer base - where systemd-presets-branding-rockstor enables rockstor-bootstrap by default.

# system with soft dependency of systemd-presets-branding-rockstor installed:
zypper --non-interactive remove rockstor
rm -rf /opt/rockstor/
zypper --non-interactive in rockstor-4.6.1-0
reboot

Visit Web-UI

  1. setup
  2. subscript to testing
  3. update via Web-UI to 5.0.1.-0 (lastest in testing). In doing so we move from a Py2.7 (master branch) to a Py3.6 (testing branch) venv, and 5.0.1-0 via venv delete addition in: #31 wipes first.

Web-UI is available under the new Py3.6 venv post our web-timer of 5 minutes - complete with updated 5.0.1-0 indicator.

phillxnet commented 1 year ago

Closing as no clear reproducer and so we have no proof of fix