Example #1
0
def restart():
    '''Restart both frontend and backend services'''
    with benchmark('services.restart'):
        if env.roledefs['php'] and len(env.roledefs['php']):
            execute('services.backend')

        if env.roledefs['web'] and len(env.roledefs['web']):
            execute('services.frontend')
Example #2
0
def restore():
    '''Performs a restore of the Mongo database for the given environment'''
    if not env.roledefs['mongo'] or len(env.roledefs['mongo']) == 0:
        abort(
            "Unable to find Mongo server(s) to perform restore on - quitting!")

    with benchmark('mongo_restore'):
        with mongo():
            execute('snapshot.recreate')
Example #3
0
def restore(init_file='/etc/mysql/init.sql'):
    '''Performs a restore of the MySQL database for the given environment'''
    if not env.roledefs['mysql'] or len(env.roledefs['mysql']) == 0:
        abort(
            "Unable to find MySQL server(s) to perform restore on - quitting!")

    with benchmark('mysql_restore'):
        with mysql(init_file):
            puts("running snapshot recreate")
            execute('snapshot.recreate')
Example #4
0
def mongo():
    try:
        with benchmark('mongo_stop'):
            puts('Waiting for MongoD to finish shutting down...')
            with nested(hide('output', 'running', 'warnings'),
                        settings(warn_only=True)):
                sudo("""
          seconds=30;
          while [ $seconds -gt 0 ]; do
            lsof -t /var/lib/mongo &>- && for p in $(lsof -t /var/lib/mongo); do kill -9 $p; done || exit 0;
            sleep 1;
            seconds=$((seconds - 1));
          done;
          exit 2
        """)
            sudo('umount /var/lib/mongo')
            yield
    finally:
        with benchmark('mongo_start'):
            sudo('mount /dev/sdb1 /var/lib/mongo')
            sudo('rm -rf /var/lib/mongo/mongod.lock /var/lib/mongo/journal')
            sudo('service mongod start')
Example #5
0
def mysql(init_file='/etc/mysql/init.sql'):
    try:
        with benchmark('mysql_stop'):
            with nested(hide('output', 'running', 'warnings'),
                        settings(warn_only=True)):
                puts('Waiting for MySQLD to finish shutting down...')
                sudo("""
          seconds=30;
          while [ $seconds -gt 0 ]; do
            lsof -t /var/lib/mysql &>- && for p in $(lsof -t /var/lib/mysql); do kill -9 $p; done || exit 0;
            sleep 1;
            seconds=$((seconds - 1));
          done;
          exit 2
        """)
            sudo('umount /var/lib/mysql')
            yield
    finally:
        with benchmark('mysql_start'):
            sudo('mount /dev/sdb1 /var/lib/mysql')
            sudo('rm -f /var/lib/mongo/master.info')
            sudo('nohup mysqld --init-file=%s &>/tmp/reinit.log &' %
                 (init_file))
            puts('Waiting for MySQLD to finish initializing...')
            with nested(hide('output', 'running', 'warnings'),
                        settings(warn_only=True)):
                sudo("""
          seconds=30;
          while [ $seconds -gt 0 ]; do
            grep -qP "^Version.+socket:.+port:.+" /tmp/reinit.log && pkill -9 mysql && exit 0;
            grep -qP "(Aborting|Starting shutdown)" /tmp/reinit.log && exit 1;
            sleep 1;
            seconds=$((seconds - 1));
          done;
          exit 2
        """)
            sudo('service mysql start')
Example #6
0
def restore(*_environ):
    '''
  Restore the given environment(s)
  '''
    _environ = split_environments(*_environ)

    if not _environ or len(_environ) == 0:
        if not env.env:
            abort("No environment(s) selected (_environ was %s)." % _environ)
        else:
            warn("restoring environment: %s" % env.env)
            _environ = set([env.env])

    with benchmark('restore'):
        for _env in _environ:
            # sysop_announce("%s is restoring mysql/mongo in environment %s" % (runner(), _env))
            execute('setenv', _env)
            for task in ['mongo.restore', 'mysql.restore', 'services.restart']:
                execute(task)
Example #7
0
def recreate():
    '''Recreate the snapshot/mountpoint for the given host'''
    with benchmark('snapshot_recreate'):
        client = VnxClient(
            VnxConfig(dry_run=env.dry_run,
                      debug=env.debugging,
                      cli_path='/usr/bin/sudo /opt/Navisphere/bin/naviseccli'))

        mountpoint_name = object_name_from_host_env("%s-smp")
        mountpoint_lun_id = client.get_lun_by_name(mountpoint_name).id

        snapshot_name = object_name_from_host_env("%s-snap")
        snapshot_lun_id = client.get_snapshot_by_name(
            snapshot_name).primary_lun_s

        client.detach_snapshot(snapshot_name, mountpoint_lun_id)
        client.delete_snapshot(snapshot_name)

        sleep(15)  # let the array cool down

        client.create_snapshot(snapshot_lun_id, snapshot_name)
        client.attach_snapshot(snapshot_name, mountpoint_lun_id)

        sleep(15)  # let the array cool down
Example #8
0
def frontend():
    '''Restart frontend services'''
    with benchmark('frontend'):
        sudo('service nginx restart')
        sudo('service varnish restart')
Example #9
0
def backend():
    '''Restart backend services'''
    with benchmark('backend'):
        sudo('service php-fpm restart')