From e5a896ef00cd162f1b8db826817c7a95addc5687 Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Thu, 5 Mar 2020 23:27:15 +0530 Subject: [PATCH] feat(db): add new-site flag to use tcp/ip instead of unix socket ref frappe/bench#949 Signed-off-by: Chinmay D. Pai --- frappe/commands/site.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 89e9ab7f34..0e65b62010 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -17,34 +17,43 @@ from six import text_type @click.option('--db-port', type=int, help='Database Port') @click.option('--mariadb-root-username', default='root', help='Root username for MariaDB') @click.option('--mariadb-root-password', help='Root password for MariaDB') +@click.option('--no-mariadb-socket', is_flag=True, default=False, help='Set MariaDB host to % and use TCP/IP Socket instead of using the UNIX Socket') @click.option('--admin-password', help='Administrator password for new site', default=None) @click.option('--verbose', is_flag=True, default=False, help='Verbose') @click.option('--force', help='Force restore if site/database already exists', is_flag=True, default=False) @click.option('--source_sql', help='Initiate database with a SQL file') @click.option('--install-app', multiple=True, help='Install app after installation') def new_site(site, mariadb_root_username=None, mariadb_root_password=None, admin_password=None, - verbose=False, install_apps=None, source_sql=None, force=None, install_app=None, - db_name=None, db_type=None, db_host=None, db_port=None): + verbose=False, install_apps=None, source_sql=None, force=None, no_mariadb_socket=False, + install_app=None, db_name=None, db_type=None, db_host=None, db_port=None): "Create a new site" frappe.init(site=site, new_site=True) _new_site(db_name, site, mariadb_root_username=mariadb_root_username, mariadb_root_password=mariadb_root_password, admin_password=admin_password, verbose=verbose, install_apps=install_app, source_sql=source_sql, force=force, - db_type=db_type, db_host=db_host, db_port=db_port) + no_mariadb_socket=no_mariadb_socket, db_type=db_type, db_host=db_host, db_port=db_port) if len(frappe.utils.get_sites()) == 1: use(site) def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=None, admin_password=None, verbose=False, install_apps=None, source_sql=None, force=False, - reinstall=False, db_type=None, db_host=None, db_port=None): + no_mariadb_socket=False, reinstall=False, db_type=None, db_host=None, db_port=None): """Install a new Frappe site""" if not force and os.path.exists(site): print('Site {0} already exists'.format(site)) sys.exit(1) + if no_mariadb_socket and not db_type == "mariadb": + print('--no-mariadb-socket requires db_type to be set to mariadb.') + sys.exit(1) + + if no_mariadb_socket: + print('Using % as Database Host.') + db_host = "%" + if not db_name: db_name = '_' + hashlib.sha1(site.encode()).hexdigest()[:16]