2016-01-02 02:52:30 -05:00
|
|
|
#!/bin/bash
|
2019-01-07 01:04:17 -05:00
|
|
|
set -eo pipefail
|
|
|
|
|
[[ $TRACE ]] && set -x
|
2016-01-02 02:52:30 -05:00
|
|
|
|
|
|
|
|
readonly DOKKU_ROOT="${DOKKU_ROOT:-/home/dokku}"
|
|
|
|
|
readonly DOKKU_LIB_ROOT="${DOKKU_LIB_PATH:-/var/lib/dokku}"
|
|
|
|
|
|
|
|
|
|
ps_backtrace() {
|
|
|
|
|
if [ $# -lt 1 ]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
echo "Usage: $0 PID" >/dev/stderr
|
2016-01-02 02:52:30 -05:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2019-01-07 01:04:17 -05:00
|
|
|
declare -i pid=$1
|
|
|
|
|
ppid=0
|
|
|
|
|
header_modifier=""
|
|
|
|
|
while :; do
|
2016-01-02 02:52:30 -05:00
|
|
|
if [ $ppid -ne 0 ]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
header_modifier=h
|
|
|
|
|
fi
|
|
|
|
|
ppid=$(ps -o ppid= $pid)
|
|
|
|
|
ps uww $header_modifier -p $pid
|
2024-08-28 06:31:27 +02:00
|
|
|
if [ $pid -eq 1 -o $pid -eq 0 ]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
pid=$ppid
|
|
|
|
|
done
|
2016-01-02 02:52:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
|
# HACK: Ensure that we only delete data when purging dokku from the system
|
2019-01-07 01:04:17 -05:00
|
|
|
if ps_backtrace $BASHPID 2>/dev/null | grep dpkg | grep -- "--purge" >/dev/null; then
|
2016-01-02 02:52:30 -05:00
|
|
|
echo "Processing purge"
|
|
|
|
|
|
|
|
|
|
echo "Destroying deployed applications"
|
2020-08-02 02:40:11 +03:00
|
|
|
for app in $(DOKKU_QUIET_OUTPUT=1 dokku apps:list); do
|
2016-01-02 02:52:30 -05:00
|
|
|
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
|
2019-01-07 01:04:17 -05:00
|
|
|
rm ${DOKKU_LIB_ROOT}/plugins/available/$plugin
|
2016-01-02 02:52:30 -05:00
|
|
|
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 "$@"
|