def make_celery(app=None):
if app is None:
app = create_app('kubedock', os.path.dirname(__file__))
if SENTRY_ENABLE:
import socket
import celery
import raven
from raven.contrib.celery import register_signal
from raven.contrib.celery import register_logger_signal
from kubedock.settings import MASTER_IP
from kubedock.settings import SENTRY_DSN, SENTRY_EXCLUDE_PATHS
from kubedock.settings import SENTRY_PROCESSORS
from kubedock.utils import get_version
from kubedock.kapi.licensing import get_license_info
authkey = get_license_info().get('auth_key', 'no installation id')
from celery.utils import log
class Celery(celery.Celery):
def on_configure(self):
hostname = "{}({})".format(socket.gethostname(), MASTER_IP)
tags = {'installation_id': authkey}
client = raven.Client(SENTRY_DSN, name=hostname,
release=get_version('kuberdock'),
tags=tags, processors=SENTRY_PROCESSORS,
exclude_paths=SENTRY_EXCLUDE_PATHS)
# register a custom filter to filter out duplicate logs
register_logger_signal(client)
# hook into the Celery error handler
register_signal(client)
else:
from celery import Celery
celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
flask_app = app
def __call__(self, *args, **kwargs):
with app.app_context():
env.user = 'root'
env.key_filename = SSH_KEY_FILENAME
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
python类key_filename()的实例源码
def db_install(host_config, config):
env.host_string = helper.get_env_host_string(host_config)
env.user = helper.get_env_user(host_config)
env.key_filename = helper.get_env_key_filename(host_config)
software_config = helper.get_software_config(host_config, 'crate')
sudo("sysctl -w vm.max_map_count=262144")
put('{}/software/scripts/crate.sh'.format(os.getcwd()), '~/', use_sudo=True)
sudo(". ~/crate.sh")
cluster_name = software_config.get('cluster-name')
data_dir = software_config.get('data-dir')
heap_size = software_config.get('heap-size', '2g')
security_group = software_config.get('security-group')
product_tag = software_config.get('product-tag')
aws_access_key = software_config.get('aws-access-key')
aws_secret_key = software_config.get('aws-secret-key')
configfile = '/etc/crate/crate.yml'
sudo('cp {} {}.save'.format(configfile, configfile))
sudo('echo "### CrateDB Settings ###" | sudo tee -a {}'.format(cluster_name, configfile))
sudo('echo "cluster.name: {}" | sudo tee -a {}'.format(cluster_name, configfile))
sudo('echo "node.name: node-{}" | sudo tee -a {}'.format(host_config['private-ip'], configfile))
sudo('echo "path.data: {}" | sudo tee -a {}'.format(data_dir, configfile))
sudo('echo "network.publish_host: {}" | sudo tee -a {}'.format(host_config['private-ip'], configfile))
sudo('echo "network.host: _site_" | sudo tee -a {}'.format(configfile))
sudo('echo "psql.enabled: true" | sudo tee -a {}'.format(configfile))
sudo('echo "psql.port: 6432" | sudo tee -a {}'.format(configfile))
sudo('echo "license.enterprise: false" | sudo tee -a {}'.format(configfile))
if security_group is not None:
sudo('echo "discovery.type: ec2" | sudo tee -a {}'.format(configfile))
sudo('echo "discovery.ec2.groups: {}" | sudo tee -a {}'.format(security_group, configfile))
if product_tag is not None:
sudo('echo "discovery.ec2.tag.product: {}" | sudo tee -a {}'.format(product_tag, configfile))
if aws_access_key is not None:
sudo('echo "cloud.aws.access_key: {}" | sudo tee -a {}'.format(aws_access_key, configfile))
sudo('echo "cloud.aws.secret_key: {}" | sudo tee -a {}'.format(aws_secret_key, configfile))
default_configfile = '/etc/default/crate'
sudo('cp {} {}.save'.format(default_configfile, default_configfile))
sudo('echo "### CrateDB Default Settings ###" | sudo tee {}'.format(default_configfile))
sudo('echo "CRATE_HEAP_SIZE={}" | sudo tee -a {}'.format(heap_size, default_configfile))
for mount in data_dir.split(','):
sudo('chown -R crate:crate {}'.format(mount))
sudo("service crate restart")
def install(host_config):
env.host_string = helper.get_env_host_string(host_config)
env.user = helper.get_env_user(host_config)
env.key_filename = helper.get_env_key_filename(host_config)
software_config = helper.get_software_config(host_config, 'cassandra')
java.v8_install(host_config)
put('{}/software/scripts/cassandra.sh'.format(os.getcwd()), '~/', use_sudo=True)
sudo("chmod +x cassandra.sh")
sudo(". ~/cassandra.sh {}")
# Configuration values from config or use defaults if do not exist
cluster_name = software_config.get('cluster-name', 'Test Cluster')
data_file_directory = software_config.get('data-file-directory', '/var/lib/cassandra/data')
commit_log_directory = software_config.get('commit-log-directory', '/var/lib/cassandra/commit_log')
saved_caches_directory = software_config.get('saved-caches-directory', '/var/lib/cassandra/saved_caches')
endpoint_snitch = software_config.get('endpoint-snitch', 'SimpleSnitch')
seeds = software_config.get('seeds', host_config['private-ip'])
listen_address = software_config.get('listen-address', host_config['private-ip'])
rpc_address = software_config.get('rpc-address', host_config['private-ip'])
configfile = '{}/software/config/cassandra/cassandra.yaml'.format(os.getcwd())
tempfile = 'cassandra.yaml'
configdata = open(configfile, 'r').read()
configdata = configdata.replace('{{CLUSTER_NAME}}', cluster_name)
configdata = configdata.replace('{{DATA_FILE_DIRECTORY}}', data_file_directory)
configdata = configdata.replace('{{COMMIT_LOG_DIRECTORY}}', commit_log_directory)
configdata = configdata.replace('{{SAVED_CACHES_DIRECTORY}}', saved_caches_directory)
configdata = configdata.replace('{{ENDPOINT_SNITCH}}', endpoint_snitch)
configdata = configdata.replace('{{SEEDS}}', seeds)
configdata = configdata.replace('{{LISTEN_ADDRESS}}', listen_address)
configdata = configdata.replace('{{RPC_ADDRESS}}', rpc_address)
_file = open(tempfile, 'w')
_file.write(configdata)
_file.close()
sudo('mkdir -p {0}; chown -R cassandra {0}'.format(data_file_directory))
sudo('mkdir -p {0}; chown -R cassandra {0}'.format(commit_log_directory))
sudo('mkdir -p {0}; chown -R cassandra {0}'.format(saved_caches_directory))
put('cassandra.yaml'.format(os.getcwd()), '/etc/cassandra/cassandra.yaml', use_sudo=True)
sudo('sudo pkill -f CassandraDaemon', warn_only=True)
sudo('service cassandra restart')
os.remove(tempfile)
def db_install(host_config, config):
env.host_string = helper.get_env_host_string(host_config)
env.user = helper.get_env_user(host_config)
env.key_filename = helper.get_env_key_filename(host_config)
software_config = helper.get_software_config(host_config, 'citusdb')
db_name = software_config.get('db-name')
db_user = software_config.get('db-user')
db_password = software_config.get('db-password')
data_dir = software_config.get('data-dir')
postgres_config = '/etc/postgresql/9.6/main/postgresql.conf'
put('{}/software/scripts/citusdb.sh'.format(os.getcwd()), '~/', use_sudo=True)
sudo(". ~/citusdb.sh")
sudo('sudo service postgresql stop')
for mount in data_dir.split(','):
sudo('chown -R postgres:postgres {}'.format(mount))
sudo('sudo sed -i.bu "s/data_directory/#data_directory/" {}'.format(postgres_config))
sudo('echo "data_directory = \'{}\'" | sudo tee -a {}'.format(data_dir, postgres_config))
sudo('sudo -u postgres bash -c "/usr/lib/postgresql/9.6/bin/initdb -D {}"'.format(data_dir))
sudo('service postgresql start')
sudo('sudo pg_conftool 9.6 main set shared_preload_libraries citus')
sudo("sudo pg_conftool 9.6 main set listen_addresses '*'")
sudo("cp /etc/postgresql/9.6/main/pg_hba.conf /etc/postgresql/9.6/main/pg_hba.conf.backup")
sudo('echo "##### Custom Configuration ######" | sudo tee /etc/postgresql/9.6/main/pg_hba.conf')
sudo('echo "local all postgres peer" | sudo tee -a /etc/postgresql/9.6/main/pg_hba.conf')
sudo('echo "local all all peer" | sudo tee -a /etc/postgresql/9.6/main/pg_hba.conf')
sudo('echo "host all all 10.0.0.0/8 trust" | sudo tee -a /etc/postgresql/9.6/main/pg_hba.conf')
sudo('echo "host all all 127.0.0.1/32 trust" | sudo tee -a /etc/postgresql/9.6/main/pg_hba.conf')
sudo('echo "host all all ::1/128 trust" | sudo tee -a /etc/postgresql/9.6/main/pg_hba.conf')
sudo('echo "host all all 0.0.0.0/0 md5" | sudo tee -a /etc/postgresql/9.6/main/pg_hba.conf')
sudo('update-rc.d postgresql enable')
sudo('sudo service postgresql restart')
sudo('sudo -i -u postgres psql -c "CREATE EXTENSION citus;"')
sudo('sudo -u postgres psql -c \"CREATE USER {} WITH PASSWORD \'{}\'\";'.format(db_user, db_password))
sudo('sudo -u postgres psql -c \"ALTER USER {} WITH SUPERUSER\";'.format(db_user))
sudo('sudo -u postgres psql -c \"CREATE DATABASE {} OWNER {}\";'.format(db_name, db_user))