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

Fix #11 Regex for docker version 1.12 #12

Open
wants to merge 5 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
9 changes: 6 additions & 3 deletions dockerDDNS.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def remove_container(container_id):
if line != '':
text_line = line.decode().rstrip()
logging.debug("Read line %s", text_line)
m = re.search(r"\s+([0-9a-f]{64}):.*\s+([a-z]+)\s*$", text_line)
m = re.search(r".*\s+container\s+([a-z]+)\s+([0-9a-f]{64}).*$", text_line)
if m:
event = m.group(2)
container_id = m.group(1)
event = m.group(1)
container_id = m.group(2)
logging.debug("Got event %s for container %s", event, container_id)

if event == "start":
Expand All @@ -146,3 +146,6 @@ def remove_container(container_id):

# 2014-11-28T15:32:04.000000000+01:00 a3d66b00acc9adbdbdbc91cc664d2d94b6a07cc4295c5cf54fcc595e2aa92a43: (from mongo:latest) restart
# 2015-03-05T08:36:14.000000000+01:00 eb75c1a5ad836d008b0fd66bf6b1ea353510175e8caa619e59d9851029b1ceca: (from ggtools/zabbix-server:latest) exec_start: ifconfig eth0

# docker Version: 1.12.1
# 2017-01-11T20:46:26.268651386-05:00 container start bc340bc76860452fb99ce15101765107f0cf32005e9fcb3261407d81d247307d (image=ubuntu:14.04, name=toto)
37 changes: 37 additions & 0 deletions systemd/Ubuntu/README.mkd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# Install

This configuration was tested on Ubuntu (16.04)

1. copy dockerDDNS.py into /usr/local/sbin/
2. Change permission to let root execute file (chmod 766 /usr/local/sbin/dockerDDNS.py)
2. copy dockerDDNS.service into /etc/systemd/system
3. finaly copy dockerDDNS into /etc/default/
4. Edit file /etc/default/dockerDDNS , fix Variables for your needs
5. reload systemd configuration file (sudo systemctl daemon-reload)

Installation complet, It's time to TRY :D

1. Validation systemd have the new configuration

$ systemctl list-unit-files | grep dockerDDN
dockerDDNS.service disabled
2. Try to start the new service

$ systemctl start dockerDDNS.service
3. View the status and fix it problems

$ systemctl status dockerDDNS.service
dockerDDNS.service - Update a dynamic DNS when Docker starts containers
Loaded: loaded (/etc/systemd/system/dockerDDNS.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2017-01-09 16:43:21 EST; 4s ago
Main PID: 2067 (python3)
Tasks: 7 (limit: 4915)
Memory: 33.4M
CPU: 263ms
CGroup: /system.slice/dockerDDNS.service
├─2067 python3 /usr/local/sbin/dockerDDNS.py --key /tmp/bind/key.private --domain dck.example.com. --server 127.0.0.1
└─2083 docker events
4. Double check, just to be sure :D

$ ps aux | grep dockerDDNS
12 changes: 12 additions & 0 deletions systemd/Ubuntu/dockerDDNS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Configuration file for the DockerDDNS service
# REF : https://github.com/ggtools/docker-tools

# DNS key to update bind9 server
DDNS_UPDATE_KEY=/etc/bind/keys/Kdck.example.com.+157+31514.private

# domain to update
DOMAIN=dck.example.com

# DNS server
DNS_SERVER=127.0.0.1

13 changes: 13 additions & 0 deletions systemd/Ubuntu/dockerDDNS.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Update a dynamic DNS when Docker starts containers
After=docker.service
Requires=docker.service

[Service]
EnvironmentFile=/etc/default/dockerDDNS
ExecStart=/usr/local/sbin/dockerDDNS.py --key $DDNS_UPDATE_KEY --domain $DOMAIN --server $DNS_SERVER --catchup
PIDFile=/var/run/dockerDDNS
KillMode=process

[Install]
WantedBy=default.target
37 changes: 37 additions & 0 deletions systemd/archLinux/README.mkd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# Install

This configuration was tested on ArchLinux (2017-01-09)

1. copy dockerDDNS.py into /usr/local/sbin/
2. Change permission to let root execute file (chmod 766 /usr/local/sbin/dockerDDNS.py)
2. copy dockerDDNS.service into /etc/systemd/system
3. finaly copy dockerDDNS into /etc/conf.d/
4. Edit file /etc/conf.d/dockerDDNS , fix Variables for your needs
5. reload systemd configuration file (sudo systemctl daemon-reload)

Installation complet, It's time to TRY :D

1. Validation systemd have the new configuration

$ systemctl list-unit-files | grep dockerDDN
dockerDDNS.service disabled
2. Try to start the new service

$ systemctl start dockerDDNS.service
3. View the status and fix it problems

$ systemctl status dockerDDNS.service
dockerDDNS.service - Update a dynamic DNS when Docker starts containers
Loaded: loaded (/etc/systemd/system/dockerDDNS.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2017-01-09 16:43:21 EST; 4s ago
Main PID: 2067 (python3)
Tasks: 7 (limit: 4915)
Memory: 33.4M
CPU: 263ms
CGroup: /system.slice/dockerDDNS.service
├─2067 python3 /usr/local/sbin/dockerDDNS.py --key /tmp/bind/key.private --domain dck.example.com. --server 127.0.0.1
└─2083 docker events
4. Double check, just to be sure :D

$ ps aux | grep dockerDDNS
12 changes: 12 additions & 0 deletions systemd/archLinux/dockerDDNS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Configuration file for the DockerDDNS service
# REF : https://github.com/ggtools/docker-tools

# DNS key to update bind9 server
DDNS_UPDATE_KEY=/etc/bind/keys/Kdck.example.com.+157+31514.private

# domain to update
DOMAIN=dck.example.com

# DNS server
DNS_SERVER=127.0.0.1

13 changes: 13 additions & 0 deletions systemd/archLinux/dockerDDNS.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Update a dynamic DNS when Docker starts containers
After=docker.service
Requires=docker.service

[Service]
EnvironmentFile=/etc/conf.d/dockerDDNS
ExecStart=/usr/local/sbin/dockerDDNS.py --key $DDNS_UPDATE_KEY --domain $DOMAIN --server $DNS_SERVER --catchup
PIDFile=/var/run/dockerDDNS
KillMode=process

[Install]
WantedBy=default.target