Created
March 1, 2015 04:01
-
-
Save criloz/0dae1558a1dc35cb2062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'cristian' | |
from base import * | |
def pull_elasticsearch_image(pmk, ip): | |
""" | |
@type param pmk: SSHClient | |
:return: | |
""" | |
exec_command(pmk, "docker pull dockerfile/elasticsearch", ip) | |
def run_container(pmk, server): | |
exec_command(pmk, "docker run --restart=on-failure:10 -d -h {hostname} --name elasticsearch-{hostname} -d\ | |
-p {private_ip}:9200:9200 -p {private_ip}:9300:9300 -v /data/elasticsearch:/data \ | |
-e SERVICE_9200_CHECK_HTTP=/_cluster/health?pretty=true -e SERVICE_9200_CHECK_INTERVAL=60s \ | |
-e LOG=true dockerfile/elasticsearch /elasticsearch/bin/elasticsearch -Des.config=/data/elasticsearch.yml" | |
.format(**server), server.ip) | |
def create_data_volume(pmk, ip): | |
exec_command(pmk, "mkdir -p /data/elasticsearch") | |
exec_command(pmk, "echo 'path: {logs: /data/log, data: /data/data}' > /data/elasticsearch/elasticsearch.yml", ip) | |
def install_elasticsearch(server_name, server): | |
""" | |
@type param server_name: str | |
@type param server: dict | |
:return: | |
""" | |
if server_name != "master": | |
return | |
client = SSHClient() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
client.connect(server["ip"], username=server["user"], port=server["port"]) | |
pull_elasticsearch_image(client, server.ip) | |
create_data_volume(client, server.ip) | |
run_container(client, server) | |
execute = [install_elasticsearch] | |
if __name__ == "__main__": | |
run_task(execute) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment