Exemple #1
0
def install_motd():
    """ Installs a succulent ascii-art MOTD. In colour!
    The raspberry was by RPi forum user b3n, taken from
    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=2&t=5494
    """

    puts(green("Installing succulent MOTD"))
    motd = text_strip_margin("""
        |
        |{g}      .~~.   .~~.
        |{g}     ". \ " " / ."
        |{r}      .~ .~~~..~.
        |{r}     : .~."~".~. :    {b}                       __                      {o}     _
        |{r}    ~ (   ) (   ) ~   {b}    _______ ____ ___  / /  ___ __________ __  {o}___  (_)
        |{r}   ( : "~".~."~" : )  {b}   / __/ _ `(_-</ _ \/ _ \/ -_) __/ __/ // / {o}/ _ \/ /
        |{r}    ~ .~ (   ) ~. ~   {p}  /_/  \_,_/___/ .__/_.__/\__/_/ /_/  \_, / {o}/ .__/_/
        |{r}     (  : "~" :  )    {p}              /_/                    /___/ {o}/_/
        |{r}      "~ .~~~. ~"
        |{r}          "~"
        |{n}
        |
        |""".format(
            g="",
            r="",
            b="",
            o="",
            p="",
            n="",
        )
    )
    with hide("output", "running"):
        sudo_file_write("/etc/motd", motd)
Exemple #2
0
    def reboot(self):
        self.before_reboot()

        puts(green('Rebooting server'))
        sudo('reboot')

        self.after_reboot()
Exemple #3
0
def local_create_run_command():
    gunicorn_command = get_gunicorn_command(daemon=False)
    puts("Creating run_server command to be run " + (
        "with" if env.USE_SUPERVISOR else "without") + " supervisor.")
    with lcd(env.localfolder):
        with open('run_server', 'w') as runner:
            runner.write(run_command_content())
Exemple #4
0
def create_project():
    """
    Создает новый проект
    """
    # спрашиваем у пользователя название папки с проектом
    prompt('project root name: ', 'project_root',
           validate='^([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$')

    # спрашиваем у пользователя название проекта
    prompt('project name: ', 'project',
           validate='^([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$')
    puts('create project: {0}'.format(env.project))

    with lcd(PROJECTS_ROOT):
        # Создаем директорию с root проектом
        local('mkdir %s' % env.project_root)

        with lcd(env.project_root):
            # Создаем директорию с django проектом и переходим в нее
            local('mkdir {0}-django'.format(env.project))

            with lcd('{0}-django'.format(env.project)):
                # Создаем виртуальное окружение
                local('virtualenv -p {0} .venv'.format(PYTHON))

                with prefix('.venv/bin/activate'):
                    # Устанавливаем django
                    if DJANGO_VERSION:
                        local('pip install django=={0}'.format(DJANGO_VERSION))
                    else:
                        local('pip install django')

                # Создаем проект из шаблона
                local('django-admin --template={0} {1}'.format(PROJECT_TEMPLATE_PATH,
                                                               env.project))
def syntax_check():
    """Runs flake8 against the codebase."""
    with fab_settings(warn_only=True):
        for file_type in settings.SYNTAX_CHECK:
            needs_to_abort = False
            # because egrep fails with exit code 1, we need to allow this as
            # a successful exit code in our env
            if 1 not in env.ok_ret_codes:
                env.ok_ret_codes.append(1)
            output = local(
                'find -name "{}" -print'.format(file_type),
                capture=True,
            )
            files = output.split()
            for file in files:
                if any(s in file for s in settings.SYNTAX_CHECK_EXCLUDES):
                    continue
                result = local('egrep -i -n "{0}" {1}'.format(
                    settings.SYNTAX_CHECK[file_type], file), capture=True)
                if result:
                    warn(red("Syntax check found in '{0}': {1}".format(
                        file, result)))
                    needs_to_abort = True
            if needs_to_abort:
                abort(red('There have been errors. Please fix them and run'
                          ' the check again.'))
            else:
                puts(green('Syntax check found no errors. Very good!'))
Exemple #6
0
    def pingcheck(self):
        domain = self._metadata.config["domain"]
        for server in sorted(self._metadata.servers):
            ip = self._metadata.servers[server]["ip"]
            puts(yellow("pinging %s.%s (%s)" % (server,domain,ip)))

            local("ping -c1 -W20 %s" % ip)
Exemple #7
0
def wait_for_health(status):
    """
    Waits for the cluster's health to match what we want

    Continually poll the elasticsearch cluster health API for health
    to match what we want
    """

    # wait (limit * sleep) seconds
    tries = DEFAULT_TRIES
    while tries > 0:
        st = get_cluster_health()
        utils.puts(
            'Waiting for cluster health to be {}, currently {}'.format(
                getattr(colors, status)(status),
                getattr(colors, st)(st),
            )
        )
        if st == status:
            return
        else:
            tries -= 1
            time.sleep(DEFAULT_INTERVAL)
    console.confirm(
        'Cluster status never got {}! Press Enter to continue, '
        'CTRL+C to abort (check output of {}/_cluster/health?pretty)'.
        format(status, env.apis[0])
    )
Exemple #8
0
def test_puts_without_prefix():
    """
    puts() shouldn't prefix output with env.host_string if show_prefix is False
    """
    s = "my output"
    puts(s, show_prefix=False)
    eq_(sys.stdout.getvalue(), "%s" % (s + "\n"))
Exemple #9
0
def add_plugin(name, image=None, dockerfile='Dockerfile', build_context=None,
               should_restart=True):
    """
    Add a new plugin by modifying skygear server configuration

    If an image is specified, it will be treated as a Docker repository image
    and pulled from the repository. If an image is not specified, a build
    directory is configured where you should upload your plugin via git.

    Skygear Server is restarted automatically by default if an image is
    specified.

    If your Dockerfile is not at the project root, you should specify
    an alternative Dockerfile location and build context.
    """
    config_file = '/home/ubuntu/myapp/development.ini'
    service_name = "plugin_{0}".format(name)
    with cd("myapp"):
        data = read_compose_override()
        if service_name in data.get('services', {}):
            error("Plugin '{0}' already exists.".format(name))
            return
        augtool(r"""
        set /files{0}/plugin\ \"{1}\"/transport http
        set /files{0}/plugin\ \"{1}\"/path http://{1}:8000
        """.format(config_file, service_name))
        data = add_docker_plugin(data, name, image, dockerfile, build_context)
        write_compose_override(data)
    if image is None:
        puts("""Plugin '{0}' is added to Skygear. To upload plugin, add
'git@<ip address>:{0}' as a git remote and push your code.""".format(name))
        return
    if should_restart:
        restart(should_recreate=True)
