def run_server(): # Initialize database before gunicorn workers startup: config = load_app_config() cassandra_hosts = [h.strip() for h in config.get('server','cassandra_hosts').split(",")] from cstar_perf.frontend.server.model import Model from cassandra.cluster import Cluster auth_provider = auth_provider_if_configured(config) cluster = Cluster(contact_points=cassandra_hosts, auth_provider=auth_provider, connect_timeout=30) keyspace = config.get('server', 'cassandra_keyspace') if config.has_option('server', 'cassandra_keyspace') else 'cstar_perf' db = Model(cluster=cluster, keyspace=keyspace) del db app_path = os.path.realpath(os.path.join(os.path.dirname( os.path.realpath(__file__)), os.path.pardir, "server")) os.chdir(app_path) log.info('Waiting for cstar_perf_notifications startup...') # this will block until cstar_perf_notifications is up and running console_publish('dummy_cluster', {'job_id': 'startup_check', 'msg': 'checking for notification server'}) # TODO when refactoring how the app is started, do not listen on all interfaces proc = subprocess.Popen(shlex.split("gunicorn -k flask_sockets.worker --bind=0.0.0.0:8000" " -t 300 --log-file=- --workers=10 app:app")) # Capture SIGTERM events to shutdown child gunicorn processes.. def on_terminate(sig, frame): print("Killing child processes...") proc.terminate() signal.signal(signal.SIGTERM, on_terminate) proc.communicate()
def run_server(): # Initialize database before gunicorn workers startup: config = load_app_config() cassandra_hosts = [h.strip() for h in config.get('server','cassandra_hosts').split(",")] from cstar_perf.frontend.server.model import Model from cassandra.cluster import Cluster auth_provider = auth_provider_if_configured(config) cluster = Cluster(contact_points=cassandra_hosts, auth_provider=auth_provider) keyspace = config.get('server', 'cassandra_keyspace') if config.has_option('server', 'cassandra_keyspace') else 'cstar_perf' db = Model(cluster=cluster, keyspace=keyspace) del db app_path = os.path.realpath(os.path.join(os.path.dirname( os.path.realpath(__file__)), os.path.pardir, "server")) os.chdir(app_path) log.info('Waiting for cstar_perf_notifications startup...') # this will block until cstar_perf_notifications is up and running console_publish('dummy_cluster', {'job_id': 'startup_check', 'msg': 'checking for notification server'}) # TODO when refactoring how the app is started, do not listen on all interfaces proc = subprocess.Popen(shlex.split("gunicorn -k flask_sockets.worker --bind=0.0.0.0:8000" " -t 300 --log-file=- --workers=10 app:app")) # Capture SIGTERM events to shutdown child gunicorn processes.. def on_terminate(sig, frame): print("Killing child processes...") proc.terminate() signal.signal(signal.SIGTERM, on_terminate) proc.communicate()
def run_server(): # Initialize database before gunicorn workers startup: config = load_app_config() cassandra_hosts = [h.strip() for h in config.get('server','cassandra_hosts').split(",")] from cstar_perf.frontend.server.model import Model from cassandra.cluster import Cluster db = Model(Cluster(cassandra_hosts)) del db app_path = os.path.realpath(os.path.join(os.path.dirname( os.path.realpath(__file__)), os.path.pardir, "server")) os.chdir(app_path) log.info('Waiting for cstar_perf_notifications startup...') # this will block until cstar_perf_notifications is up and running console_publish('dummy_cluster', {'job_id': 'startup_check', 'msg': 'checking for notification server'}) proc = subprocess.Popen(shlex.split("gunicorn -k flask_sockets.worker -t 300 --log-file=- --workers=10 app:app")) # Capture SIGTERM events to shutdown child gunicorn processes.. def on_terminate(sig, frame): print("Killing child processes...") proc.terminate() signal.signal(signal.SIGTERM, on_terminate) proc.communicate()
# Server email notifications to users: import smtplib from email.mime.text import MIMEText import os from jinja2 import Template, Environment, PackageLoader import ConfigParser import logging import urlparse from cstar_perf.frontend import SERVER_CONFIG_PATH from cstar_perf.frontend.server.util import load_app_config try: app_config = load_app_config() except: app_config = {} template_env = Environment(loader=PackageLoader( 'cstar_perf.frontend.server', os.path.join('templates', 'email'))) log = logging.getLogger('cstar_perf.model') class Email(object): message_template = 'default.jinja2' # name of jinja2 template file in templates/email subject = "Subject goes here - this is a regular jinja template - you can use {{vars}}" required_args = None # list of argument names that must appear in __init__ kwargs _vars = {"base_url": app_config.get('server', 'url')} additional_vars = {} def __init__(self, recipients=[], **kwargs):
# Server email notifications to users: import smtplib from email.mime.text import MIMEText import os from jinja2 import Template, Environment, PackageLoader import ConfigParser import logging import urlparse from cstar_perf.frontend import SERVER_CONFIG_PATH from cstar_perf.frontend.server.util import load_app_config app_config = load_app_config() template_env = Environment(loader=PackageLoader('cstar_perf.frontend.server', os.path.join('templates','email'))) log = logging.getLogger('cstar_perf.model') class Email(object): message_template = 'default.jinja2' # name of jinja2 template file in templates/email subject = "Subject goes here - this is a regular jinja template - you can use {{vars}}" required_args = None # list of argument names that must appear in __init__ kwargs _vars = { "base_url": app_config.get('server', 'url') } additional_vars = {} def __init__(self, recipients=[], **kwargs): self.config = self.__get_config() self.setup(recipients, **kwargs) def __get_config(self, path=SERVER_CONFIG_PATH):