~billy-olsen/charms/xenial/mongodb/trunk

« back to all changes in this revision

Viewing changes to hooks/hooks.py

[veterok] Add flag to signal when the new_mongo_dir was just created and migrate the existing data directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1547
1547
    assert(data_directory_path)
1548
1548
    volid = volume_get_volume_id()
1549
1549
    if volid:
1550
 
        if volume_is_permanent(volid):
 
1550
        volid_from_subordinate = volume_get_id_for_storage_subordinate()
 
1551
        if volume_is_permanent(volid) and not volid_from_subordinate:
1551
1552
            if not volume_init_and_mount(volid):
1552
1553
                juju_log(
1553
1554
                    "volume_init_and_mount failed, not applying changes")
1581
1582
 
1582
1583
        # Create a directory structure below "new" mount_point
1583
1584
        curr_dir_stat = os.stat(data_directory_path)
 
1585
        new_mongo_dir_just_created = False
1584
1586
        if not os.path.isdir(new_mongo_dir):
1585
1587
            juju_log("mkdir %s" % new_mongo_dir)
1586
1588
            os.mkdir(new_mongo_dir)
 
1589
            new_mongo_dir_just_created = True
1587
1590
            # copy permissions from current data_directory_path
1588
1591
            os.chown(new_mongo_dir, curr_dir_stat.st_uid, curr_dir_stat.st_gid)
1589
1592
            os.chmod(new_mongo_dir, curr_dir_stat.st_mode)
1595
1598
        if not stop_hook():
1596
1599
            juju_log("stop_hook() failed - can't migrate data.")
1597
1600
            return False
1598
 
        if not os.path.exists(new_mongo_dir):
 
1601
        if not os.path.exists(new_mongo_dir) or new_mongo_dir_just_created:
1599
1602
            juju_log("migrating mongo data {}/ -> {}/".format(
1600
1603
                data_directory_path, new_mongo_dir))
1601
1604
            # void copying PID file to perm storage (shouldn't be any...)