Exemple #10
0
def stage7_midonet_tunnelzone_members():
    metadata = Config(os.environ["CONFIGFILE"])

    if cuisine.file_exists("/tmp/.%s.lck" % sys._getframe().f_code.co_name):
        return

    cuisine.package_ensure("expect")

    for container_role in ['container_midonet_gateway', 'container_openstack_compute', 'container_openstack_neutron']:
        if container_role in metadata.roles:
            for container in metadata.containers:
                if container in metadata.roles[container_role]:
                    puts(green("adding container %s as member to tunnel zones" % container))
                    add_host_to_tunnel_zone(metadata.config["debug"], container, metadata.containers[container]["ip"])

    for physical_role in ['physical_midonet_gateway', 'physical_openstack_compute']:
        if physical_role in metadata.roles:
            for server in metadata.servers:
                if server in metadata.roles[physical_role]:
                    puts(green("adding server %s as member to tunnel zones" % server))

                    #
                    # tinc can only work with MTU 1500
                    # we could use the approach from http://lartc.org/howto/lartc.cookbook.mtu-mss.html
                    # but instead we will disable rp_filter and use the physical interface ip
                    #
                    # server_ip = "%s.%s" % (metadata.config["vpn_base"], metadata.config["idx"][server])
                    #

                    server_ip = metadata.servers[server]["ip"]
                    add_host_to_tunnel_zone(metadata.config["debug"], server, server_ip)

    cuisine.file_write("/tmp/.%s.lck" % sys._getframe().f_code.co_name, "xoxo")
Exemple #11
0
def info(text, *args, **kwargs):
    args = (yellow(arg) for arg in args)
    kwargs = {key: yellow(value) for key, value in kwargs.items()}
    text = text.format(*args, **kwargs)
    if not text.startswith(' '):
        text = green(text)
    puts(text)
Exemple #12
0
def mysql_install():
    """ Installs mysql. """
    if _mysql_is_installed():
        puts('Mysql is already installed.')
        return

    passwd = _get_root_password()

    # this way mysql won't ask for a password on installation
    # see http://serverfault.com/questions/19367/scripted-install-of-mysql-on-ubuntu
    os = utils.detect_os()
    system.aptitude_install('debconf-utils')

    mysql_versions = {'lenny': '5.0', 'squeeze': '5.1', 'maverick': '5.1'}
    version = mysql_versions[os]

    debconf_defaults = [
        "mysql-server-%s mysql-server/root_password_again password %s" % (version, passwd),
        "mysql-server-%s mysql-server/root_password password %s" % (version, passwd),
    ]

    sudo("echo '%s' | debconf-set-selections" % "\n".join(debconf_defaults))

    warn('\n=========\nThe password for mysql "root" user will be set to "%s"\n=========\n' % passwd)
    system.aptitude_install('mysql-server')
Exemple #13
0
def midonet_manager():

    if "OS_MIDOKURA_REPOSITORY_USER" in os.environ:
        puts(green("installing MidoNet Manager on %s" % env.host_string))

        run("""
API_IP="%s"
dpkg --configure -a
apt-get install -y -u midonet-manager

#
# midonet manager 1.9.3
#
cat >/var/www/html/midonet-manager/config/client.js <<EOF
{
  "api_host": "http://${API_IP}:8080",
  "login_host": "http://${API_IP}:8080",
  "api_namespace": "midonet-api",
  "api_version": "1.8",
  "api_token": false,
  "poll_enabled": true,
  "agent_config_api_host": "http://${API_IP}:8459",
  "agent_config_api_namespace": "conf",
  "trace_api_host": "http://${API_IP}:8080",
  "traces_ws_url": "ws://${API_IP}:8460"
}
EOF

service apache2 restart

""" % metadata.servers[metadata.roles['midonet_api'][0]]['ip'])

    else:
        puts(yellow("MidoNet Manager is only available in MEM"))
Exemple #14
0
def script(path):
    """
    Copy and run the given script *while the service is down*

    Useful for when you need to make adjustments to the service between stop
    and start. This script gets copied to all the target nodes, turned on the
    execution bit, then called without any parameters.

    Arguments:

    * ``path``: Path to the local file to be uploaded. This file has to exist
      and will be uploaded to a temporary location (which will be cleaned up
      upon exit)

    """

    fp = os.path.abspath(os.path.expanduser(path))
    if not os.path.isfile(fp):
        raise IOError('Local script {} is not a file'.format(fp))

    remote_dir = os.path.join(
        tempfile.gettempdir(), 'burlybeetle',
        env.service_name, env.timestamp,
    )
    env.script_file = os.path.join(remote_dir, os.path.basename(fp))
    if env.commit:
        run('mkdir -pv {}'.format(remote_dir))
        put(fp, env.script_file)
        run('chmod -v +x {}'.format(env.script_file))
    else:
        utils.puts('put (noop): {} -> {}'.format(fp, env.script_file))
Exemple #15
0
 def _do(f_out, path, imported):
     s = ''
     dirpath = dirname(path)      
     with _open_file(path, 'r') as f_in:
         s = f_in.read()
  
     # Write out prepends
     for m in _re_prepend.finditer(s):
         file_path = _find_file(m.group('file'), dirpath)
         if not file_path in imported:
             puts('  prepend: %s' % file_path)
             imported.append(file_path)
             _do(f_out, file_path, imported)
     
     # Write out file
     _mark(f_out, os.path.basename(path))  
     f_out.write(s+'\n')
     
     # Write out appends    
     for m in _re_append.finditer(s):
         file_path = _find_file(m.group('file'), dirpath)
         if not file_path in imported:
             puts('  append: %s' % file_path)
             imported.append(file_path)
             _do(f_out, file_path, imported)
Exemple #16
0
def apply(obj, repo=None):
    if repo is None:
        repo = docs_meta.GIT_REMOTE["upstream"]

    cmd = [
        "curl",
        "https://github.com/{0}/".format(repo),
        "|",
        "git",
        "am",
        "--signoff --3way" if env.sign else "--3way",
    ]

    if obj.startswith("http"):
        cmd[1] = obj
        if not obj.endswith(".patch"):
            cmd[1] += ".patch"

        local(" ".join(cmd))
    elif re.search("[a-zA-Z]+", obj):
        cmd[1] = cmd[1] + "commit/" + obj + ".patch"

        local(" ".join(cmd))
        puts("[git]: merged commit {0} for {1} into {2}".format(obj, repo, docs_meta.get_branch()))
    else:
        cmd[1] = cmd[1] + "pull/" + obj + ".patch"

        local(" ".join(cmd))
        puts("[git]: merged pull request #{0} for {1} into {2}".format(obj, repo, docs_meta.get_branch()))
Exemple #17
0
def stage_latest():
    """
    Copy version to latest within local cdn repository
    """
    if 'version' in CONFIG:
        version = CONFIG['version']
    else:
        tags = _get_tags()
        puts('This project has the following tags:')
        puts(tags)
    
        while True:
            version = prompt("Which version to stage as 'latest'? ").strip()        
            if not version in tags:
                warn('You must enter an existing version')
            else:
                break
    
    print 'stage_latest: %s' % version
    
    # Make sure version has been staged
    version_cdn_path = join(env.cdn_path, version)
    if not os.path.exists(version_cdn_path): 
        abort("Version '%s' has not been staged" % version)
      
    # Stage version as latest           
    latest_cdn_path = join(env.cdn_path, 'latest')
    _clean(latest_cdn_path)
    copy([{"src": version_cdn_path, "dst": latest_cdn_path}])
Exemple #18
0
def apply(obj,repo=None):
    if repo is None:

        repo = get_conf().git.remote.upstream

    cmd = ['curl',
           'https://github.com/{0}/'.format(repo),
           '|', 'git', 'am',
           '--signoff --3way' if env.sign else '--3way' ]

    if obj.startswith('http'):
        cmd[1] = obj
        if not obj.endswith('.patch'):
            cmd[1] += '.patch'
        local(' '.join(cmd))
    elif re.search('[a-zA-Z]+', obj):
        cmd[1] = cmd[1] + 'commit/' + obj + '.patch'

        local(' '.join(cmd))
        puts('[git]: merged commit {0} for {1} into {2}'.format(obj, repo, get_branch()))
    else:
        cmd[1] = cmd[1] + 'pull/' + obj + '.patch'

        local(' '.join(cmd))
        puts('[git]: merged pull request #{0} for {1} into {2}'.format(obj, repo, get_branch()))
