Exemplo n.º 1
0
def update_code():
    """
    update source
    """
    with zch():
        with cd('/zch/src/wowhua_box'):
            sudo('hg pull -u')
Exemplo n.º 2
0
def script(name, args=None, ext=None):
    """
    Run a script in `live_scripts/bin`.

    :param str name:
        name of the script to run, including extension. E.g.,
        `query_balance.py`. Python scripts are run in zchenv.
    :param str args: args for the script.
    :param str ext: script type, one of `sh` or `py`
    """
    if not ext:
        ext = name.split('.')[-1]
        if not ext:
            abort('interpreter not set and it cannot be determined ' +
                  'from "{}"'.format(name))
    try:
        interpreter = ALLOWED_SCRIPT_TYPES[ext]
    except KeyError:
        abort('No interpreter configured for the type "{}"'.format(ext))
    else:
        if args:
            cmd = '{} {}'.format(name, args)
        else:
            cmd = name
        with cd('/zch/live_scripts/bin'):
            with zch():
                if interpreter == 'python':
                    with zchenv():
                        sudo('python {}'.format(cmd))
                elif interpreter == 'bash':
                    sudo('bash {}'.format(cmd))
Exemplo n.º 3
0
def config():
    """
    install production configuration in service's ".d" directory
    """
    with zch():
        config_dir = '/zch/live_scripts/etc/{}/'.format(env.zch_subnet)
        with zchenv():
            sudo('/zch/live_scripts/bin/link_config.py {}'.format(config_dir))
Exemplo n.º 4
0
def current():
    """
    show current version of ticket center
    """
    with zch():
        with cd('/zch/src/wowhua_box'):
            sudo('hg summary')
            sudo('whoami')
Exemplo n.º 5
0
def init_code():
    with zch():
        with settings(warn_only=True):
            if sudo('test -d /zch/src/wowhua_box').failed:
                sudo('hg clone ssh://[email protected]/lingxiaoinc/wowhua_box/ '
                     + '/zch/src/wowhua_box')
            if sudo('test -d /zch/live_scripts').failed:
                sudo(
                    'ln -s /zch/src/wowhua_box/live_scripts /zch/live_scripts')
        with cd('/zch/src/wowhua_box'):
            with zchenv():
                sudo('pip install -r requirements.txt')
    config()
Exemplo n.º 6
0
def update(rev):
    """
    update `live_scripts`; update ticket center and install new packages

    :param str rev: hg revision of ticket center to be updated to
    """
    with zch():
        with cd('/zch/src/wowhua_box'):
            sudo('hg pull')
            sudo('hg update -r {}'.format(rev))
            with zchenv():
                sudo('pip install -r requirements.txt')
        with cd('/zch/live_scripts'):
            sudo('hg pull -u')
Exemplo n.º 7
0
def setup_zch():
    with settings(warn_only=True):
        if sudo('test -d /zch').failed:
            put('./provision.sh', '/home/leopold')
            sudo('bash provision.sh')
            sudo(
                "echo '%sudo   ALL=(zch) NOPASSWD: /bin/bash' >> /etc/sudoers")
            with zch():
                sudo('mkdir -p /zch/virtualenvs /zch/src /zch/.ssh')
                sudo('virtualenv /zch/virtualenvs/zchenv')
            put('./deploy_keys/wowhua', '/zch/.ssh', use_sudo=True, mode=0600)
            put('./deploy_keys/ssh_config',
                '/zch/.ssh/config',
                use_sudo=True,
                mode=0600)
            sudo('chown zch.zch /zch/.ssh/wowhua')
            sudo('chown zch.zch /zch/.ssh/config')

            put('./cron/ntp_time',
                '/etc/cron.daily/',
                use_sudo=True,
                mode=0700)
            sudo('chown root.root /etc/cron.daily/ntp_time')