Example #1
0
def doUpgrade():
    if os.path.isdir(mongosymlink) and not lxtools.getIfSymbolicLink(mongosymlink):
        # Upgrade
        print('Upgrade needed...')

        # Check if admin
        if not lxtools.getIfAdmin():
            print(config.getMessage('REQUIREADMIN'))
            return False

        # Load package file
        pkginfo = lxtools.loadjson(os.path.join(mongosymlink, config.getConfigKey('configfile')))
        mongoversion = pkginfo.get('version', None)

        # Execute Patches
        patches = config.getConfigKey('mongo.patches', None)
        patch.doPatch(mongosymlink, patches)

        # Stop Service/Daemon and de-register Service/Daemon, safe-remove
        print('Stop Service/Daemon...')
        package.runScript(pkginfo, ['remove', 'safe', 'hidden'])

        # Check if *all* symbolic links removed, when not remove it
        symlinks = config.getConfigKey('mongo.links', {})
        if symlinks:
            for names in symlinks:
                target = symlinks[names]['target']

                if os.path.exists(target) and lxtools.getIfSymbolicLink(target):
                    os.remove(target)

        # Move Directory to mongodb/{version}/
        print('Move files...')
        mongodir = os.path.join(mongobasedir, mongoversion)

        # Create new mongodb directory and move installed version
        os.makedirs(mongobasedir)
        os.rename(mongosymlink, mongodir)

        # Create Symlink
        print('Create symlinks...')
        lxtools.setDirectoryLink(mongosymlink, mongodir)

        # Start Daemon/Service
        print('Start Service/Daemon...')
        package.runScript(pkginfo, ['install', 'hidden'])

        print('Done')
        return True
    else:
        return None
Example #2
0
def resetNode():
    # If User Admin?
    if not lxtools.getIfAdmin():
        print(config.getMessage('REQUIREADMIN'))
        return False

    # Windows
    if sys.platform == 'win32':
        # Delete old LINK Directory when exits
        if os.path.exists(lxBinPath):
            # If Directory a Symbolic Link
            if not lxtools.getIfSymbolicLink(lxBinPath):
                print(
                    'ERROR: Target Directory is not a link and can not be removed.'
                )
                return False

            # Remove Link
            try:
                os.remove(lxBinPath)
            except BaseException as e:
                print('ERROR:', e)
                return False

        return True

    # Unix
    if sys.platform.startswith('linux') or sys.platform == 'darwin':
        links = config.getConfigKey('node.links')

        # Unlink old version
        for names in links:
            target = os.path.join(links[names]['target'], names)
            options = links[names].get('options', [])

            # Check if link, when true then remove it
            if os.path.islink(target):
                try:
                    os.remove(target)
                except BaseException as e:
                    print('ERROR:', e)
                    return False
            else:
                # Check if "fullname" a real existing path/file, then raise Exception
                if os.path.isdir(target) or os.path.isfile(target):
                    if 'remove_if_exists' in options:
                        try:
                            print('Remove Directory', target)
                            lxtools.rmDirectory(target)
                        except BaseException as e:
                            print('ERROR:', e)
                            return False
                    else:
                        print('UUh, a target is not a link...', target)
                        return False

        return True

    # No operation for that system :(
    return False
Example #3
0
def doReset():
    activeVersion = getActiveMongoVersion()

    # if not a version activated, then abort
    if activeVersion == '':
        print('No currently activated MongoDB Version')
        return False

    # Admin required
    if not lxtools.getIfAdmin():
        print(config.getMessage('REQUIREADMIN'))
        return False

    # If folder exits but not an symlink, then abort
    if activeVersion is False:
        print('ERROR: Folder is not a symlink.')
        return False

    print('Deactivate MongoDB v' + activeVersion)

    # Run Script file
    pkginfo = lxtools.loadjson(os.path.join(mongosymlink, config.getConfigKey('configfile')))
    package.runScript(pkginfo, ['remove', 'safe', 'hidden'])

    # Check if *all* symbolic links removed, when not remove it
    symlinks = config.getConfigKey('mongo.links', None)
    if symlinks:
        for names in symlinks:
            target = os.path.join(symlinks[names]['target'], names)

            if os.path.exists(target) and lxtools.getIfSymbolicLink(target):
                os.remove(target)

    if not resetMongo():
        return False
