Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review: Feature/registrator systemd #6

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions roles/registrator/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
registrator_service: registrator

registrator_container_name: "{{registrator_service}}"
registrator_docker_image: progrium/registrator
registrator_docker_tag: latest

registrator_consul_connect: "consul://consul:8500"
6 changes: 6 additions & 0 deletions roles/registrator/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: systemd daemon-reload
sudo: yes
command: /bin/systemctl daemon-reload
tags:
- systemd-daemon-reload
29 changes: 19 additions & 10 deletions roles/registrator/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
---
- name: run registrator container
- name: generate registrator systemd service file
sudo: yes
docker:
name: registrator
image: progrium/registrator:latest
state: running
hostname: "{{ inventory_hostname }}"
volumes: /var/run/docker.sock:/tmp/docker.sock
privileged: yes
links: consul:consul
command: consul://consul:8500
template:
src: registrator.service.j2
dest: "/usr/lib/systemd/system/{{registrator_service}}.service"
notify: systemd daemon-reload
register: registrator_unit
tags:
- registrator
- registrator-docker-create-systemd-sevice

- name: register registrator service with systemd
sudo: yes
service:
enabled: yes
name: "{{registrator_service}}"
state: started
tags:
- registrator
- registrator-docker-systemd-start
24 changes: 24 additions & 0 deletions roles/registrator/templates/registrator.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[Unit]
Description=registrator
Documentation=https://github.com/progrium/registrator
After=docker.service
After=dnsmasq.service
Requires=docker.service
Requires=dnsmasq.service

[Service]
Restart=on-failure

ExecStart=/bin/bash -c \
"/usr/bin/docker start {{registrator_container_name}} || \
/usr/bin/docker run --name={{registrator_container_name}} \
--link consul:consul \
--privileged=true \
-v /var/run/docker.sock:/tmp/docker.sock \
-h {{inventory_hostname}} \
{{registrator_docker_image }}:{{registrator_docker_tag}} {{registrator_consul_connect}}"

ExecStop=/usr/bin/docker kill {{registrator_container_name}}

[Install]
WantedBy=multi-user.target