Exemplo n.º 1
0
def backup_site(site):
	"backup site"
	from bench.utils import get_sites, backup_site
	if not site in get_sites(bench='.'):
		print 'site not found'
		sys.exit(1)
	backup_site(site, bench='.')
Exemplo n.º 2
0
def backup_site(site):
    "backup site"
    from bench.utils import get_sites, backup_site
    if not site in get_sites(bench='.'):
        print 'site not found'
        sys.exit(1)
    backup_site(site, bench='.')
Exemplo n.º 3
0
Arquivo: utils.py Projeto: wy/bench
def backup_site(site):
    "backup site"
    from bench.utils import get_sites, backup_site
    if site not in get_sites(bench_path='.'):
        print('site not found')
        sys.exit(1)
    backup_site(site, bench_path='.')
Exemplo n.º 4
0
def get_sites_with_config(bench_path):
    from bench.config.common_site_config import get_config
    from bench.config.site_config import get_site_config

    sites = get_sites(bench_path=bench_path)
    dns_multitenant = get_config(bench_path).get('dns_multitenant')

    ret = []
    for site in sites:
        site_config = get_site_config(site, bench_path=bench_path)
        ret.append({
            "name":
            site,
            "port":
            site_config.get('nginx_port'),
            "ssl_certificate":
            site_config.get('ssl_certificate'),
            "ssl_certificate_key":
            site_config.get('ssl_certificate_key')
        })

        if dns_multitenant and site_config.get('domains'):
            for domain in site_config.get('domains'):
                # domain can be a string or a dict with 'domain', 'ssl_certificate', 'ssl_certificate_key'
                if isinstance(domain, basestring):
                    domain = {'domain': domain}

                domain['name'] = site
                ret.append(domain)

    use_wildcard_certificate(bench_path, ret)

    return ret
Exemplo n.º 5
0
def setup_manager(yes=False, port=23624, domain=None):
	"Setup bench-manager.local site with the bench_manager app installed on it"
	from six.moves import input
	create_new_site = True
	if 'bench-manager.local' in os.listdir('sites'): 
		ans = input('Site aleady exists. Overwrite existing new site? [Y/n]: ')
		while ans.lower() not in ['y', 'n', '']:
			ans = input('Please type "y" or "n". Site aleady exists. Overwrite existing new site? [Y/n]: ')
		if ans=='n': create_new_site = False
	if create_new_site: exec_cmd("bench new-site --force bench-manager.local")

	if 'bench_manager' in os.listdir('apps'):
		print('App aleady exists. Skipping downloading the app')
	else: 
		exec_cmd("bench get-app bench_manager")

	exec_cmd("bench --site bench-manager.local install-app bench_manager")

	from bench.config.common_site_config import get_config
	bench_path = '.'
	conf = get_config(bench_path)
	if conf.get('restart_supervisor_on_update') or conf.get('restart_systemd_on_update'):
		# implicates a production setup or so I presume
		if not domain:
			print("Please specify the site name on which you want to host bench-manager using the 'domain' flag")
			sys.exit(1)
	
		from bench.utils import get_sites, get_bench_name
		bench_name = get_bench_name(bench_path)

		if domain not in get_sites(bench_path):
			raise Exception("No such site")

		from bench.config.nginx import make_bench_manager_nginx_conf
		make_bench_manager_nginx_conf(bench_path, yes=yes, port=port, domain=domain)
Exemplo n.º 6
0
def get_sites_with_config(bench_path):
	from bench.config.common_site_config import get_config
	from bench.config.site_config import get_site_config

	sites = get_sites(bench_path=bench_path)
	dns_multitenant = get_config(bench_path).get('dns_multitenant')

	ret = []
	for site in sites:
		site_config = get_site_config(site, bench_path=bench_path)
		ret.append({
			"name": site,
			"port": site_config.get('nginx_port'),
			"ssl_certificate": site_config.get('ssl_certificate'),
			"ssl_certificate_key": site_config.get('ssl_certificate_key')
		})

		if dns_multitenant and site_config.get('domains'):
			for domain in site_config.get('domains'):
				# domain can be a string or a dict with 'domain', 'ssl_certificate', 'ssl_certificate_key'
				if isinstance(domain, basestring):
					domain = { 'domain': domain }

				domain['name'] = site
				ret.append(domain)

	use_wildcard_certificate(bench_path, ret)

	return ret
