def setup_startup_script(install_dir, nexus_current_dir_name, sym_linked_nexus_dir, nexus_username):
    full_current_dir = os.path.join(install_dir, nexus_current_dir_name)
    startup_script_path = os.path.join(full_current_dir, 'bin/nexus')

    if not fabric_exists('/etc/init.d/nexus'):
        with cd('/etc/init.d'):
            sudo('ln -s ' + startup_script_path + ' /etc/init.d/nexus')
            sudo('chmod 755 /etc/init.d/nexus')
            sudo('update-rc.d nexus defaults')

    # Edit the init script changing the following variables:
    #    * Change NEXUS_HOME to the absolute folder location e.g. NEXUS_HOME="/usr/local/nexus"
    #    * Set the RUN_AS_USER to nexus or any other user with restricted rights that you want to use to run the service
    #
    # update nexus home first
    before = 'NEXUS_HOME=\".+\"'
    after = 'NEXUS_HOME=\"' + sym_linked_nexus_dir + '\"'
    fabric_sed(startup_script_path, before, after, use_sudo=True, backup='.bak')

    # make sure the RUN_AS_USER variable is not commented out
    fabric_uncomment(startup_script_path, 'RUN_AS_USER='******'#', backup='.bak')

    # now update RUN_AS_USER
    before = '^\s*RUN_AS_USER=.*'
    after = 'RUN_AS_USER=\"' + nexus_username + '\"'
    fabric_sed(startup_script_path, before, after, use_sudo=True, backup='.bak')
Example #2
0
def setup_startup_script(install_dir, nexus_current_dir_name,
                         sym_linked_nexus_dir, nexus_username):
    full_current_dir = os.path.join(install_dir, nexus_current_dir_name)
    startup_script_path = os.path.join(full_current_dir, 'bin/nexus')

    if not fabric_exists('/etc/init.d/nexus'):
        with cd('/etc/init.d'):
            sudo('ln -s ' + startup_script_path + ' /etc/init.d/nexus')
            sudo('chmod 755 /etc/init.d/nexus')
            sudo('update-rc.d nexus defaults')

    # Edit the init script changing the following variables:
    #    * Change NEXUS_HOME to the absolute folder location e.g. NEXUS_HOME="/usr/local/nexus"
    #    * Set the RUN_AS_USER to nexus or any other user with restricted rights that you want to use to run the service
    #
    # update nexus home first
    before = 'NEXUS_HOME=\".+\"'
    after = 'NEXUS_HOME=\"' + sym_linked_nexus_dir + '\"'
    fabric_sed(startup_script_path,
               before,
               after,
               use_sudo=True,
               backup='.bak')

    # make sure the RUN_AS_USER variable is not commented out
    fabric_uncomment(startup_script_path,
                     'RUN_AS_USER='******'#',
                     backup='.bak')

    # now update RUN_AS_USER
    before = '^\s*RUN_AS_USER=.*'
    after = 'RUN_AS_USER=\"' + nexus_username + '\"'
    fabric_sed(startup_script_path,
               before,
               after,
               use_sudo=True,
               backup='.bak')
Example #3
0
def sed(filename, before, after, limit='', use_sudo=False, backup='.bak'):
    require('hosts')
    if 'localhost' in env.hosts:
        # Code copied from Fabric - is there a better way to have Fabric's sed()
        # use our sudo and run functions?
        expr = r"sed -i%s -r -e '%ss/%s/%s/g' %s"
        # Characters to be escaped in both
        for char in "/'":
            before = before.replace(char, r'\%s' % char)
            after = after.replace(char, r'\%s' % char)
        # Characters to be escaped in replacement only (they're useful in
        # regexe in the 'before' part)
        for char in "()":
            after = after.replace(char, r'\%s' % char)
        if limit:
            limit = r'/%s/ ' % limit
        command = expr % (backup, limit, before, after, filename)
        func = use_sudo and sudo or run
        return func(command)
    else:
        return fabric_sed(filename, before, after, limit, use_sudo, backup)
Example #4
0
def sed(filename, before, after, limit='', use_sudo=False, backup='.bak'):
    require('hosts')
    if 'localhost' in env.hosts:
        # Code copied from Fabric - is there a better way to have Fabric's sed()
        # use our sudo and run functions?
        expr = r"sed -i%s -r -e '%ss/%s/%s/g' %s"
        # Characters to be escaped in both
        for char in "/'":
            before = before.replace(char, r'\%s' % char)
            after = after.replace(char, r'\%s' % char)
        # Characters to be escaped in replacement only (they're useful in
        # regexe in the 'before' part)
        for char in "()":
            after = after.replace(char, r'\%s' % char)
        if limit:
            limit = r'/%s/ ' % limit
        command = expr % (backup, limit, before, after, filename)
        func = use_sudo and sudo or run
        return func(command)
    else:
        return fabric_sed(filename, before, after, limit, use_sudo, backup)