diff options
author | Erica Portnoy <ebportnoy@gmail.com> | 2017-03-16 03:05:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-16 03:05:52 +0300 |
commit | 5fa20805586213262d5b5848747bfc5ec8241139 (patch) | |
tree | cc6e018cffcc26836f183bec42c18e0d17292bdd /certbot-nginx | |
parent | 018a304cd6335c7cb6586faadd89b331cffc485c (diff) |
If we fail to reload Nginx, write to temporary files instead of piping output (#4333)
Due to issues with piping and Nginx on Arch.
Diffstat (limited to 'certbot-nginx')
-rw-r--r-- | certbot-nginx/certbot_nginx/configurator.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/certbot-nginx/certbot_nginx/configurator.py b/certbot-nginx/certbot_nginx/configurator.py index 7348def2f..46ce18ab2 100644 --- a/certbot-nginx/certbot_nginx/configurator.py +++ b/certbot-nginx/certbot_nginx/configurator.py @@ -5,6 +5,7 @@ import re import shutil import socket import subprocess +import tempfile import time import OpenSSL @@ -829,22 +830,22 @@ def nginx_restart(nginx_ctl, nginx_conf="/etc/nginx.conf"): """ try: - proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf, "-s", "reload"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, stderr = proc.communicate() + proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf, "-s", "reload"]) + proc.communicate() if proc.returncode != 0: # Maybe Nginx isn't running - nginx_proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, stderr = nginx_proc.communicate() - - if nginx_proc.returncode != 0: - # Enter recovery routine... - raise errors.MisconfigurationError( - "nginx restart failed:\n%s\n%s" % (stdout, stderr)) + # Write to temporary files instead of piping because of communication issues on Arch + # https://github.com/certbot/certbot/issues/4324 + with tempfile.TemporaryFile() as out: + with tempfile.TemporaryFile() as err: + nginx_proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf], + stdout=out, stderr=err) + nginx_proc.communicate() + if nginx_proc.returncode != 0: + # Enter recovery routine... + raise errors.MisconfigurationError( + "nginx restart failed:\n%s\n%s" % (out.read(), err.read())) except (OSError, ValueError): raise errors.MisconfigurationError("nginx restart failed") |