Properly handle dokku data removal

- remove deployed applications during dpkg purge
- disable all core plugins during dpkg purge
- ensure init files are removed
- ensure motd is removed
- remove all core plugins, dokku config files (including tls/sshcommand entries etc.) during purge
- remove all empty directories and broken symlinks in the DOKKU_ROOT and DOKKU_LIB_ROOT directories during purge

Note that we do not delete the dokku user itself as there might be other data we don't know about in this directory.
This commit is contained in:
Jose Diaz-Gonzalez
2016-01-02 02:52:30 -05:00
parent 51a50fb571
commit 73b3c4af40
2 changed files with 91 additions and 4 deletions

40
debian/postrm vendored
View File

@@ -1,7 +1,39 @@
#!/bin/bash
set -eo pipefail; [[ $TRACE ]] && set -x
if [[ "$1" == "purge" ]] && [[ -e /usr/share/debconf/confmodule ]]; then
. /usr/share/debconf/confmodule
db_purge
fi
readonly DOKKU_ROOT="${DOKKU_ROOT:-/home/dokku}"
readonly DOKKU_LIB_ROOT="${DOKKU_LIB_PATH:-/var/lib/dokku}"
main() {
rm -f /etc/init/dokku-installer.conf
rm -f /etc/init/dokku-redeploy.conf
rm -f /etc/systemd/system/dokku-installer.conf
rm -f /etc/systemd/system/dokku-redeploy.service
rm -f /etc/update-motd.d/99-dokku
if [[ "$1" == "purge" ]]; then
rm -f ${DOKKU_ROOT}/.dokkurc ${DOKKU_ROOT}/dokkurc ${DOKKU_ROOT}/tls
rm -f ${DOKKU_ROOT}/.ssh/authorized_keys ${DOKKU_ROOT}/.sshcommand
rm -f ${DOKKU_ROOT}/ENV ${DOKKU_ROOT}/HOSTNAME ${DOKKU_ROOT}/VERSION
rm -rf ${DOKKU_ROOT}/.cache
rm -rf ${DOKKU_LIB_ROOT}/core-plugins
rm -f ${DOKKU_LIB_ROOT}/plugins/config.toml
if [[ -d ${DOKKU_LIB_ROOT} ]]; then
find -L ${DOKKU_LIB_ROOT} -type l -delete
find ${DOKKU_LIB_ROOT} -type d -empty -delete
fi
if [[ -d ${DOKKU_ROOT} ]]; then
find -L ${DOKKU_ROOT} -type l -delete
find ${DOKKU_ROOT} -type d -empty -delete
fi
if [[ -e /usr/share/debconf/confmodule ]]; then
. /usr/share/debconf/confmodule
db_purge
fi
fi
}
main "$@"

55
debian/prerm vendored Executable file
View File

@@ -0,0 +1,55 @@
#!/bin/bash
set -eo pipefail; [[ $TRACE ]] && set -x
readonly DOKKU_ROOT="${DOKKU_ROOT:-/home/dokku}"
readonly DOKKU_LIB_ROOT="${DOKKU_LIB_PATH:-/var/lib/dokku}"
ps_backtrace() {
if [ $# -lt 1 ]; then
echo "Usage: $0 PID" > /dev/stderr
exit 1
fi
declare -i pid=$1;
ppid=0;
header_modifier="";
while : ; do
if [ $ppid -ne 0 ]; then
header_modifier=h;
fi;
ppid=$(ps -o ppid= $pid);
ps uww $header_modifier -p $pid;
if [ $pid -eq 1 ]; then
break;
fi;
pid=$ppid;
done;
}
main() {
# HACK: Ensure that we only delete data when purging dokku from the system
if ps_backtrace $BASHPID 2> /dev/null | grep dpkg | grep -- "--purge" > /dev/null; then
echo "Processing purge"
echo "Destroying deployed applications"
for app in $(DOKKU_QUIET_OUTPUT=1 dokku apps); do
dokku --force apps:destroy $app
done
# HACK: Only disable core plugins, as we don't know what data users store in non-core plugin directories
echo "Disabling all core plugins"
find ${DOKKU_LIB_ROOT}/core-plugins/available -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do
if [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then
rm ${DOKKU_LIB_ROOT}/plugins/available/$plugin;
PLUGIN_PATH=${DOKKU_LIB_ROOT}/core-plugins plugn disable $plugin
PLUGIN_PATH=${DOKKU_LIB_ROOT}/plugins plugn disable $plugin
fi
done
else
echo "Processing $1"
fi
dokku cleanup
}
main "$@"