Skip to content

Commit b8b7cc0

Browse files
committed
Merge pull request #646 from opdemand/fix-registry-seed
fix confd wait issue
2 parents ef6299d + d179eed commit b8b7cc0

10 files changed

Lines changed: 37 additions & 23 deletions

File tree

controller/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ RUN useradd deis --groups sudo --home-dir /app --shell /bin/bash
3030
RUN sed -i -e 's/%sudo\tALL=(ALL:ALL) ALL/%sudo\tALL=(ALL:ALL) NOPASSWD:ALL/' /etc/sudoers
3131
RUN chown -R deis:deis /app
3232

33+
# create directory for confd templates
34+
RUN mkdir -p /templates && chown -R deis:deis /templates
35+
3336
# create directory for logs
34-
RUN mkdir -p /app/logs && chown -R deis:deis /app/logs
37+
RUN mkdir -p /var/log/deis && chown -R deis:deis /var/log/deis
3538

3639
# define the execution environment
3740
CMD ["/app/bin/boot"]

controller/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ coverage:
1212
coverage html
1313

1414
build:
15-
docker build -t deis/server .
15+
docker build -t deis/controller .
1616

1717
run:
18-
docker run -rm -p $${PORT:-8000}:$${PORT:-8000} -e ETCD=$${ETCD:-127.0.0.1:4001} -name deis-server deis/server ; exit 0
18+
docker run -rm -p $${PORT:-8000}:$${PORT:-8000} -e ETCD=$${ETCD:-127.0.0.1:4001} -name deis-controller deis/controller ; exit 0
1919

2020
shell:
21-
docker run -t -i -rm -e ETCD=$${ETCD:-127.0.0.1:4001} deis/server /bin/bash
21+
docker run -t -i -rm -e ETCD=$${ETCD:-127.0.0.1:4001} deis/controller /bin/bash
2222

2323
clean:
24-
-docker rmi deis/server
24+
-docker rmi deis/controller
2525

2626
flake8:
2727
flake8

controller/bin/boot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ until confd -onetime -node $ETCD -config-file /app/confd.toml 2>/dev/null; do
3232
done
3333

3434
# wait for confd to populate all values
35-
while grep -q '<no value>' /app/confd_settings.py; do
35+
while grep -q '<no value>' /templates/confd_settings.py; do
3636
echo "waiting for confd to write all values..."
3737
confd -onetime -node $ETCD -config-file /app/confd.toml 2>/dev/null
3838
sleep $(($ETCD_TTL/2)) # sleep for half the TTL

controller/bin/start

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ cd /app
77
# run an idempotent database migration
88
sudo -E -u deis ./manage.py syncdb --migrate --noinput
99

10+
# spawn celery worker in the background
11+
sudo -E -u deis celery worker --app=deis --loglevel=INFO --workdir=/app --pidfile=/tmp/celery.pid &
12+
1013
# spawn a gunicorn server in the foreground
11-
sudo -E -u deis ./manage.py run_gunicorn -b 0.0.0.0 -w 8 -t 600 -n deis --log-level debug # -k gevent
14+
sudo -E -u deis ./manage.py run_gunicorn -b 0.0.0.0 -w 8 -t 600 -n deis --log-level debug --pid=/tmp/gunicorn.pid # -k gevent

controller/conf.d/confd_settings.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[template]
22
src = "confd_settings.py"
3-
dest = "/app/confd_settings.py"
3+
dest = "/templates/confd_settings.py"
44
uid = 1000
55
gid = 1000
66
mode = "0640"

controller/confd.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
confdir = "/app"
33
interval = 5
44
prefix = "/"
5-
quiet = true
5+
quiet = true

controller/deis/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@
317317

318318
# import dynamic confd settings from /app, if they exist
319319
try:
320-
if os.path.exists('/app/confd_settings.py'):
321-
sys.path.append('/app')
320+
if os.path.exists('/templates/confd_settings.py'):
321+
sys.path.append('/templates')
322322
from confd_settings import * # noqa
323323
except ImportError:
324324
pass

controller/templates/confd_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
CELERY_RESULT_BACKEND = BROKER_URL
2727

2828
# move log directory out of /app/deis
29-
DEIS_LOG_DIR = '/app/logs'
29+
DEIS_LOG_DIR = '/var/log/deis'
3030

3131
# specify which provider API modules to load
3232
PROVIDER_MODULES = ('mock', 'digitalocean', 'ec2', 'rackspace', 'vagrant', 'static')

controller/templates/reload

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
#!/bin/bash
22

3-
# write out chef configuration
4-
sudo mkdir -p /etc/chef
5-
sudo chown deis /etc/chef
6-
echo {{ .deis_chef_clientKey }} | base64 -d > /etc/chef/client.pem
7-
echo {{ .deis_chef_validationKey }} | base64 -d > /etc/chef/validation.pem
8-
cat > /etc/chef/client.rb <<EOF
3+
# write out chef configuration if necessary
4+
if [[ "{{ .deis_controller_cmModule }}" == "cm.chef" ]]; then
5+
6+
# write out chef configuration
7+
sudo mkdir -p /etc/chef
8+
sudo chown deis /etc/chef
9+
echo "{{ .deis_chef_clientKey }}" | base64 -d > /etc/chef/client.pem
10+
echo "{{ .deis_chef_validationKey }}" | base64 -d > /etc/chef/validation.pem
11+
cat > /etc/chef/client.rb <<EOF
912
log_level :auto
1013
log_location STDOUT
1114
chef_server_url "{{ .deis_chef_url }}"
1215
validation_client_name "{{ .deis_chef_validationName }}"
1316
node_name "{{ .deis_chef_clientName }}"
1417
EOF
18+
19+
fi
20+
21+
# gracefully reload celery and gunicorn
22+
test -e /tmp/celery.pid && kill -HUP `cat /tmp/celery.pid`
23+
test -e /tmp/gunicorn.pid && kill -HUP `cat /tmp/gunicorn.pid`
24+
25+
exit 0

registry/bin/seed

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#!/bin/bash
22
set -eo pipefail
33

4-
# if the keyspace already exists, exit early
5-
etcdctl -C $ETCD ls $ETCD_PATH >/dev/null && exit 0
6-
74
# seed etcd with default configuration
85
etcdctl -C $ETCD set $ETCD_PATH/protocol http
9-
etcdctl -C $ETCD set $ETCD_PATH/secretKey ${REGISTRY_SECRET_KEY:-`openssl rand -base64 64 | tr -d '\n'`}
6+
etcdctl -C $ETCD ls $ETCD_PATH/secretKey >/dev/null || etcdctl -C $ETCD set $ETCD_PATH/secretKey ${REGISTRY_SECRET_KEY:-`openssl rand -base64 64 | tr -d '\n'`}
107

11-
exit 0
8+
exit 0

0 commit comments

Comments
 (0)