Example #4
0
def resetNode():
    # If User Admin?
    if not lxtools.getIfAdmin():
        print(config.getMessage('REQUIREADMIN'))
        return False

    # Windows
    if sys.platform == 'win32':
        # Delete old LINK Directory when exits
        if os.path.exists(lxBinPath):
            # If Directory a Symbolic Link
            if not lxtools.getIfSymbolicLink(lxBinPath):
                print('ERROR: Target Directory is not a link and can not be removed.')
                return False

            # Remove Link
            try:
                os.remove(lxBinPath)
            except BaseException as e:
                print('ERROR:', e)
                return False

        return True

    # Unix
    if sys.platform.startswith('linux') or sys.platform == 'darwin':
        links = config.getConfigKey('node.links')

        # Unlink old version
        for names in links:
            target = os.path.join(links[names]['target'], names)
            options = links[names].get('options', [])

            # Check if link, when true then remove it
            if os.path.islink(target):
                try:
                    os.remove(target)
                except BaseException as e:
                    print('ERROR:', e)
                    return False
            else:
                # Check if "fullname" a real existing path/file, then raise Exception
                if os.path.isdir(target) or os.path.isfile(target):
                    if 'remove_if_exists' in options:
                        try:
                            print('Remove Directory', target)
                            lxtools.rmDirectory(target)
                        except BaseException as e:
                            print('ERROR:', e)
                            return False
                    else:
                        print('UUh, a target is not a link...', target)
                        return False

        return True

    # No operation for that system :(
    return False
Example #5
0
def getLocalNodeVersion():
    # Check if symbolic link
    if not lxtools.getIfSymbolicLink(lxBinPath):
        return False

    try:
        # Read symbolic Link
        path = os.readlink(lxBinPath)

        # Remove bin/node. Only for non win32 platforms
        if sys.platform != 'win32':
            path = path.rsplit(os.sep, 2)[0]

        # Splits the Seperator and Returns the last Pathname (nodeversion)
        return path.rsplit(os.sep).pop()
    except:
        return ''
Example #6
0
def getLocalNodeVersion():
    # Check if symbolic link
    if not lxtools.getIfSymbolicLink(lxBinPath):
        return False

    try:
        # Read symbolic Link
        path = os.readlink(lxBinPath)

        # Remove bin/node. Only for non win32 platforms
        if sys.platform != 'win32':
            path = path.rsplit(os.sep, 2)[0]

        # Splits the Seperator and Returns the last Pathname (nodeversion)
        return path.rsplit(os.sep).pop()
    except:
        return ''
Example #7
0
def getActiveMongoVersion():
    # Check if symbolic link
    if not os.path.isdir(mongosymlink):
        return ''

    if not lxtools.getIfSymbolicLink(mongosymlink):
        return False

    try:
        # Read symbolic Link
        path = os.readlink(mongosymlink)

        # Splits the Seperator and Returns the last Pathname (mongoversion)
        return path.rsplit(os.sep).pop()
    except Exception as e:
        print('ERROR:', e)
        return ''
Example #8
0
def resetMongo():
    # If User Admin?
    if not lxtools.getIfAdmin():
        print(config.getMessage('REQUIREADMIN'))
        return False

    # Delete old LINK Directory when exits
    if os.path.exists(mongosymlink):

        # If Directory a Symbolic Link
        if not lxtools.getIfSymbolicLink(mongosymlink):
            print('ERROR: Mongo folder is not a link and can not be removed.')
            return False

        # Remove Link
        try:
            os.remove(mongosymlink)
        except BaseException as e:
            print('ERROR:', e)
            return False

    return True