Exemplo n.º 7
0
def set_site_config_nginx_property(site,
                                   config,
                                   bench_path='.',
                                   gen_config=True):
    if site not in get_sites(bench_path=bench_path):
        raise Exception("No such site")
    update_site_config(site, config, bench_path=bench_path)
    if gen_config:
        make_nginx_conf(bench_path=bench_path)
Exemplo n.º 8
0
def get_sites_with_config(bench_path):
    from bench.config.common_site_config import get_config
    from bench.config.site_config import get_site_config

    sites = get_sites(bench_path=bench_path)
    dns_multitenant = get_config(bench_path).get('dns_multitenant')

    ret = []
    for site in sites:
        try:
            site_config = get_site_config(site, bench_path=bench_path)
        except Exception as e:
            strict_nginx = get_config(bench_path).get('strict_nginx')
            if strict_nginx:
                print(
                    "\n\nERROR: The site config for the site {} is broken.".
                    format(site),
                    "If you want this command to pass, instead of just throwing an error,",
                    "You may remove the 'strict_nginx' flag from common_site_config.json or set it to 0",
                    "\n\n")
                raise (e)
            else:
                print(
                    "\n\nWARNING: The site config for the site {} is broken.".
                    format(site),
                    "If you want this command to fail, instead of just showing a warning,",
                    "You may add the 'strict_nginx' flag to common_site_config.json and set it to 1",
                    "\n\n")
                continue

        ret.append({
            "name":
            site,
            "port":
            site_config.get('nginx_port'),
            "ssl_certificate":
            site_config.get('ssl_certificate'),
            "ssl_certificate_key":
            site_config.get('ssl_certificate_key')
        })

        if dns_multitenant and site_config.get('domains'):
            for domain in site_config.get('domains'):
                # domain can be a string or a dict with 'domain', 'ssl_certificate', 'ssl_certificate_key'
                if isinstance(domain, str) or isinstance(domain, unicode):
                    domain = {'domain': domain}

                domain['name'] = site
                ret.append(domain)

    use_wildcard_certificate(bench_path, ret)

    return ret
Exemplo n.º 9
0
def get_sites_with_config(bench_path):
	sites = get_sites(bench_path=bench_path)
	ret = []
	for site in sites:
		site_config = get_site_config(site, bench_path=bench_path)
		ret.append({
			"name": site,
			"port": site_config.get('nginx_port'),
			"ssl_certificate": site_config.get('ssl_certificate'),
			"ssl_certificate_key": site_config.get('ssl_certificate_key')
		})
	return ret
Exemplo n.º 10
0
def get_sites_with_config(bench_path):
	sites = get_sites(bench=bench_path)
	ret = []
	for site in sites:
		site_config = get_site_config(site, bench_path=bench_path)
		ret.append({
			"name": site,
			"port": site_config.get('nginx_port'),
			"ssl_certificate": site_config.get('ssl_certificate'),
			"ssl_certificate_key": site_config.get('ssl_certificate_key')
		})
	return ret
Exemplo n.º 11
0
def setup_manager(yes=False, port=23624, domain=None):
    from six.moves import input
    from bench.utils import get_sites
    from bench.config.common_site_config import get_config
    from bench.config.nginx import make_bench_manager_nginx_conf

    create_new_site = True

    if "bench-manager.local" in os.listdir("sites"):
        ans = input(
            "Site already exists. Overwrite existing site? [Y/n]: ").lower()
        while ans not in ("y", "n", ""):
            ans = input(
                "Please enter 'y' or 'n'. Site already exists. Overwrite existing site? [Y/n]: "
            ).lower()
        if ans == "n":
            create_new_site = False

    if create_new_site:
        exec_cmd("bench new-site --force bench-manager.local")

    if "bench_manager" in os.listdir("apps"):
        print("App already exists. Skipping app download.")
    else:
        exec_cmd("bench get-app bench_manager")

    exec_cmd("bench --site bench-manager.local install-app bench_manager")

    bench_path = "."
    conf = get_config(bench_path)

    if conf.get("restart_supervisor_on_update") or conf.get(
            "restart_systemd_on_update"):
        # implicates a production setup or so I presume
        if not domain:
            print(
                "Please specify the site name on which you want to host bench-manager using the 'domain' flag"
            )
            sys.exit(1)

        if domain not in get_sites(bench_path):
            raise Exception("No such site")

        make_bench_manager_nginx_conf(bench_path,
                                      yes=yes,
                                      port=port,
                                      domain=domain)
