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):
	"Install a new Frappe site"
	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except:
		enable_scheduler = False

	install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name, admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)
	make_site_dirs()
	_install_app("frappe", verbose=verbose, set_as_patched=not source_sql)

	if frappe.conf.get("install_apps"):
		for app in frappe.conf.install_apps:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

	if install_apps:
		for app in install_apps:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

	frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
	scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
	print "*** Scheduler is", scheduler_status, "***"
	frappe.destroy()
Example #2
0
def install(db_name,
            root_login="******",
            root_password=None,
            source_sql=None,
            admin_password='******',
            force=False,
            site_config=None,
            reinstall=False,
            quiet=False):
    from frappe.installer import install_db, install_app, make_site_dirs
    verbose = not quiet

    install_db(root_login=root_login,
               root_password=root_password,
               db_name=db_name,
               source_sql=source_sql,
               admin_password=admin_password,
               verbose=verbose,
               force=force,
               site_config=site_config,
               reinstall=reinstall)
    make_site_dirs()
    install_app("frappe", verbose=verbose, set_as_patched=not source_sql)
    if frappe.conf.get("install_apps"):
        for app in frappe.conf.install_apps:
            install_app(app, verbose=verbose, set_as_patched=not source_sql)
    frappe.destroy()
Example #3
0
def _install(db_name, root_login="******", root_password=None, source_sql=None,
		admin_password = '******', force=False, site_config=None, reinstall=False, quiet=False, install_apps=None):

	from frappe.installer import install_db, install_app, make_site_dirs
	import frappe.utils.scheduler
	verbose = not quiet

	# enable scheduler post install?
	enable_scheduler = _is_scheduler_enabled()

	install_db(root_login=root_login, root_password=root_password, db_name=db_name, source_sql=source_sql,
		admin_password = admin_password, verbose=verbose, force=force, site_config=site_config, reinstall=reinstall)
	make_site_dirs()
	install_app("frappe", verbose=verbose, set_as_patched=not source_sql)

	if frappe.conf.get("install_apps"):
		for app in frappe.conf.install_apps:
			install_app(app, verbose=verbose, set_as_patched=not source_sql)

	if install_apps:
		for app in install_apps:
			install_app(app, verbose=verbose, set_as_patched=not source_sql)

	frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
	scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
	print "*** Scheduler is", scheduler_status, "***"
Example #4
0
def _install(db_name, root_login="******", root_password=None, source_sql=None,
		admin_password = '******', force=False, site_config=None, reinstall=False, quiet=False, install_apps=None):

	from frappe.installer import install_db, install_app, make_site_dirs
	import frappe.utils.scheduler

	verbose = not quiet

	# enable scheduler post install?
	enable_scheduler = _is_scheduler_enabled()

	install_db(root_login=root_login, root_password=root_password, db_name=db_name, source_sql=source_sql,
		admin_password = admin_password, verbose=verbose, force=force, site_config=site_config, reinstall=reinstall)
	make_site_dirs()
	install_app("frappe", verbose=verbose, set_as_patched=not source_sql)

	if frappe.conf.get("install_apps"):
		for app in frappe.conf.install_apps:
			install_app(app, verbose=verbose, set_as_patched=not source_sql)

	if install_apps:
		for app in install_apps:
			install_app(app, verbose=verbose, set_as_patched=not source_sql)

	frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
	scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
	print "*** Scheduler is", scheduler_status, "***"
Example #5
0
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):
	"Install a new Frappe site"
	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except:
		enable_scheduler = False

	install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name, admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)
	make_site_dirs()
	_install_app("frappe", verbose=verbose, set_as_patched=not source_sql)

	if frappe.conf.get("install_apps"):
		for app in frappe.conf.install_apps:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

	if install_apps:
		for app in install_apps:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

	frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
	scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
	print "*** Scheduler is", scheduler_status, "***"
	frappe.destroy()
Example #6
0
def install(db_name, root_login="******", root_password=None, source_sql=None,
		admin_password = '******', verbose=True, force=False, site_config=None, reinstall=False):
	from frappe.installer import install_db, install_app, make_site_dirs
	install_db(root_login=root_login, root_password=root_password, db_name=db_name, source_sql=source_sql,
		admin_password = admin_password, verbose=verbose, force=force, site_config=site_config, reinstall=reinstall)
	make_site_dirs()
	install_app("frappe", verbose=verbose)
	frappe.destroy()
Example #7
0
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):
    """Install a new Frappe site"""

    if not db_name:
        db_name = hashlib.sha1(site).hexdigest()[:16]

    from frappe.installer import install_db, make_site_dirs
    from frappe.installer import install_app as _install_app
    import frappe.utils.scheduler

    frappe.init(site=site)

    try:
        # enable scheduler post install?
        enable_scheduler = _is_scheduler_enabled()
    except:
        enable_scheduler = False

    make_site_dirs()

    try:
        installing = touch_file(get_site_path('locks', 'installing.lock'))

        install_db(root_login=mariadb_root_username,
                   root_password=mariadb_root_password,
                   db_name=db_name,
                   admin_password=admin_password,
                   verbose=verbose,
                   source_sql=source_sql,
                   force=force,
                   reinstall=reinstall)

        apps_to_install = ['frappe'] + (frappe.conf.get("install_apps")
                                        or []) + (list(install_apps) or [])
        for app in apps_to_install:
            _install_app(app, verbose=verbose, set_as_patched=not source_sql)

        frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
        frappe.db.commit()

        scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled(
        ) else "enabled"
        print "*** Scheduler is", scheduler_status, "***"

    finally:
        if os.path.exists(installing):
            os.remove(installing)

        frappe.destroy()
Example #8
0
def validate(site):
    frappe.init(site=site, sites_path=sites_path)
    make_site_dirs()
    backup()
    frappe.init(site=site, sites_path=sites_path)
    frappe.connect()
    if not executed(last_3_patch):
        raise Exception, "site not ready to migrate to version 4"
    frappe.destroy()
def validate(site):
        frappe.init(site=site, sites_path=sites_path)
        make_site_dirs()
        backup()
        frappe.init(site=site, sites_path=sites_path)
        frappe.connect()
        if not executed(last_3_patch):
                raise Exception, "site not ready to migrate to version 4"
        frappe.destroy()
Example #10
0
def install(db_name, root_login="******", root_password=None, source_sql=None,
		admin_password = '******', force=False, site_config=None, reinstall=False, quiet=False):
	from frappe.installer import install_db, install_app, make_site_dirs
	verbose = not quiet

	install_db(root_login=root_login, root_password=root_password, db_name=db_name, source_sql=source_sql,
		admin_password = admin_password, verbose=verbose, force=force, site_config=site_config, reinstall=reinstall)
	make_site_dirs()
	install_app("frappe", verbose=verbose, set_as_patched=not source_sql)
	if frappe.conf.get("install_apps"):
		for app in frappe.conf.install_apps:
			install_app(app, verbose=verbose, set_as_patched=not source_sql)
	frappe.destroy()
Example #11
0
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, source_db=False, reinstall=False,
			  db_user_allowed_host=None):
	"""Install a new Frappe site"""

	if not db_name:
		db_name = hashlib.sha1(site.encode()).hexdigest()[:16]

	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except Exception:
		enable_scheduler = False

	make_site_dirs()

	if source_db:
		source_sql = create_existing_db_backup(source_db, mariadb_root_password, mariadb_root_username)

	installing = None
	try:
		installing = touch_file(get_site_path('locks', 'installing.lock'))

		install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name,
			admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall, db_user_allowed_host=db_user_allowed_host)

		apps_to_install = ['frappe'] + (frappe.conf.get("install_apps") or []) + (list(install_apps) or [])
		for app in apps_to_install:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

		frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
		frappe.db.commit()

		scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
		print("*** Scheduler is", scheduler_status, "***")

	except frappe.exceptions.ImproperDBConfigurationError:
		_drop_site(site, mariadb_root_username, mariadb_root_password, force=True)

	finally:
		if installing and os.path.exists(installing):
			os.remove(installing)

		frappe.destroy()
Example #12
0
def main():
    backup_dir = get_backup_dir()

    if len(list_directories(backup_dir)) == 0:
        pull_backup_from_s3()

    for site in list_directories(backup_dir):
        site_slug = site.replace('.', '_')
        backups = [
            datetime.datetime.strptime(backup, DATE_FORMAT)
            for backup in list_directories(os.path.join(backup_dir, site))
        ]
        latest_backup = max(backups).strftime(DATE_FORMAT)
        files_base = os.path.join(backup_dir, site, latest_backup, '')
        files_base += latest_backup + '-' + site_slug
        site_config_path = files_base + '-site_config_backup.json'
        if not os.path.exists(site_config_path):
            site_config_path = os.path.join(backup_dir, site,
                                            'site_config.json')
        if site in get_sites():
            print('Overwrite site {}'.format(site))
            restore_database(files_base, site_config_path, site)
            restore_private_files(files_base)
            restore_files(files_base)
        else:
            site_config = get_conf_params(
                db_name='_' + hashlib.sha1(site.encode()).hexdigest()[:16],
                db_password=random_string(16))

            frappe.local.site = site
            frappe.local.sites_path = os.getcwd()
            frappe.local.site_path = os.getcwd() + '/' + site
            make_conf(
                db_name=site_config.get('db_name'),
                db_password=site_config.get('db_password'),
            )
            make_site_dirs()

            print('Create site {}'.format(site))
            restore_database(files_base, site_config_path, site)
            restore_private_files(files_base)
            restore_files(files_base)

    if frappe.redis_server:
        frappe.redis_server.connection_pool.disconnect()

    exit(0)
Example #13
0
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,
			  no_mariadb_socket=False, reinstall=False,  db_password=None, db_type=None, db_host=None,
			  db_port=None, new_site=False):
	"""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 not db_name:
		db_name = '_' + hashlib.sha1(site.encode()).hexdigest()[:16]

	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except Exception:
		enable_scheduler = False

	make_site_dirs()

	installing = touch_file(get_site_path('locks', 'installing.lock'))

	install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name,
		admin_password=admin_password, verbose=verbose, source_sql=source_sql, force=force, reinstall=reinstall,
		db_password=db_password, db_type=db_type, db_host=db_host, db_port=db_port, no_mariadb_socket=no_mariadb_socket)
	apps_to_install = ['frappe'] + (frappe.conf.get("install_apps") or []) + (list(install_apps) or [])
	for app in apps_to_install:
		_install_app(app, verbose=verbose, set_as_patched=not source_sql)

	os.remove(installing)

	frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
	frappe.db.commit()

	scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
	print("*** Scheduler is", scheduler_status, "***")
Example #14
0
def main():
    backup_dir = get_backup_dir()

    if len(list_directories(backup_dir)) == 0:
        pull_backup_from_s3()

    for site in list_directories(backup_dir):
        site_slug = site.replace('.', '_')
        backups = [
            datetime.datetime.strptime(backup, DATE_FORMAT)
            for backup in list_directories(os.path.join(backup_dir, site))
        ]
        latest_backup = max(backups).strftime(DATE_FORMAT)
        files_base = os.path.join(backup_dir, site, latest_backup, '')
        files_base += latest_backup + '-' + site_slug
        site_config_path = files_base + '-site_config_backup.json'
        if not os.path.exists(site_config_path):
            site_config_path = os.path.join(backup_dir, site,
                                            'site_config.json')
        if site in get_sites():
            restore_database(files_base, site_config_path, site)
            restore_private_files(files_base)
            restore_files(files_base)
        else:
            mariadb_root_password = get_password('MYSQL_ROOT_PASSWORD')
            if not mariadb_root_password:
                print('Variable MYSQL_ROOT_PASSWORD not set')
                exit(1)

            site_config = get_conf_params(
                db_name='_' + hashlib.sha1(site.encode()).hexdigest()[:16],
                db_password=random_string(16))

            frappe.local.site = site
            frappe.local.sites_path = os.getcwd()
            frappe.local.site_path = os.getcwd() + '/' + site
            make_conf(
                db_name=site_config.get('db_name'),
                db_password=site_config.get('db_password'),
            )
            make_site_dirs()
            restore_database(files_base, site_config_path, site)
            restore_private_files(files_base)
            restore_files(files_base)

    exit(0)
Example #15
0
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):
	"""Install a new Frappe site"""

	if not db_name:
		db_name = hashlib.sha1(site.encode()).hexdigest()[:16]

	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except Exception:
		enable_scheduler = False

	make_site_dirs()

	installing = None
	try:
		installing = touch_file(get_site_path('locks', 'installing.lock'))

		install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name,
			admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)

		apps_to_install = ['frappe'] + (frappe.conf.get("install_apps") or []) + (list(install_apps) or [])
		for app in apps_to_install:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

		frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
		frappe.db.commit()

		scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
		print("*** Scheduler is", scheduler_status, "***")

	except frappe.exceptions.ImproperDBConfigurationError:
		_drop_site(site, mariadb_root_username, mariadb_root_password, force=True)

	finally:
		if installing and os.path.exists(installing):
			os.remove(installing)

		frappe.destroy()
Example #16
0
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):
	"""Install a new Frappe site"""

	from frappe.installer import install_db, make_site_dirs
	from frappe.installer import install_app as _install_app
	import frappe.utils.scheduler

	frappe.init(site=site)

	try:
		# enable scheduler post install?
		enable_scheduler = _is_scheduler_enabled()
	except:
		enable_scheduler = False

	make_site_dirs()

	try:
		installing = touch_file(get_site_path('locks', 'installing.lock'))

		install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name,
			admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)

		apps_to_install = ['frappe'] + (frappe.conf.get("install_apps") or []) + (list(install_apps) or [])
		for app in apps_to_install:
			_install_app(app, verbose=verbose, set_as_patched=not source_sql)

		frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
		frappe.db.commit()

		scheduler_status = "disabled" if frappe.utils.scheduler.is_scheduler_disabled() else "enabled"
		print "*** Scheduler is", scheduler_status, "***"

	finally:
		os.remove(installing)
		frappe.destroy()
Example #17
0
def execute():
	make_site_dirs()
	if frappe.local.conf.backup_path and frappe.local.conf.backup_path.startswith("public"):
		raise Exception("Backups path in conf set to public directory")
Example #18
0
def execute():
    make_site_dirs()
    if frappe.local.conf.backup_path and frappe.local.conf.backup_path.startswith(
            "public"):
        raise Exception, "Backups path in conf set to public directory"