Commit f315bca7 by Martin Fitzpatrick Committed by Fred Smith

Condition LETS_ENCRYPT_EMAIL, nginx restart order, add subdir

Fixes to make running in edx_sandbox conditional on both
LETS_ENCRYPT_EMAIL and LETS_ENCRYPT_DOMAINS being set. Restart
nginx only after the config has been copied/symlinks in place
and add everything to an subdir in /opt/letsencrypt
parent f91438a9
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
- ecommerce - ecommerce
when: SANDBOX_ENABLE_ECOMMERCE when: SANDBOX_ENABLE_ECOMMERCE
- role: lets_encrypt - role: lets_encrypt
when: LETS_ENCRYPT_DOMAINS when: LETS_ENCRYPT_DOMAINS and LETS_ENCRYPT_EMAIL
- role: edxlocal - role: edxlocal
when: EDXAPP_MYSQL_HOST == 'localhost' when: EDXAPP_MYSQL_HOST == 'localhost'
- role: memcache - role: memcache
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
- name: install certbot - name: install certbot
git: git:
repo: https://github.com/certbot/certbot repo: https://github.com/certbot/certbot
dest: /opt/certbot dest: /opt/letsencrypt/certbot
tags: tags:
- install - install
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
- name: render certbot script - name: render certbot script
template: template:
src: run_certbot.sh.j2 src: run_certbot.sh.j2
dest: /opt/run_certbot.sh dest: /opt/letsencrypt/run_certbot.sh
mode: u+x mode: u+x
tags: tags:
- install - install
...@@ -94,13 +94,13 @@ ...@@ -94,13 +94,13 @@
- name: render nginx cert configuration file - name: render nginx cert configuration file
template: template:
src: ssl-certs.conf.j2 src: ssl-certs.conf.j2
dest: /opt/ssl-certs.conf dest: /opt/letsencrypt/ssl-certs.conf
owner: root owner: root
tags: tags:
- install - install
- name: run certbot - name: run certbot
command: /opt/run_certbot.sh command: /opt/letsencrypt/run_certbot.sh
tags: tags:
- install - install
- update - update
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
minute : "{{ 59|random }}" minute : "{{ 59|random }}"
cron_file : "lets-encrypt-renew" cron_file : "lets-encrypt-renew"
user : "root" user : "root"
job : /opt/run_certbot.sh job : /opt/letsencrypt/run_certbot.sh
state : present state : present
tags: tags:
- install - install
......
...@@ -8,16 +8,13 @@ if [ $? -ne 0 ]; then ...@@ -8,16 +8,13 @@ if [ $? -ne 0 ]; then
fi fi
# Start nginx up (ignore if already running) # Start nginx up (ignore if already running)
echo "Ensure nginx is running..."
service nginx start || true service nginx start || true
echo "Request certificate via certbot... (or renew)" echo "Request certificate via certbot... (or renew)"
# Run certbot installation # Run certbot installation
/opt/certbot/certbot-auto certonly --webroot --webroot-path=/usr/share/nginx/www --email {{ LETS_ENCRYPT_EMAIL }} --agree-tos --http-01-port {{ LETS_ENCRYPT_PORT }} {% for domain in LETS_ENCRYPT_DOMAINS %} -d {{ domain }} {% endfor %} --non-interactive /opt/letsencrypt/certbot/certbot-auto certonly --webroot --webroot-path=/usr/share/nginx/www --email {{ LETS_ENCRYPT_EMAIL }} --agree-tos --http-01-port {{ LETS_ENCRYPT_PORT }} {% for domain in LETS_ENCRYPT_DOMAINS %} -d {{ domain }} {% endfor %} --non-interactive
echo "Restarting nginx service to reload config..."
service nginx restart
echo "Create symlinks to Let's Encrypt certificates..." echo "Create symlinks to Let's Encrypt certificates..."
...@@ -28,9 +25,13 @@ ln -sf /etc/letsencrypt/live/{{ LETS_ENCRYPT_DOMAINS|first }}/privkey.pem /etc/s ...@@ -28,9 +25,13 @@ ln -sf /etc/letsencrypt/live/{{ LETS_ENCRYPT_DOMAINS|first }}/privkey.pem /etc/s
echo "Writing nginx certificate configuration..." echo "Writing nginx certificate configuration..."
# Copy the configuration file (with the above certs) into place # Copy the configuration file (with the above certs) into place
cp /opt/ssl-certs.conf /etc/nginx/ssl-certs.conf cp /opt/letsencrypt/ssl-certs.conf /etc/nginx/ssl-certs.conf
# Stop nginx again if it wasn't running, or restart it if it was # Stop nginx again if it wasn't running, or restart it if it was
if [ "$nginxstate" == "stopped" ]; then if [ "$nginxstate" == "stopped" ]; then
echo "Stopping nginx..."
service nginx stop service nginx stop
else
echo "Restarting nginx..."
service nginx restart
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment