Skip to content

Commit

Permalink
Merge pull request #4 from ludovicc/master
Browse files Browse the repository at this point in the history
Install Chronos from official distribution channel
  • Loading branch information
JasonGiedymin committed Dec 16, 2015
2 parents ba7cf02 + efd030a commit 9142ace
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 100 deletions.
20 changes: 20 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
chronos_version: 2.4.0
chronos_package_version: 0.1.20150828104228

# # == chronos conf ==
mesos_zk_chroot: "mesos"
chronos_zk_auth: ""
chronos_zk_dns: "{{ inventory_hostname }}"
chronos_zk_port: 2181
chronos_zk_chroot: chronos
chronos_zk_connect: "zk://{{ chronos_zk_dns }}:{{ chronos_zk_port }}/{{chronos_zk_chroot}}"

chronos_zk_mesos_master: "zk://{{ chronos_zk_dns }}:{{ chronos_zk_port }}/{{ mesos_zk_chroot }}"

chronos_hostname: "{{ inventory_hostname }}"
chronos_port: 4400

# TODO chronos_env_java_opts: "-Xmx512m"

haproxy_script_location: "/usr/local/bin"
110 changes: 110 additions & 0 deletions files/haproxy_dns_cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<\USAGE
USAGE: haproxy_cfg <chronos host:port>
haproxy_cfg generates a config file to run HAProxy on localhost and proxy to a number of backend hosts.
To gracefully reload haproxy:
:; haproxy -f /path/to/config -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)
USAGE
}; function --help { -h ;}
export LC_ALL=en_US.UTF-8

function header {
cat <<EOF
global
daemon
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
user haproxy
group haproxy
defaults
log global
retries 3
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
stats enable
stats auth admin:admin
stats uri /haproxy
EOF
}

function marathon_apps {
z="`curl -H "Accept: text/plain" -s "$1/v2/tasks"`"

frontend "$z"
backend "$z"
}

function frontend {
cat <<EOF
frontend http-in
bind *:80
mode http
option httplog
option dontlognull
option forwardfor
option http-server-close
EOF

while IFS= read
do
set -- $REPLY
local name="$1"
cat <<EOF
acl host_${name} hdr_beg(host) -i ${name}
use_backend ${name}_cluster if host_${name}
EOF
done <<< "$1"
}