Exemple #19
0
def wait_for_node(node, leave=False):
    """
    Waits for a node to leave or join the cluster

    Continually poll the elasticsearch cluster status API for the node
    """

    tries = DEFAULT_TRIES
    while tries > 0:
        utils.puts(
            'Waiting for node {} to {}'.format(
                node, 'leave' if leave else 'come back',
            )
        )
        data = curl_and_json(env.apis, '/_nodes/_all/info')
        for node_id, node_conf in data['nodes'].items():
            if 'host' in node_conf:
                if not leave and node_conf['host'] == node:
                    return
        else:
            if leave:
                return
            else:
                tries -= 1
                time.sleep(DEFAULT_INTERVAL)
    console.confirm(
        'Node {} never {}! Press Enter to continue, '
        'CTRL+C to abort (check output of {}/_nodes/_all/info?pretty)'.
        format(
            node,
            'left' if leave else 'came back',
            env.apis[0],
        )
    )
Exemple #20
0
def clean(output = ABS_OUTPUT_PATH):
    """ Remove old content """
    cmd = "rm -r {0}".format(output)
    with settings(warn_ony = True):
        outcome  = local(cmd)
    if outcome.failed:
        puts("Nothing found; probably already deleted.")
Exemple #21
0
def post_stop_callback(node):
    """Wait until the node leaves the cluster"""

    if env.commit:
        wait_for_node(node, leave=True)
    else:
        utils.puts('wait for node {} (noop): to leave'.format(node))
Exemple #22
0
def stage11():
    puts(yellow("adding ssh connections to local known hosts file"))
    for server in metadata.servers:
        puts(green("connecting to %s now and adding the key" % server))
        local("ssh -o StrictHostKeyChecking=no root@%s uptime" % metadata.servers[server]["ip"])

    execute(stage11)
Exemple #23
0
def help():
    puts("""
    Usage: fab command:[arg1],[arg2]

    Description:
        Deployment (and not only...) tool for work in Apache Tomcat + Maven multi-module environment

    Required:
        Apache Tomcat 6+
        Apache Maven 2+

    Commands:
        help                        - this page

        build                       - Maven package build
        war                         - copy current WAR package to Tomcat
        static                      - copy current static files to Tomcat

        tomcat:[start|stop|restart] - Tomcat management
        clean                       - clean deployed Tomcat app
        jpda                        - run Tomcat's JPDA

        test:[test profile],[name]  - run test with specified profile and class name with Maven

        full                        - 'build' + 'tomcat:stop' + 'war' + 'tomcat:start' commands coherently
    """)
Exemple #24
0
def setup_packages():
    cuisine.select_package('apt')
    puts(green('Installing Ubuntu packages'))
    with cuisine.mode_sudo():
        cuisine.package_update()
        cuisine.package_upgrade()
        cuisine.package_ensure([
            "aptitude",
            "build-essential",
            "curl",
            "git",
            "guake",
            "haskell-platform",
            "htop",
            "ibux-mozc",
            "libclang-dev",
            'libncursesw5-dev',
            "libssl-dev",
            "paco",
            "python3-dev",
            "tmux",
            "tree",
            "wget",
            "zip",
            "zsh",
            ])
Exemple #25
0
def upload_file(bucket, key_name, file_path, remote_prefix=None, policy='public-read', metadata=None):
    if not metadata:
        metadata = {}

    if remote_prefix:
        key_name = '{0}/{1}'.format(remote_prefix, key_name)

    fd = open(file_path)
    md5 = compute_md5(fd)
    fd.close()

    current_md5 = None
    current_key = bucket.lookup(key_name)
    if current_key:
        current_md5 = current_key.get_metadata('fabix-md5')
        if current_md5 == md5[0]:
            for k, v in metadata.iteritems():
                current_key.set_metadata(k, v)
            puts("Skip file {0}".format(file_path))
            return current_key

    key = bucket.new_key(key_name)

    for k, v in metadata.iteritems():
        key.set_metadata(k, v)

    key.set_metadata('fabix-md5', md5[0])

    puts("Upload file {0}".format(file_path))
    key.set_contents_from_filename(file_path, md5=md5, policy=policy)
    return key
Exemple #26
0
def rollback():
    """
        Rolls back currently deployed version to its predecessor
    """
    with cd(env.basepath):
        run('mv current/rollback rollback')
        run('mv current undeployed')
        run('mv rollback current')
        version = run('readlink current')
        previous = run('readlink undeployed')
        puts(green('>>> Rolled back from %(previous)s to %(version)s' % { 'previous': previous, 'version': version }))
        run('rm -fr %s' % previous)
        run('rm undeployed')
        sudo('service nginx reload')
    with cd(env.nodejs):
        for n in [1, 2]:
            with settings(warn_only=True):
                sudo('stop nodejs N=%s' % n)
            run('mv instance%s/rollback rollback%s' % (n, n))
            run('mv instance%s undeployed' % n)
            run('mv rollback%s instance%s' % (n, n))
            version = run('readlink instance%s' % n)
            previous = run('readlink undeployed')
            puts(green('>>> Rolled back nodejs %(n)s from %(previous)s to %(version)s' % { 'n': n, 'previous': previous, 'version': version }))
            run('rm -fr %s' % previous)
            run('rm undeployed')
            sudo('start nodejs N=%s' % n)
Exemple #27
0
def get_repository():
    if run("test -d %s" % env.REPOSITORY_FOLDER, quiet=True).failed:
        puts("Creating repository folder.")
        run("mkdir -p %s" % env.REPOSITORY_FOLDER)
    if not exists(posixpath.join(env.REPOSITORY_FOLDER, '.git')):
        puts("Cloning from repository.")
        run("git clone %s %s" % (env.GIT_REPOSITORY, env.REPOSITORY_FOLDER))
Exemple #28
0
def production():
    """
        Execute the other actions on production environment
    """
    puts(green('>>> Running on Production!'))
    env.hosts = ['web1.precog.com']
    puts(green('Servers: %s' % ", ".join(env.hosts)))
Exemple #29
0
def test_puts_with_user_output_off():
    """
    puts() shouldn't print input to sys.stdout if "user" output level is off
    """
    output.user = False
    puts("You aren't reading this.")
    eq_(sys.stdout.getvalue(), "")
Exemple #30
0
def openerp_rsyslog():
    require.files.file(
        '/etc/rsyslog.d/20-openerp.conf', 
        source='files/etc/rsyslog.d/20-openerp.conf', 
        owner='root', 
        group='root', 
        mode=644, 
        use_sudo = True
    )
    require.files.file(
        '/etc/init.d/openerp',
        source='files/etc/init.d/openerp',
        owner='root',
        group='root',
        mode='755',
        use_sudo=True
    )
    require.files.directory(
        '/var/log/openerp',
        mode=777, 
        use_sudo=True
    )
    require.service.restarted('rsyslog')
    ## we need a full stop and start as we updated /etc/init.d/openerp file
    puts('Stopping openerp')
    service.stop('openerp')
    puts('Starting openerp')
    service.start('openerp')
Exemple #31
0
def reboot(wait):
    """
    Reboot the remote system, disconnect, and wait for ``wait`` seconds.

    After calling this operation, further execution of `run` or `sudo` will
    result in a normal reconnection to the server, including any password
    prompts.

    .. versionadded:: 0.9.2
    """
    sudo('reboot')
    client = connections[env.host_string]
    client.close()
    if env.host_string in connections:
        del connections[env.host_string]
    if output.running:
        puts("Waiting for reboot: ", flush=True, end='')
        per_tick = 5
        for second in range(int(wait / per_tick)):
            puts(".", show_prefix=False, flush=True, end='')
            time.sleep(per_tick)
        puts("done.\n", show_prefix=False, flush=True)
Exemple #32
0
def show(role=None, i=True, a=None, nested=False):
    """Show recipes

    :param role: show single role
    :param i: ifo flag
    """
    roles_path = get_roles_dir()

    # Show details about specified recipe
    if role and os.path.exists(get_role_path(role)):
        if i:
            info(role)
        else:
            puts(colors.blue("Role <{0}> on {1}".format(role, get_role_path(role))))
        return

    puts(colors.blue("Show all roles <{0}>".format(roles_path)))

    for role in get_roles_list():
        if i:
            info(role)
        else:
            puts(colors.blue("Role <{0}> on {1}".format(role, get_role_path(role))))
Exemple #33
0
def commit_and_sync(comment=None):
    """git commit and sync"""
    output_list = local('git status', True).split('\n')
    branch = output_list[0].replace('On branch ', '')
    if branch in ['develop', 'master']:
        puts('不允许在 {} 分支 用 {} 命令直接操作'.format(yellow(branch), get_function_name()))
    elif 'nothing to commit' in output_list[-1]:
        puts('{} 分支没有变动, 不需要提交'.format(yellow(branch)))
        if 'is ahead of' in output_list[1]:
            puts('同步 {} 分支'.format(yellow(branch)))
            local_proxy('git push')
    else:
        local('git reset')
        delete_files = [x.strip() for x in output_list if x.find('deleted:') != -1]
        for file in delete_files:
            filename = file.split(':')[1].strip()
            local('git rm {}'.format(filename))
        local('git add .')
        if not comment:
            comment = raw_input('请输入提交的注解: ')
        local('git status')
        local('git commit -m "{}"'.format(comment))
        local_proxy('git push')
Exemple #34
0
def print_result(execute_res):
    """ Print task results classed by return value/error code """
    import json
    result_dict = inv_dict(execute_res)
    puts(json.dumps(result_dict, indent=4))
Exemple #35
0
def restart_web_server():
    puts(green('Reloading the supervisor process'))

    sudo('supervisorctl reload')
Exemple #36
0
def install(role=None, pypi_option=env.pypi_option):
    """初始化工具包, 例如 fab install:ios"""
    if not role:
        role = raw_input('请输入角色 [all, android, ios, macos, node, python, django, wiki, jekyll]: ')
    puts(green('安装 Fabric ( 修正 six, 以免以后执行 fab update 报错 ), isort, requests'))  # https://github.com/pypa/pip/issues/3165
    local('sudo -H pip2 install -U Fabric{} --ignore-installed six'.format(pypi_option))
    local('sudo -H pip2 install isort requests{}'.format(pypi_option))
    if not os.path.exists('/usr/local/bin/brew'):
        puts(green('安装 Homebrew'))
        local('/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"')
    puts(green('安装 bash-completion, Tree'))
    local('brew install bash-completion tree')
    puts(green('安装 Ruby, 配置 RubyGems'))
    local('brew install ruby')  # 系统原版某些gem安装不上
    local('brew link --overwrite ruby')
    local('gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/')
    local('sudo gem update --system')
    # puts(green('安装 GitHub Desktop, Google Chrome, Visual Studio Code'))
    # local('brew cask install github google-chrome visual-studio-code')
    puts(green('安装 Charles, Dash, Postman'))
    local('brew cask install bearychat charles dash postman')
    if role.lower() in ['wiki']:
        puts(green('安装 gollum'))  # https://github.com/gollum/gollum/wiki/Installation
        local('brew install icu4c')
        local('sudo gem install charlock_holmes -- --with-icu-dir=/usr/local/opt/icu4c')
        local('sudo gem install gollum')
    if role.lower() in ['jekyll']:
        puts(green('安装 Jekyll, Bundler'))
        local('sudo gem install jekyll bundler')  # https://jekyllrb.com
    if role.lower() in ['all', 'android', 'django']:
        puts(green('安装 Java'))
        local('brew cask install java')
    if role.lower() in ['all', 'mobile', 'ios', 'macos']:
        puts(green('安装 CocoaPods'))
        local('sudo gem install cocoapods')
        puts(green('安装 Carthage, SwiftFormat, SwiftLint'))
        local('brew install carthage swiftformat swiftlint')
    if role.lower() in ['all', 'mobile', 'android']:
        puts(green('安装 Android Studio'))
        local('brew cask install android-studio')
    if role.lower() in ['all', 'mobile', 'android', 'ios', 'macos']:
        puts(green('安装 fastlane'))
        local('sudo gem install fastlane -NV')  # gem方式 官方文档有参数 -NV, brew方式被墙且无法更新
    if role.lower() in ['all', 'node']:
        puts(green('安装 Node.js'))
        local('brew install node')
        puts(green('全局安装 BrowserSync, gulp, JS Beautifier'))
        local('npm install -g browser-sync gulp-cli gulp js-beautify')
    if role.lower() in ['all', 'python', 'django']:
        puts(green('安装 Python'))
        local('brew install python')
        puts(green('安装 Pylint, Flake8, YAPF, twine, virtualenvwrapper'))  # 上传到pypi需要twine
        local('sudo -H pip3 install pylint flake8 yapf twine virtualenvwrapper{}'.format(pypi_option))
    if role.lower() in ['all', 'django']:
        puts(green('安装 MySQL, Memcached, libMemcached, Redis, gettext'))
        local('brew install mysql memcached libmemcached redis gettext')
        puts(green('安装 Transifex Command-Line Tool'))
        local('sudo -H pip3 install transifex-client{}'.format(pypi_option))
        puts(green('安装 Docker, MySQL Workbench'))
        local('brew cask install docker mysqlworkbench')
    local('brew cleanup')
    local('brew cask cleanup')
    local('sudo gem clean')
    puts(green('配置 .bash_profile'))
    curl('-o .bash_profile https://raw.githubusercontent.com/nyssance/Free/master/bash_profile')
Exemple #37
0
def update(pypi_option=env.pypi_option):
    """更新工具包"""
    puts(cyan('更新自己 当前版本 {} 更新在下次执行时生效'.format(env.version)))
    curl('-O https://raw.githubusercontent.com/nyssance/Free/master/fabfile.py')
    puts(cyan('更新 bash_profile'))
    curl('-o .bash_profile https://raw.githubusercontent.com/nyssance/Free/master/bash_profile')
    puts(cyan('更新 Homebrew'))
    local('brew upgrade')
    local('brew cleanup')
    if os.path.exists('/usr/local/bin/node'):
        puts(cyan('更新 npm'))
        local('npm update -g')
    if os.path.exists('/usr/local/bin/pip3'):
        puts(cyan('更新 pip, Pylint, Flake8, YAPF, twine, virtualenvwrapper'))
        local('sudo -H pip3 install -U pip pylint flake8 yapf twine virtualenvwrapper{}'.format(pypi_option))
        puts(cyan('更新 Transifex Command-Line Tool'))
        local('sudo -H pip3 install -U transifex-client{}'.format(pypi_option))
    puts(cyan('更新 Fabric, isort, requests'))
    # local('sudo -H pip2 install -U pip{}'.format(pypi_option))  # 更新pip2会引起pip3失效
    local('sudo -H pip2 install -U Fabric isort requests{}'.format(pypi_option))
    puts(cyan('更新 RubyGems'))
    local('sudo gem update --system')
    local('sudo gem update')
    local('sudo gem clean')
    local('brew cask outdated')
    puts(cyan('更新完毕\n如果更新了python, 需要重新创建虚拟环境\n如果更新了ruby, 可能需要 brew link --overwrite ruby'))
Exemple #38
0
    def note(msg): puts(green(msg), flush=True)

    def do_node(addr, peer_a, peer_b):
Exemple #39
0
    def etchosts(self):
        for server in sorted(self._metadata.servers):
            puts("%s %s.%s %s" % (self._metadata.servers[server]["ip"], server,
                                  self._metadata.config["domain"], server))
            puts("%s.%s %s.tinc.%s" %
                 (self._metadata.config["vpn_base"],
                  self._metadata.config["idx"][server], server,
                  self._metadata.config["domain"]))
            puts("%s %s.dockernet.%s" %
                 (CIDR(self._metadata.servers[server]["dockernet"])[1], server,
                  self._metadata.config["domain"]))

        for container in sorted(self._metadata.containers):
            role = self._metadata.containers[container]["role"]
            container_ip = self._metadata.containers[container]["ip"]
            server = self._metadata.containers[container]["server"]

            puts("%s %s_%s.%s %s_%s" %
                 (container_ip, role, server, self._metadata.config["domain"],
                  role, server))
            puts("%s %s.%s" % (container_ip, role, server))
            puts("%s %s.%s.dockernet.%s" %
                 (container_ip, role, server, self._metadata.config["domain"]))
Exemple #40
0
 def on_update():
     puts('Added APT repository: %s' % source_line)
     update_index()
Exemple #41
0
def deploy():
    """ deploy na serverju
    uporaba:
    $ fab live deploy
    """
    with prefix('source /srv/django-envs/mothra/bin/activate'):
        with cd('/srv/django-projects/mothra'):
            puts(yellow("[Pulling from origin, on branch %s]" %
                        (env.branch, )))
            run('git pull origin %s' % (env.branch, ))
            run('git checkout %s' % (env.branch, ))

            puts(yellow("[Installing packages]"))

            run('pip install -qr requirements.txt')

            puts(yellow("[Migrating apps]"))
            for app in apps_to_migrate:
                puts("--> [Migrating %s]" % (app, ))
                run('python manage.py migrate %s --no-initial-data' % (app, ))

            puts(yellow("[Collecting static files]"))
            run("python manage.py collectstatic --noinput")

            puts(yellow("[Auto importing packages]"))
            run("python manage.py auto_import_packages")

        with cd('/srv/django-projects/supervisor'):
            puts(yellow("[Restarting the run streams daemon"))
            run('supervisorctl restart runstreams')

        with cd('/srv/django-projects/supervisor'):
            puts(yellow("[Restarting the gunicorn daemon"))
            run('supervisorctl restart mothra')
Exemple #42
0
def setup():
    """Initial setup of the project. Use ``setup_with_production_data`` instead
    if the project is already installed on a server"""
    if os.path.exists('venv'):
        puts(red('It seems that this project is already set up, aborting.'))
        return 1

    if not os.path.exists('venv'):
        execute('local.create_virtualenv')
    execute('local.frontend_tools')
    if not os.path.exists('.env'):
        execute('local.create_dotenv')
    execute('local.create_database')

    puts(green('Initial setup has completed successfully!', bold=True))
    puts(green('Next steps:'))
    puts(green('- Update the README: edit README.rst'))
    puts(
        green(
            '- Create a superuser: venv/bin/python manage.py createsuperuser'))
    puts(green('- Run the development server: fab dev'))
    puts(green('- Create a Bitbucket repository: fab git.init_bitbucket'))
    puts(green('- Configure a server for this project: fab server.setup' %
               env))
Exemple #43
0
def clonedb(original_db, clone_db, region="ap-northeast-1"):
    """ [deploy] Creates a clone of the current production DB.

    Usage from the command line requires fab's special arg syntax, e.g.:
        $ fab clonedb:'staging','test-db-one'
    """
    # Make sure the DB exists first
    output = local("aws rds describe-db-instances --region %s" % region,
                   capture=True)
    instances = json.loads(output)
    orig_instance = None
    for i in instances['DBInstances']:
        if i['DBInstanceIdentifier'] == original_db:
            orig_instance = i
        # Note: we don't else/elif here so we can ensure orig and clone are
        # different.
        if i['DBInstanceIdentifier'] == clone_db:
            abort("Target clone db name '%s' is already in use!" % clone_db)
    if not orig_instance:
        abort("The database '%s' doesn't exist" % original_db)
    # Check that the DB is available.
    if orig_instance["DBInstanceStatus"] != "available":
        abort(
            "The database '%s' is not available, try later. (In state '%s')" %
            (original_db, orig_instance["DBInstanceStatus"]))
    # Generate the various settings we'll use later.
    if len(orig_instance['VpcSecurityGroups']) != 1:
        warn("I don't know how to handle multiple security groups, \
              leaving clone in 'default'.")
    sec_group = orig_instance['VpcSecurityGroups'][0]["VpcSecurityGroupId"]
    datestamp = datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S")
    clone_snapshot = "from-%s-for-%s-%s" % (original_db, clone_db, datestamp)
    print sec_group, clone_snapshot, clone_db, original_db
    # Create the snapshot.
    puts("Creating DB snapshot '%s', this will take a while." % clone_snapshot)
    cmd = "aws rds create-db-snapshot --db-snapshot-identifier %s \
           --db-instance-identifier %s" % (clone_snapshot, original_db)
    out = local(cmd, capture=True)
    print out
    # Spin till the snapshot has been created...
    while True:
        cmd = ("aws rds describe-db-snapshots --db-snapshot-identifier %s" %
               clone_snapshot)
        snapshot = json.loads(local(cmd, capture=True))["DBSnapshots"][0]
        state = snapshot["Status"]
        progress = snapshot["PercentProgress"]
        if state == "available":
            puts("Creating snapshot complete.")
            break
        puts("    %s: %s%% complete" % (state, progress))
        time.sleep(60)
    # Now create the new DB.
    puts("Creating clone DB from snapshot, this'll also take a while.")
    cmd = ("aws rds restore-db-instance-from-db-snapshot \
           --db-snapshot-identifier %s --db-instance-identifier %s \
           --db-instance-class db.t2.large --no-multi-az \
           --db-subnet-group-name main" % (clone_snapshot, clone_db))
    out = local(cmd, capture=True)
    puts("Waiting for DB to be created...")
    while True:
        cmd = ("aws rds describe-db-instances --db-instance-identifier %s" %
               clone_db)
        instance = json.loads(local(cmd, capture=True))["DBInstances"][0]
        state = instance["DBInstanceStatus"]
        if state == "available":
            break
        puts("    State: %s" % state)
        time.sleep(60)
    # Update the security group.
    cmd = ("aws rds modify-db-instance --db-instance-identifier %s \
            --vpc-security-group-ids %s" % (clone_db, sec_group))
    out = local(cmd, capture=True)
    # Finally display new DB endpoint info.
    cmd = ("aws rds describe-db-instances --db-instance-identifier %s" %
           clone_db)
    instance = json.loads(local(cmd, capture=True))["DBInstances"][0]
    hostname = instance["Endpoint"]["Address"]
    puts("Your clone DB hostname is '%s'." % hostname)
    puts("Login info is the same as the DB you cloned.")
    puts("Clean up DBs and snapshots when you're done. This shit ain't free.")
Exemple #44
0
def configure_firewall():
    puts(green('Configuring server firewall'))

    sudo('ufw allow proto tcp from any to any port 22')
    sudo('ufw allow 80')
    sudo('ufw --force enable')
Exemple #45
0
def setup_users():
    puts(green('Creating Ubuntu users'))

    user_ensure('redacted_webapp')
Exemple #46
0
 def remote_has_local_branch(self, remote_path, local_branch):
     with cd(remote_path):
         git_branches = run('git branch')
         puts(cyan(git_branches))
Exemple #47
0
def deploy(git_ref, upgrade=False):
    """Deploy project.

    Deploy the code of the given git reference to the previously selected
    environment.

    Args:
        upgrade(Optional[bool]):
            Pass ``upgrade=True`` to upgrade the versions of the already
            installed project requirements (with pip)
        git_ref(str): name branch you make deploy.

    Example:
        >>>fab environment:vagrant deploy:devel.
    """
    require('hosts', 'user', 'group', 'site_dir', 'django_settings')

    # Retrives git reference metadata and creates a temp directory with the
    # contents resulting of applying a ``git archive`` command.
    message = white('Creating git archive from {0}'.format(git_ref), bold=True)
    with cmd_msg(message):
        repo = ulocal('basename `git rev-parse --show-toplevel`', capture=True)
        commit = ulocal('git rev-parse --short {0}'.format(git_ref),
                        capture=True)
        branch = ulocal('git rev-parse --abbrev-ref HEAD', capture=True)

        tmp_dir = '/tmp/blob-{0}-{1}/'.format(repo, commit)

        ulocal('rm -fr {0}'.format(tmp_dir))
        ulocal('mkdir {0}'.format(tmp_dir))
        ulocal('git archive {0} ./src | tar -xC {1} --strip 1'.format(
            commit, tmp_dir))

    # Uploads the code of the temp directory to the host with rsync telling
    # that it must delete old files in the server, upload deltas by checking
    # file checksums recursivelly in a zipped way; changing the file
    # permissions to allow read, write and execution to the owner, read and
    # execution to the group and no permissions for any other user.
    with cmd_msg(white('Uploading code to server...', bold=True)):
        ursync_project(local_dir=tmp_dir,
                       remote_dir=env.site_dir,
                       delete=True,
                       default_opts='-chrtvzP',
                       extra_opts='--chmod=750',
                       exclude=["*.pyc", "env/", "cover/"])

    # Performs the deployment task, i.e. Install/upgrade project
    # requirements, syncronize and migrate the database changes, collect
    # static files, reload the webserver, etc.
    message = white('Running deployment tasks', bold=True)
    with cmd_msg(message, grouped=True):
        with virtualenv():

            message = white('Installing Python requirements with pip')
            with cmd_msg(message, spaces=2):
                run('pip install -{0}r ./requirements/production.txt'.format(
                    'U' if upgrade else ''))

            message = white('Migrating database')
            with cmd_msg(message, spaces=2):
                run('python manage.py migrate --noinput')

            message = white('Collecting static files')
            with cmd_msg(message, spaces=2):
                run('python manage.py collectstatic --noinput')

            message = white('Setting file permissions')
            with cmd_msg(message, spaces=2):
                run('chgrp -R {0} .'.format(env.group))
                run('chgrp -R {0} ../media'.format(env.group))

            message = white('Restarting webserver')
            with cmd_msg(message, spaces=2):
                run('touch ../reload')

            message = white('Registering deployment')
            with cmd_msg(message, spaces=2):
                register_deployment(commit, branch)

    # Clean the temporary snapshot files that was just deployed to the host
    message = white('Cleaning up...', bold=True)
    with cmd_msg(message):
        ulocal('rm -fr {0}'.format(tmp_dir))

    puts(green(SUCCESS_ART), show_prefix=False)
    puts(white('Code from {0} was succesfully deployed to host {1}'.format(
        git_ref, ', '.join(env.hosts)),
               bold=True),
         show_prefix=False)
Exemple #48
0
def create(instance_name):
    """
    Create a GCP instance `instance_name` and associate a static IP with it.
    """
    # puts(green('You may need to run `gcloud init` before running this command.'))
    # STEP 1: reserve a static IP address
    reserve_ip_cmd =  'gcloud compute addresses create ' + instance_name
    reserve_ip_cmd += ' --region ' + GCP_REGION
    local(reserve_ip_cmd)
    #
    # STEP 2: provision instance
    create_cmd =  'gcloud compute instances create ' + instance_name
    create_cmd += ' --zone ' + GCP_ZONE
    create_cmd += ' --machine-type f1-micro'
    create_cmd += ' --boot-disk-size ' + GCP_BOOT_DISK_SIZE
    create_cmd += ' --image-project debian-cloud --image debian-8-jessie-v20170619'
    create_cmd += ' --address ' + instance_name
    create_cmd += ' --tags http-server,https-server'
    create_cmd += ' --format json'
    cmd_out = local(create_cmd, capture=True)
    cmd_result = json.loads(cmd_out)
    new_ip = cmd_result[0]['networkInterfaces'][0]['accessConfigs'][0]['natIP']
    puts(green('Created demo instance ' + instance_name + ' with IP ' + new_ip))
    puts(green('Add this paragraph to the dict `env.roledefs` in `fabfile.py`:'))
    puts(blue("    '%s': {"                                     % instance_name    ))
    puts(blue("        'hosts':['%s'],"                         % new_ip           ))
    puts(blue("        'channels_to_import': ['<channel_id>'],"                    ))
    puts(blue("        'facility_name': '" + instance_name.replace('-', ' ') + "',"))
    puts(blue("        'hostname': '%s.learningequality.org',"  % instance_name    ))
    puts(blue("    },"                                                             ))
Exemple #49
0
def install_squid_proxy():
    """
    Install squid3 package and starts it so demoserver can be used as HTTP proxy.
    Note this rquires opening port 3128 on from the GCP console for this server,
    which can be done by applying the "Network tag" `allow-http-proxy-3128`.
    """
    with settings(warn_only=True), hide('stdout'):
        sudo('apt-get update -qq')
        sudo('apt-get -y install squid3')
    put('config/etc_squid_squid.conf', '/etc/squid/squid.conf', use_sudo=True)
    sudo('chown root:root /etc/squid/squid.conf')
    sudo('service squid restart')
    puts('\n')
    puts(green('Proxy service started on ' + str(env.host)))
    puts(blue('Next steps:'))
    puts(blue('  1. Visit https://console.cloud.google.com/compute/instances?project=kolibri-demo-servers&organizationId=845500209641&instancessize=50'))
    puts(blue('  2. Add the Network Tag  "allow-http-proxy-3128" to the server ' + env.effective_roles[0]))
    puts(blue('  3. Append {}:{} to the PROXY_LIST used for cheffing.'.format(env.host, '3128')))
