1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-12-22 07:17:05 +00:00

migrate the migration state from MIGRATIONID in /etc/mailinabox.conf to STORAGE_ROOT/mailinabox.version so that the data format of STORAGE_ROOT is stored in the directory itself

This commit is contained in:
Joshua Tauberer 2014-08-03 21:41:32 +00:00
parent 64cb00b9d6
commit 5db12be507
2 changed files with 27 additions and 10 deletions

View File

@ -45,6 +45,12 @@ def migration_2(env):
for fn in glob.glob(os.path.join(env["STORAGE_ROOT"], 'mail/mailboxes/*/*/.dovecot.svbin')):
os.unlink(fn)
def migration_3(env):
# Move the migration ID from /etc/mailinabox.conf to $STORAGE_ROOT/mailinabox.version
# so that the ID stays with the data files that it describes the format of. The writing
# of the file will be handled by the main function.
pass
def get_current_migration():
ver = 0
while True:
@ -61,7 +67,14 @@ def run_migrations():
env = load_environment()
ourver = int(env.get("MIGRATIONID", "0"))
migration_id_file = os.path.join(env['STORAGE_ROOT'], 'mailinabox.version')
if os.path.exists(migration_id_file):
with open(migration_id_file) as f:
ourver = int(f.read().strip())
else:
# Load the legacy location of the migration ID. We'll drop support
# for this eventually.
ourver = int(env.get("MIGRATIONID", "0"))
while True:
next_ver = (ourver + 1)
@ -71,6 +84,7 @@ def run_migrations():
# No more migrations to run.
break
print()
print("Running migration to Mail-in-a-Box #%d..." % next_ver)
try:
@ -88,8 +102,13 @@ def run_migrations():
# Write out our current version now. Do this sooner rather than later
# in case of any problems.
env["MIGRATIONID"] = ourver
save_environment(env)
with open(migration_id_file, "w") as f:
f.write(str(ourver) + "\n")
# Delete the legacy location of this field.
if "MIGRATIONID" in env:
del env["MIGRATIONID"]
save_environment(env)
# iterate and try next version...

View File

@ -50,16 +50,13 @@ fi
if [ -f /etc/mailinabox.conf ]; then
# Run any system migrations before proceeding. Since this is a second run,
# we assume we have Python already installed.
echo
setup/migrate.py --migrate
# Okay now load the old .conf file to get existing configuration options.
# Load the old .conf file to get existing configuration options loaded
# into variables with a DEFAULT_ prefix.
cat /etc/mailinabox.conf | sed s/^/DEFAULT_/ > /tmp/mailinabox.prev.conf
source /tmp/mailinabox.prev.conf
MIGRATIONID=$DEFAULT_MIGRATIONID
else
# What migration are we at for new installs?
MIGRATIONID=$(setup/migrate.py --current)
rm -f /tmp/mailinabox.prev.conf
fi
# The box needs a name.
@ -249,6 +246,8 @@ if [ -z "$STORAGE_ROOT" ]; then
if [ ! -d /home/$STORAGE_USER ]; then useradd -m $STORAGE_USER; fi
STORAGE_ROOT=/home/$STORAGE_USER
mkdir -p $STORAGE_ROOT
echo $(setup/migrate.py --current) > $STORAGE_ROOT/mailinabox.version
chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version
fi
# Save the global options in /etc/mailinabox.conf so that standalone
@ -262,7 +261,6 @@ PUBLIC_IPV6=$PUBLIC_IPV6
PRIVATE_IP=$PRIVATE_IP
PRIVATE_IPV6=$PRIVATE_IPV6
CSR_COUNTRY=$CSR_COUNTRY
MIGRATIONID=$MIGRATIONID
EOF
# Start service configuration.