function backend {
while IFS= read
do
set -- $REPLY
local name="$1"
local port="$2"
shift 2
cat <<EOF
backend ${name}_cluster
option httpclose
option forwardfor
mode http
balance leastconn
EOF
while [[ $# -gt 0 ]]
do
out " server ${name}-$# $1 check"
shift
done
done <<< "$1"
}

function config {
header
marathon_apps "$@"
}

function main {
config "$@"
}

function msg { out "$*" >&2 ;}
function err { local x=$? ; msg "$*" ; return $(( $x == 0 ? 1 : $x )) ;}
function out { printf '%s\n' "$*" ;}

if [[ ${1:-} ]] && declare -F | cut -d' ' -f3 | fgrep -qx -- "${1:-}"
then "$@"
else main "$@"
fi
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ galaxy_info:
description: Ansible Chronos Playbook Role
company: http://jasongiedymin.com
license: Apache 2
min_ansible_version: 1.2
min_ansible_version: 1.3
#
# Below are all platforms currently available. Just uncomment
# the ones that apply to your role. If you don't see your
Expand Down
19 changes: 13 additions & 6 deletions tasks/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
---
- name: Create Chronos default conf file
template: src=chronos_conf.j2 dest=/etc/default/chronos
owner="root" group="root" mode=0664
- name: Add apt-key
apt_key: id=E56151BF keyserver=keyserver.ubuntu.com state=present

- name: Create Chronos default init file
template: src=chronos.j2 dest=/etc/init/chronos.conf
owner="root" group="root" mode=0664
- name: Add Mesosphere repo
apt_repository:
repo: "{{ chronos_apt_repo }}"
state: present

- name: Install Chronos package
apt:
pkg: chronos={{chronos_version}}-{{chronos_package_version}}.{{ansible_distribution|lower}}{{ansible_distribution_version.split('.')|join('')}}
state: present
update_cache: yes
cache_valid_time: 600
6 changes: 6 additions & 0 deletions tasks/RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Add mesosphere repo
yum: name={{ mesosphere_repo }} state=present

- name: Install Chronos
yum: name=chronos-{{chronos_version}} state=present
3 changes: 0 additions & 3 deletions tasks/common.yml

This file was deleted.

100 changes: 100 additions & 0 deletions tasks/conf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---

#- name: wait for zookeeper to listen
# command: "/usr/local/bin/zookeeper-wait-for-listen.sh {{ inventory_hostname }}"
#
#- name: create zookeeper acl
# sudo: yes
# command: "{{ chronos_zk_acl_cmd }}"
# notify:
# - restart chronos
# when: zk_chronos_user_secret is defined
# run_once: true
# tags:
# - chronos

- name: create chronos conf directory
sudo: yes
file:
dest: /etc/chronos/conf
state: directory
tags:
- chronos

- name: systemd check
stat: path=/usr/lib/systemd/system/
register: systemd_check

- name: configure chronos unit file
sudo: yes
replace:
dest: /usr/lib/systemd/system/chronos.service
regexp: "=network.target"
replace: '=mesos-master.service'
when: systemd_check.stat.exists == true
notify:
- reload chronos
- restart chronos
tags:
- chronos

- name: configure chronos to wait for zookeeper before starting
sudo: yes
lineinfile:
dest: /usr/lib/systemd/system/chronos.service
line: "ExecStartPre=/usr/local/bin/zookeeper-wait-for-listen.sh {{ chronos_zk_dns }}"
insertbefore: "^ExecStart="
state: present
when: systemd_check.stat.exists == true
notify:
- reload chronos
- restart chronos
tags:
- chronos

# TODO: feels like a hack
- name: fix chronos bin file
sudo: yes
replace:
dest: /usr/bin/chronos
regexp: '\[\[ -s /etc/mesos/zk \]\]'
replace: 'false'
notify:
- restart chronos
tags:
- chronos

- name: set key/value options
sudo: yes
when: item.value != ""
copy:
dest: /etc/chronos/conf/{{ item.key }}
content: "{{ item.value }}"
with_items:
- key: zk_hosts
value: "{{ chronos_zk_connect }}"
- key: master
value: "{{ chronos_zk_mesos_master }}"
- key: hostname
value: "{{ chronos_hostname }}"
- key: http_port
value: "{{ chronos_port }}"
#- key: mem_opts
# value: "{{ chronos_env_java_opts }}"
- key: mesos_framework_name
value: "chronos"
notify:
- restart chronos
tags:
- chronos

- name: enable and start chronos
sudo: yes
service:
enabled: yes
name: chronos
state: started
tags:
- chronos

- meta: flush_handlers
31 changes: 0 additions & 31 deletions tasks/deploy.yml

This file was deleted.

17 changes: 17 additions & 0 deletions tasks/haproxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Check HAProxy
stat: path=/etc/haproxy
register: haproxy_dir

- name: Setup HAProxy script
copy: src=haproxy_dns_cfg dest="{{ haproxy_script_location }}/haproxy_dns_cfg" mode=755
when: haproxy_dir.stat.exists

- name: Create HAProxy reload script
template: src=haproxy_reload.j2 dest={{ haproxy_script_location }}/haproxy_reload
owner="root" group="root" mode=0744
when: haproxy_dir.stat.exists

- name: Setup cron job for HAProxy
cron: name="reload chronos haproxy" minute="*/1" job="{{ haproxy_script_location }}/haproxy_reload"
when: haproxy_dir.stat.exists
16 changes: 14 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
---
- include: common.yml
- include_vars: "{{ ansible_os_family }}.yml"

- include: Debian.yml
when: ansible_os_family == "Debian"

- include: deploy.yml
- include: RedHat.yml
when: ansible_os_family == "RedHat"

- include: conf.yml

- include: haproxy.yml
when: haproxy_script_location != ""

- name: Delete old slave info to ensure clean startup of Chronos after an upgrade
file: path=/tmp/mesos/meta/slaves/latest state=absent

- name: Start Chronos service
service: name=chronos state=restarted enabled=yes
24 changes: 0 additions & 24 deletions templates/chronos.j2

This file was deleted.

7 changes: 0 additions & 7 deletions templates/chronos_conf.j2

This file was deleted.

1 change: 1 addition & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chronos_apt_repo: "deb http://repos.mesosphere.io/{{ansible_distribution|lower}} {{ansible_distribution_release|lower}} main"
9 changes: 9 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
os_version: "{{ ansible_lsb.release if ansible_lsb is defined else ansible_distribution_version }}"
os_version_major: "{{ os_version | regex_replace('^([0-9]+)[^0-9]*.*', '\\\\1') }}"

mesosphere_releases:
'6': 'mesosphere-el-repo-6-3.noarch.rpm'
'7': 'mesosphere-el-repo-7-1.noarch.rpm'

mesosphere_repo: "http://repos.mesosphere.com/el/{{ os_version_major }}/noarch/RPMS/{{ mesosphere_releases[os_version_major] }}"

Loading

0 comments on commit 9142ace

Please sign in to comment.