Skip to content
Snippets Groups Projects
Commit e4f07e3b authored by Gilles Filippini's avatar Gilles Filippini
Browse files

[fix] docker: entrypoint - backup conf.json

When `/etc/duniter` is not mounted as a persistent volume, the
configuration file is lost after re-creating the instance.

To prevent this, before transitionning the configuration file from
volume '/var/lib/duniter' to volume '/etc/duniter', the entrypoint
backups it into '/var/lib/duniter'.  On restart, if the entrypoint
detects that the link to '/etc/duniter/conf.json' is dangling, it
prints a big fat warning into the logs and re-use the backuped
config file.
parent 6a73c975
No related branches found
No related tags found
1 merge request!1380Docker entrypoint - fixes and error handling
......@@ -4,6 +4,7 @@ set -u
function boolean () {
echo "$1" | sed -E 's/^(true|yes|1)$/true/i'
}
big_fat_warning='\033[01;31m**WARNING**:\033[0m'
DEBUG_ENTRYPOINT="$(boolean "${DEBUG_ENTRYPOINT:-false}")"
if [ "$DEBUG_ENTRYPOINT" = true ]; then
......@@ -17,10 +18,25 @@ home_default=$home/duniter_default
manual_config="$(boolean "${DUNITER_MANUAL_CONFIG:-false}")"
auto_sync="$(boolean "${DUNITER_AUTO_SYNC:-false}")"
# Use path /etc/duniter/conf.json
if ! [ -f "$config/conf.json" ] && [ -f "$home_default/conf.json" ]; then
# Use new path /etc/duniter/conf.json
if ! [ -f "$config/conf.json" ]; then
if [ "$(readlink "$home_default/conf.json")" = "$config/conf.json" ]; then
# The configuration file was moved already but the link is dangling
# It is likely that '/etc/duniter' is an anonymous volume
echo -e "$big_fat_warning Your configuration file didn't survive the restart!"
echo -e "$big_fat_warning Make sure that '/etc/duniter' is explicitely mounted as a persistent volume or you'll lose it again."
if [ -f "$home_default/conf.json.backup" ]; then
echo -e "$big_fat_warning Found backup file '$home_default/conf.json.backup'; using it..."
mv "$home_default/conf.json.backup" "$home_default/conf.json"
fi
fi
if [ -f "$home_default/conf.json" ]; then
echo "Moving existing configuration file '$home_default/conf.json' to its new location: '$config/conf.json'"
echo "A backup is kept at '$home_default/conf.json.backup'"
cp "$home_default/conf.json" "$home_default/conf.json.backup"
mv "$home_default/conf.json" "$config/conf.json"
fi
fi
mkdir -p "$home/duniter_default"
ln -fs "$config/conf.json" "$home_default/conf.json"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment