Skip to content

Commit

Permalink
If we fail to reload Nginx, write to temporary files instead of pipin…
Browse files Browse the repository at this point in the history
…g output (#4333)

Due to issues with piping and Nginx on Arch.
  • Loading branch information
ohemorange committed Mar 16, 2017
1 parent 018a304 commit 5fa2080
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions certbot-nginx/certbot_nginx/configurator.py
Expand Up @@ -5,6 +5,7 @@
import shutil
import socket
import subprocess
import tempfile
import time

import OpenSSL
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 5fa2080

Please sign in to comment.