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)
def mysql_server(**kwargs): require_sudo(reason='Only root can install mysql server.') 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,)) 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) package('mysql-server', before_install=init_root_password, after_install=init_root_password_) if is_centos(): mysql_service_name = 'mysqld' my_cnf = '/etc/my.cnf' elif is_ubuntu(): mysql_service_name = 'mysql' my_cnf = '/etc/mysql/my.cnf' else: raise NotImplemented mysql_service = service(mysql_service_name, process_name='mysqld', start=True) def restart(): mysql_service.restart() if is_centos(): shell('/sbin/chkconfig mysqld on')