diff options
Diffstat (limited to 'packaging')
| -rwxr-xr-x | packaging/deb/meshbay-common/DEBIAN/preinst | 14 | ||||
| -rwxr-xr-x | packaging/deb/meshbay-common/DEBIAN/prerm | 13 | ||||
| -rw-r--r-- | packaging/deb/meshbay-node/DEBIAN/postinst | 21 | ||||
| -rw-r--r-- | packaging/rpm/meshbay-common.spec | 14 | ||||
| -rw-r--r-- | packaging/rpm/meshbay-node.spec | 34 |
5 files changed, 95 insertions, 1 deletions
diff --git a/packaging/deb/meshbay-common/DEBIAN/preinst b/packaging/deb/meshbay-common/DEBIAN/preinst new file mode 100755 index 0000000..16af2f8 --- /dev/null +++ b/packaging/deb/meshbay-common/DEBIAN/preinst @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +# The postinst compiles bytecode next to every module, into __pycache__ +# directories the package does not own. Left in place, they keep dpkg from +# removing a directory the new version no longer ships, and it warns. +case "$1" in + upgrade) + find /opt/meshbay-common/venv -depth -type d -name __pycache__ \ + -exec rm -rf {} + 2>/dev/null || true + ;; +esac + +#DEBHELPER# diff --git a/packaging/deb/meshbay-common/DEBIAN/prerm b/packaging/deb/meshbay-common/DEBIAN/prerm new file mode 100755 index 0000000..e7b665b --- /dev/null +++ b/packaging/deb/meshbay-common/DEBIAN/prerm @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + +# Bytecode the postinst compiled is not the package's: removed here, so that +# dpkg can remove the directories it was written into. +case "$1" in + remove|upgrade|deconfigure) + find /opt/meshbay-common/venv -depth -type d -name __pycache__ \ + -exec rm -rf {} + 2>/dev/null || true + ;; +esac + +#DEBHELPER# diff --git a/packaging/deb/meshbay-node/DEBIAN/postinst b/packaging/deb/meshbay-node/DEBIAN/postinst index ba16633..f78cf6c 100644 --- a/packaging/deb/meshbay-node/DEBIAN/postinst +++ b/packaging/deb/meshbay-node/DEBIAN/postinst @@ -1,11 +1,30 @@ #!/bin/sh set -e +# The node runs as a user service, in every signed-in user's own systemd +# manager: the system-wide reload does not reach those, and each would keep +# the old unit and the old code until restarted by hand. Every running user +# manager reloads, and restarts the node where it was running. +reload_user_managers() { + for bus in /run/user/*/systemd/private; do + [ -S "$bus" ] || continue + uid=$(basename "$(dirname "$(dirname "$bus")")") + user=$(id -nu "$uid" 2>/dev/null) || continue + systemctl --user -M "$user@" daemon-reload 2>/dev/null || true + [ -n "$1" ] && systemctl --user -M "$user@" try-restart meshbay-node.service 2>/dev/null || true + done +} + case "$1" in configure) - # Reload systemd if available if [ -d /run/systemd/system ]; then systemctl daemon-reload || true + # $2 is the version replaced: on an upgrade, a running node + # restarts onto the new code. + if [ -n "$2" ]; then + systemctl try-restart 'meshbay-node@*.service' 2>/dev/null || true + fi + reload_user_managers "$2" fi ;; esac diff --git a/packaging/rpm/meshbay-common.spec b/packaging/rpm/meshbay-common.spec index 948de9a..147dc17 100644 --- a/packaging/rpm/meshbay-common.spec +++ b/packaging/rpm/meshbay-common.spec @@ -17,6 +17,20 @@ Installs to /opt/meshbay-common/venv/. %install cp -a %{_staging_root}/* %{buildroot}/ +# Bytecode written at run time into __pycache__ is not the package's, and would +# keep rpm from removing a directory the new version no longer ships. +%pre +if [ "$1" -ge 2 ]; then + find /opt/meshbay-common/venv -depth -type d -name __pycache__ \ + -exec rm -rf {} + 2>/dev/null || true +fi + +%preun +if [ "$1" -eq 0 ]; then + find /opt/meshbay-common/venv -depth -type d -name __pycache__ \ + -exec rm -rf {} + 2>/dev/null || true +fi + %files /opt/meshbay-common diff --git a/packaging/rpm/meshbay-node.spec b/packaging/rpm/meshbay-node.spec index 1ba7f26..9b9c6bf 100644 --- a/packaging/rpm/meshbay-node.spec +++ b/packaging/rpm/meshbay-node.spec @@ -35,6 +35,40 @@ if [ -d /run/systemd/system ]; then systemctl daemon-reload || true fi +# After the whole transaction, so that meshbay-common is in place too. A +# marker left by %pre says whether this was an upgrade. +%pre +if [ "$1" -ge 2 ]; then + touch /run/meshbay-node-upgrade 2>/dev/null || true +fi + +%posttrans +# The node runs as a user service, in every signed-in user's own systemd +# manager: the system-wide reload does not reach those, and each would keep +# the old unit and the old code until restarted by hand. Every running user +# manager reloads, and restarts the node where it was running. +reload_user_managers() { + for bus in /run/user/*/systemd/private; do + [ -S "$bus" ] || continue + uid=$(basename "$(dirname "$(dirname "$bus")")") + user=$(id -nu "$uid" 2>/dev/null) || continue + systemctl --user -M "$user@" daemon-reload 2>/dev/null || true + [ -n "$upgraded" ] && systemctl --user -M "$user@" try-restart meshbay-node.service 2>/dev/null || true + done +} +upgraded= +if [ -e /run/meshbay-node-upgrade ]; then + upgraded=1 + rm -f /run/meshbay-node-upgrade +fi +if [ -d /run/systemd/system ]; then + systemctl daemon-reload || true + if [ -n "$upgraded" ]; then + systemctl try-restart 'meshbay-node@*.service' 2>/dev/null || true + fi + reload_user_managers +fi + %preun if [ -d /run/systemd/system ]; then systemctl daemon-reload || true |