Skip to content

Commit

Permalink
cleanup(scripts): cleanup systemd unit in RPM installer
Browse files Browse the repository at this point in the history
Signed-off-by: Stanley Chan <[email protected]>
  • Loading branch information
happy-dude committed Aug 6, 2022
1 parent e85ac8c commit ea33d12
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions scripts/rpm/postinstall.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>`
# 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 <service>`
%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
17 changes: 17 additions & 0 deletions scripts/rpm/postuninstall.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
# 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 <service>`
%systemd_postun_with_restart 'falco.service'
16 changes: 16 additions & 0 deletions scripts/rpm/preuninstall.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
# 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 <service>`
%systemd_preun 'falco.service'

0 comments on commit ea33d12

Please sign in to comment.