From ea33d12bb44787cf74f9d9fbacdc7403a65e4c24 Mon Sep 17 00:00:00 2001 From: Stanley Chan Date: Fri, 5 Aug 2022 12:47:49 -0700 Subject: [PATCH] cleanup(scripts): cleanup systemd unit in RPM installer Signed-off-by: Stanley Chan --- scripts/rpm/postinstall.in | 33 +++++++++++++++++++++++++++++++++ scripts/rpm/postuninstall.in | 17 +++++++++++++++++ scripts/rpm/preuninstall.in | 16 ++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/scripts/rpm/postinstall.in b/scripts/rpm/postinstall.in index aff76762748..4848efcdd47 100755 --- a/scripts/rpm/postinstall.in +++ b/scripts/rpm/postinstall.in @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +set -e mod_version="@DRIVER_VERSION@" dkms add -m falco -v $mod_version --rpm_safe_upgrade @@ -29,3 +30,35 @@ else echo -e "Module build for the currently running kernel was skipped since the" echo -e "kernel source for this kernel does not seem to be installed." fi + +# validate rpm macros by `rpm -qp --scripts ` +# RPM scriptlets: https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_systemd +# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax + +# systemd_post macro expands to +# if postinst: +# `systemd-update-helper install-system-units ` +%systemd_post 'falco.service' + +# post install mirrored from .deb +if [ $1 -eq 1 ]; then + # This will only remove masks created on package removal. + /usr/bin/systemctl --system unmask 'falco.service' >/dev/null || true + + # enable falco on installation + # note: DEB postinstall script checks for changed symlinks + /usr/bin/systemctl --system enable 'falco.service' >/dev/null || true + + # start falco on installation + /usr/bin/systemctl --system start 'falco.service' >/dev/null || true +fi + +# post upgrade mirrored from .deb +if [ $1 -gt 1 ]; then + if [ -d /run/systemd/system ]; then + /usr/bin/systemctl --system daemon-reload >/dev/null || true + + # restart falco on upgrade if service is already running + /usr/bin/systemctl --system condrestart 'falco.service' >/dev/null || true + fi +fi diff --git a/scripts/rpm/postuninstall.in b/scripts/rpm/postuninstall.in index 87526372199..8fd9b6924ba 100755 --- a/scripts/rpm/postuninstall.in +++ b/scripts/rpm/postuninstall.in @@ -14,3 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # + +set -e + +# post uninstall mirrored from .deb +if [ -d /run/systemd/system ] && [ "$1" = 0 ]; then + /usr/bin/systemctl --system daemon-reload >/dev/null || true + /usr/bin/systemctl --system mask 'falco.service' >/dev/null || true +fi + +# validate rpm macros by `rpm -qp --scripts ` +# RPM scriptlets: https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_systemd +# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax + +# systemd_postun_with_restart macro expands to +# if package upgrade, not uninstall: +# `systemd-update-helper mark-restart-system-units ` +%systemd_postun_with_restart 'falco.service' diff --git a/scripts/rpm/preuninstall.in b/scripts/rpm/preuninstall.in index fb9b4e5e428..a8fe6120db7 100755 --- a/scripts/rpm/preuninstall.in +++ b/scripts/rpm/preuninstall.in @@ -14,5 +14,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # +set -e /usr/bin/falco-driver-loader --clean + +# pre uninstall mirrored from .deb +if [ -d /run/systemd/system ] && [ $1 -eq 0 ]; then + # stop falco service before uninstall + /usr/bin/systemctl --system stop 'falco.service' >/dev/null || true +fi + +# validate rpm macros by `rpm -qp --scripts ` +# RPM scriptlets: https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_systemd +# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax + +# systemd_preun macro expands to +# if preuninstall: +# `systemd-update-helper remove-system-units ` +%systemd_preun 'falco.service'