Exemplo n.º 12
0
def setup_manager(yes=False, port=23624, domain=None):
    "Setup bench-manager.local site with the bench_manager app installed on it"
    from six.moves import input
    create_new_site = True
    if 'bench-manager.local' in os.listdir('sites'):
        ans = input(
            'Site already exists. Overwrite existing site? [Y/n]: ').lower()
        while ans not in ('y', 'n', ''):
            ans = input(
                'Please enter "y" or "n". Site already exists. Overwrite existing site? [Y/n]: '
            ).lower()
        if ans == 'n':
            create_new_site = False
    if create_new_site:
        exec_cmd("bench new-site --force bench-manager.local")

    if 'bench_manager' in os.listdir('apps'):
        print('App already exists. Skipping app download.')
    else:
        exec_cmd("bench get-app bench_manager")

    exec_cmd("bench --site bench-manager.local install-app bench_manager")

    from bench.config.common_site_config import get_config
    bench_path = '.'
    conf = get_config(bench_path)
    if conf.get('restart_supervisor_on_update') or conf.get(
            'restart_systemd_on_update'):
        # implicates a production setup or so I presume
        if not domain:
            print(
                "Please specify the site name on which you want to host bench-manager using the 'domain' flag"
            )
            sys.exit(1)

        from bench.utils import get_sites, get_bench_name
        bench_name = get_bench_name(bench_path)

        if domain not in get_sites(bench_path):
            raise Exception("No such site")

        from bench.config.nginx import make_bench_manager_nginx_conf
        make_bench_manager_nginx_conf(bench_path,
                                      yes=yes,
                                      port=port,
                                      domain=domain)
Exemplo n.º 13
0
def get_sites_with_config(bench_path):
	from bench.config.common_site_config import get_config
	from bench.config.site_config import get_site_config

	sites = get_sites(bench_path=bench_path)
	dns_multitenant = get_config(bench_path).get('dns_multitenant')

	ret = []
	for site in sites:
		try:
			site_config = get_site_config(site, bench_path=bench_path)
		except Exception as e:
			strict_nginx = get_config(bench_path).get('strict_nginx')
			if strict_nginx:
				print("\n\nERROR: The site config for the site {} is broken.".format(site),
					"If you want this command to pass, instead of just throwing an error,",
					"You may remove the 'strict_nginx' flag from common_site_config.json or set it to 0",
					"\n\n")
				raise (e)
			else:
				print("\n\nWARNING: The site config for the site {} is broken.".format(site),
					"If you want this command to fail, instead of just showing a warning,",
					"You may add the 'strict_nginx' flag to common_site_config.json and set it to 1",
					"\n\n")
				continue

		ret.append({
			"name": site,
			"port": site_config.get('nginx_port'),
			"ssl_certificate": site_config.get('ssl_certificate'),
			"ssl_certificate_key": site_config.get('ssl_certificate_key')
		})

		if dns_multitenant and site_config.get('domains'):
			for domain in site_config.get('domains'):
				# domain can be a string or a dict with 'domain', 'ssl_certificate', 'ssl_certificate_key'
				if isinstance(domain, str) or isinstance(domain, unicode):
					domain = { 'domain': domain }

				domain['name'] = site
				ret.append(domain)

	use_wildcard_certificate(bench_path, ret)

	return ret
Exemplo n.º 14
0
def backup_site(site):
    from bench.utils import get_sites, backup_site
    if site not in get_sites(bench_path='.'):
        print('Site `{0}` not found'.format(site))
        sys.exit(1)
    backup_site(site, bench_path='.')
Exemplo n.º 15
0
def set_site_config_nginx_property(site, config, bench_path='.', gen_config=True):
	if site not in get_sites(bench_path=bench_path):
		raise Exception("No such site")
	update_site_config(site, config, bench_path=bench_path)
	if gen_config:
		make_nginx_conf(bench_path=bench_path)