Exemple #50
0
def restart_kolibri(post_restart_sleep=0):
    sudo('supervisorctl restart kolibri')
    if post_restart_sleep > 0:
        puts(green('Taking a pause for ' + str(post_restart_sleep) + 'sec to let migrations run...'))
        time.sleep(post_restart_sleep)
Exemple #51
0
def h():
    """atuo exc world"""
    puts('*' * 50)
    puts(cyan('  Fabric 使用指南\n'))
    puts(green('  查看所有命令: fab -l'))
    puts(green('  查看命令: fab -d 命令'))
    puts(yellow('  带参数命令请输入: fab 命令:参数'))
    puts('*' * 50)
Exemple #52
0
def deploy():
    api.require('environment')

    # Check to make sure that there isn't any unchecked files
    git_status = api.local('git status --porcelain', capture=True)

    if git_status:
        utils.abort('There are unchecked files.')

    # Push the repo to the remote
    api.local('git push {0} {1}'.format(api.env.remote, api.env.branch))

    # Build the static website.
    api.local('python manage.py freeze')

    # rsync the website to the server.
    rsync_project(
        remote_dir=api.env.html_dir,
        local_dir=api.env.local_build_dir,
        delete=True,
        exclude=['static/scss/', 'static/bower/', 'static/.webassets-cache/'])

    # Draw a ship
    utils.puts("               |    |    |               ")
    utils.puts("              )_)  )_)  )_)              ")
    utils.puts("             )___))___))___)\            ")
    utils.puts("            )____)____)_____)\\          ")
    utils.puts("          _____|____|____|____\\\__      ")
    utils.puts(" ---------\                   /--------- ")
    utils.puts("   ^^^^^ ^^^^^^^^^^^^^^^^^^^^^           ")
    utils.puts("     ^^^^      ^^^^     ^^^    ^^        ")
    utils.puts("          ^^^^      ^^^                  ")
Exemple #53
0
def _colored_puts(msg, color, with_stars):
    if with_stars:
        puts(color("******** %s ********" % (msg, )))
    else:
        puts(color(msg))
Exemple #54
0
def start_ami_instance(ami_id, instance_name):
    """
    Start an AMI instance running
    :param ami_id:
    :param instance_name:
    """
    puts('Starting the instance {0} from id {1}'.format(instance_name, ami_id))

    # This relies on a ~/.boto file holding the '<aws access key>', '<aws secret key>'
    ec2_connection = boto.connect_ec2()

    if env.subnet_id == '':
        reservations = ec2_connection.run_instances(
            ami_id,
            instance_type=INSTANCE_TYPE,
            key_name=KEY_NAME,
            security_groups=SECURITY_GROUPS)
    elif env.subnet_id == 'subnet-85af9fea':
        reservations = ec2_connection.run_instances(
            ami_id,
            instance_type=INSTANCE_TYPE,
            subnet_id=env.subnet_id,
            key_name=KEY_NAME_VPC,
            security_group_ids=PROD_SECURITY_GROUPS_VPC)
    else:
        reservations = ec2_connection.run_instances(
            ami_id,
            instance_type=INSTANCE_TYPE,
            subnet_id=env.subnet_id,
            key_name=KEY_NAME_VPC,
            security_group_ids=TEST_SECURITY_GROUPS_VPC)

    instance = reservations.instances[0]
    # Sleep so Amazon recognizes the new instance
    for i in range(4):
        fastprint('.')
        time.sleep(5)

    # Are we running yet?
    while not instance.update() == 'running':
        fastprint('.')
        time.sleep(5)

    # Sleep a bit more Amazon recognizes the new instance
    for i in range(4):
        fastprint('.')
        time.sleep(5)
    puts('.')

    ec2_connection.create_tags([instance.id],
                               {'Name': '{0}'.format(instance_name)})

    if env.subnet_id != '':
        puts('Allocating public IP address.')
        allocation = ec2_connection.allocate_address('vpc')
        time.sleep(5)
        if not ec2_connection.associate_address(
                public_ip=None,
                instance_id=instance.id,
                allocation_id=allocation.allocation_id):
            abort('Could not associate the IP to the instance {0}'.format(
                instance.id))

        # Give AWS time to switch everything over
        time.sleep(10)
        instance.update(True)

    # The instance is started, but not useable (yet)
    puts('Started the instance(s) now waiting for the SSH daemon to start.')
    for i in range(12):
        fastprint('.')
        time.sleep(5)
    puts('.')

    # Return the instance
    return instance, ec2_connection
Exemple #55
0
def hello():
    puts('*' * 60)
    puts('*  ' + cyan('  Fabric 使用指南  '.center(58, '=')) + '  *')
    puts('*' + ' ' * 58 + '*')
    puts('*' + green('  查看所有命令: fab -l'.ljust(64)) + '*')
    puts('*' + green('      查看命令: fab -d 命令'.ljust(64)) + '*')
    puts('*' + magenta('    带参数命令: fab 命令:参数'.ljust(67)) + '*')
    puts('*' + blue('  info') + red(' error ') + yellow('warning') + ' ' * 38 + '*')
    puts('*' + ' ' * 58 + '*')
    puts('*' * 60)
Exemple #56
0
def pogs_install(with_db):
    """
    Perform the tasks to install the whole BOINC server on a single machine
    """
    # Get the packages
    sudo('yum --assumeyes --quiet install {0}'.format(YUM_BOINC_PACKAGES))

    # Setup Users
    for user in env.list_of_users:
        sudo('useradd {0}'.format(user))
        sudo('mkdir /home/{0}/.ssh'.format(user))
        sudo('chmod 700 /home/{0}/.ssh'.format(user))
        sudo('chown {0}:{0} /home/{0}/.ssh'.format(user))
        sudo('mv /home/ec2-user/{0}.pub /home/{0}/.ssh/authorized_keys'.format(
            user))
        sudo('chmod 700 /home/{0}/.ssh/authorized_keys'.format(user))
        sudo('chown {0}:{0} /home/{0}/.ssh/authorized_keys'.format(user))

        # Add them to the sudoers
        sudo(
            '''su -l root -c 'echo "{0} ALL = NOPASSWD: ALL" >> /etc/sudoers' '''
            .format(user))

    nfs_mkdir('archive')
    nfs_mkdir('boinc-magphys')
    nfs_mkdir('galaxies')
    nfs_mkdir('projects')
    nfs_mkdir('logs_ami')
    run('mkdir -p /home/ec2-user/archive/to_store')

    # Clone our code
    if env.branch == '':
        run('git clone git://github.com/ICRAR/boinc-magphys.git')
    else:
        run('git clone -b {0} git://github.com/ICRAR/boinc-magphys.git'.format(
            env.branch))

    # Create the .boto file
    run('''echo "[Credentials]
aws_access_key_id = {0}
aws_secret_access_key = {1}" >> /home/ec2-user/.boto'''.format(
        env.aws_access_key_id, env.aws_secret_access_key))

    # Setup the S3 environment
    if to_boolean(env.create_s3):
        with cd('/home/ec2-user/boinc-magphys/machine-setup/boinc-pogs'):
            run('fab --set project_name={0} create_s3'.format(
                env.project_name))

    if with_db:
        # Activate the DB
        sudo('mysql_install_db')
        sudo('chown -R mysql:mysql /var/lib/mysql/*')
        sudo('chkconfig mysqld --add')
        sudo('chkconfig mysqld on')
        sudo('service mysqld start')

        # Wait for it to start up
        time.sleep(5)

        # Setup the database for recording WU's
        run('mysql --user=root < /home/ec2-user/boinc-magphys/server/src/database/create_database.sql'
            )

        # Make the BOINC project
        with cd('/home/ec2-user/boinc/tools'):
            run('./make_project -v --no_query --url_base http://{0} --db_user root {1}'
                .format(env.hosts[0], env.project_name))

        run('''echo '# DB Settings
databaseUserid = "root"
databasePassword = ""
databaseHostname = "localhost"
databaseName = "magphys"
boincDatabaseName = "{0}"' > /home/ec2-user/boinc-magphys/server/src/config/pogs.settings'''
            .format(env.project_name))

    else:
        # Setup the database for recording WU's
        run('mysql --user={0} --host={1} --password={2} < /home/ec2-user/boinc-magphys/server/src/database/create_database.sql'
            .format(env.db_username, env.db_host_name, env.db_password))

        # Make the BOINC project
        with cd('/home/ec2-user/boinc/tools'):
            run('./make_project -v --no_query --drop_db_first --url_base http://{0} --db_user {1} --db_host={2} --db_passwd={3} {4}'
                .format(env.hosts[0], env.db_username, env.db_host_name,
                        env.db_password, env.project_name))

        run('''echo '# DB Settings
databaseUserid = "{0}"
databasePassword = "******"
databaseHostname = "{2}"
databaseName = "magphys"
boincDatabaseName = "{3}"' > /home/ec2-user/boinc-magphys/server/src/config/pogs.settings'''
            .format(env.db_username, env.db_password, env.db_host_name,
                    env.project_name))

    run('''echo '# Work Generation settings
min_pixels_per_file = "15"
row_height = "7"
threshold = "1000"
high_water_mark = "400"
report_deadline = "7"

# Archive settings
delete_delay = "5"
boinc_statistics_delay = "2"

# AWS settings
ami_id = "XXX"
instance_type = "m1.small"
key_name = "XXX"
security_groups = "XXX","YYY"
subnet_ids = "XXX","YYY"

# POGS Settings
tmp = "/tmp"
boinc_project_root = "/home/ec2-user/projects/{0}"
project_name = "{0}"' >> /home/ec2-user/boinc-magphys/server/src/config/pogs.settings'''
        .format(env.project_name))

    # Copy the config files
    run('cp /home/ec2-user/boinc-magphys/server/config/boinc_files/db_dump_spec.xml /home/ec2-user/projects/{0}/db_dump_spec.xml'
        .format(env.project_name))
    run('cp /home/ec2-user/boinc-magphys/server/config/boinc_files/html/user/* /home/ec2-user/projects/{0}/html/user/'
        .format(env.project_name))
    run('cp /home/ec2-user/boinc-magphys/server/config/boinc_files/hr_info.txt /home/ec2-user/projects/{0}/hr_info.txt'
        .format(env.project_name))
    run('cp /home/ec2-user/boinc-magphys/server/config/boinc_files/project_files.xml /home/ec2-user/projects/{0}/project_files.xml'
        .format(env.project_name))
    run('mkdir -p /home/ec2-user/projects/{0}/html/stats_archive'.format(
        env.project_name))
    run('mkdir -p /home/ec2-user/projects/{0}/html/stats_tmp'.format(
        env.project_name))

    comment('/home/ec2-user/projects/{0}/html/ops/create_forums.php'.format(
        env.project_name),
            '^die',
            char='// ')

    run('mkdir -p /home/ec2-user/projects/{0}/html/user/logos'.format(
        env.project_name))
    run('cp /home/ec2-user/boinc-magphys/server/logos/* /home/ec2-user/projects/{0}/html/user/logos/'
        .format(env.project_name))

    # Build the validator
    with cd('/home/ec2-user/boinc-magphys/server/src/magphys_validator'):
        run('make')

    # Setup the ops area password
    with cd('/home/ec2-user/projects/{0}/html/ops'.format(env.project_name)):
        run('htpasswd -bc .htpasswd {0} {1}'.format(env.ops_username,
                                                    env.ops_password))

    with cd('/home/ec2-user/boinc-magphys/machine-setup/boinc-pogs'):
        run('fab --set project_name={0},gmail_account={1} setup_postfix'.
            format(env.project_name, env.gmail_account))
        run('fab --set project_name={0} edit_files'.format(env.project_name))
        sudo('fab --set project_name={0} setup_website'.format(
            env.project_name))

    # This is needed because the files that Apache serve are inside the user's home directory.
    run('chmod 711 /home/ec2-user')
    run('chmod -R oug+r /home/ec2-user/projects/{0}'.format(env.project_name))
    run('chmod -R oug+x /home/ec2-user/projects/{0}/html'.format(
        env.project_name))
    run('chmod ug+w /home/ec2-user/projects/{0}/log_*'.format(
        env.project_name))
    run('chmod ug+wx /home/ec2-user/projects/{0}/upload'.format(
        env.project_name))

    # Setup the forums
    with cd('/home/ec2-user/projects/{0}/html/ops'.format(env.project_name)):
        run('php create_forums.php')

    # Save the instance as an AMI
    puts("Stopping the instance")
    env.ec2_connection.stop_instances(env.ec2_instance.id, force=True)
    while not env.ec2_instance.update() == 'stopped':
        fastprint('.')
        time.sleep(5)

    puts(
        "The AMI is being created. Don't forget to terminate the instance if not needed"
    )
    env.ec2_connection.create_image(env.ec2_instance.id,
                                    env.ami_name,
                                    description='The base MAGPHYS AMI')

    puts('All done')
Exemple #57
0
def reset_passwords():
    run_local('venv/bin/python manage.py shell -c "'
              'from django.contrib.auth import get_user_model;'
              'c=get_user_model();u=c();u.set_password(\'password\');'
              'c.objects.update(password=u.password)"')
    puts(green('All users now have a password of "password".'))
Exemple #58
0
def production():
    puts(red('Using PRODUCTION settings'))
    env.hosts = ['app.redacted.com']
    env.user = '******'
    env.password = '******'
Exemple #59
0
 def new_func(*args, **kwargs):
     if not os.getuid() == 0:
         puts('You must be root to run this command, try running with sudo')
         sys.exit(1)
     return func(*args, **kwargs)
def deploy():
    """
    fab test deploy
    fab production deploy
    """
    print("Executing on %(host)s as %(user)s" % env)
    with cd(env.code_dir):
        checkout_master()
        stash()
        pull()
        npm_i()
        npm_build()
        bower_install()
        with prefix("source venv/bin/activate"):
            pip_install()
            migrate()
            collect_static()
            restart_gunicorn()
        if env.stage == 'test':
            restart_apache()
        if env.stage == 'production':
            restart_nginx()
        fix_static_permissions()
        fix_media_permissions()
    puts("               |    |    |               ")
    puts("              )_)  )_)  )_)              ")
    puts("             )___))___))___)\            ")
    puts("            )____)____)_____)\\          ")
    puts("          _____|____|____|____\\\__      ")
    puts(" ---------\                   /--------- ")
    puts("   ^^^^^ ^^^^^^^^^^^^^^^^^^^^^           ")
    puts("     ^^^^      ^^^^     ^^^    ^^        ")
    puts("          ^^^^      ^^^                  ")
    puts("           ^^^       ^^^^^^              ")