Exemplo n.º 1
0
    def init_root_password():
        root_password = get_password_for_user('mysql', 'root', purpose='Password for mysql server')

        if is_ubuntu():
            run('echo mysql-server mysql-server/root_password password \'%s\' | debconf-set-selections' % root_password,
                secrets=(root_password,))
            run('echo mysql-server mysql-server/root_password_again password \'%s\' | debconf-set-selections' % root_password,
                secrets=(root_password,))
Exemplo n.º 2
0
    def init_root_password():
        root_password = get_password_for_user('mysql', 'root', purpose='Password for mysql server')

        root_password = subprocess.list2cmdline([root_password])

        if is_ubuntu():
            run('echo mysql-server mysql-server/root_password password %s | debconf-set-selections' % root_password,
                secrets=[])
            run('echo mysql-server mysql-server/root_password_again password %s | debconf-set-selections' % root_password,
                secrets=(root_password,))
Exemplo n.º 3
0
def run_server_cmd():
    parser = argparse.ArgumentParser()
    parser.add_argument('--config', type=str, nargs='?')
    parser.set_defaults(config=None)
    parser.add_argument('--install', action='store_true', default=False)
    parser.add_argument('--add-user', action='store_true', default=False)
    args = parser.parse_args()

    if args.install:
        require_sudo()

        path = os.path.dirname(__file__) + '/templates/upstart-server.conf'
        run('cp %s /etc/init/pywizard-server.conf' % path)
        run('chmod +x /etc/init/pywizard-server.conf')
        run('start pywizard-server')
        run('status pywizard-server')

    else:

        logging.basicConfig(level=logging.INFO)

        config_file = None
        if not args.config:
            curdir_server_yml_ = os.path.curdir + '/server.yml'
            etc_pywizard_server_yml = '/etc/pywizard/server.yml'

            if os.path.exists(curdir_server_yml_):
                config_file = curdir_server_yml_
            elif os.path.exists(etc_pywizard_server_yml):
                config_file = etc_pywizard_server_yml
            else:
                sys.stderr.write("\n\n\nConfig file was not found in current directory (%s) or /etc (%s). "
                                 "You can specify it manualy with parameter '--config'" % (
                                     curdir_server_yml_,
                                     etc_pywizard_server_yml
                                 ))
                exit(1)
        else:
            config_file = args.config

        config = read_yaml_cofig(config_file)

        if args.add_user:
            run_django(config)
            execute_from_command_line(['manage.py', 'createsuperuser'])
        else:
            run_server(config)
Exemplo n.º 4
0
def mysql_dump(database, filepath, user, password, host='localhost', restore_script_path=None):
    host = host.strip()
    if not host or len(host) < 1:
        raise Exception('Bad host')

    debug('Dumping db %s into %s' % (database, filepath))
    run("mysqldump -h %s -u %s -p%s %s > %s" % (host, user, password, database, filepath))
    run('chmod 700 %s' % filepath)

    if restore_script_path:
        script = "#!/bin/bash\nmysql -h %s -u %s -p%s %s < %s" % (host, user, password, database, filepath)
        with open(restore_script_path, 'w+') as f:
            f.write(script)
        run('chmod 700 %s' % restore_script_path)
Exemplo n.º 5
0
 def init_root_password_():
     root_password = get_password_for_user('mysql', 'root', purpose='Password for mysql server')
     if is_centos():
         run("service mysqld start")
         run("mysqladmin -u root password '%s'" % root_password)
Exemplo n.º 6
0
def mysql_execute(sql, user, password, host='localhost'):
    return run(format_mysql_query(host, password, sql, user), secrets=(password,))