1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-11-26 02:57:04 +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')): for fn in glob.glob(os.path.join(env["STORAGE_ROOT"], 'mail/mailboxes/*/*/.dovecot.svbin')):
os.unlink(fn) 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(): def get_current_migration():
ver = 0 ver = 0
while True: while True:
@ -61,6 +67,13 @@ def run_migrations():
env = load_environment() env = load_environment()
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")) ourver = int(env.get("MIGRATIONID", "0"))
while True: while True:
@ -71,6 +84,7 @@ def run_migrations():
# No more migrations to run. # No more migrations to run.
break break
print()
print("Running migration to Mail-in-a-Box #%d..." % next_ver) print("Running migration to Mail-in-a-Box #%d..." % next_ver)
try: try:
@ -88,7 +102,12 @@ def run_migrations():
# Write out our current version now. Do this sooner rather than later # Write out our current version now. Do this sooner rather than later
# in case of any problems. # in case of any problems.
env["MIGRATIONID"] = ourver 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) save_environment(env)
# iterate and try next version... # iterate and try next version...

View File

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