If we fail to reload Nginx, write to temporary files instead of piping output (#4333)

Due to issues with piping and Nginx on Arch.
This commit is contained in:
Erica Portnoy
2017-03-15 17:05:52 -07:00
committed by GitHub
parent 018a304cd6
commit 5fa2080558
+14 -13
View File
@@ -5,6 +5,7 @@ import re
import shutil import shutil
import socket import socket
import subprocess import subprocess
import tempfile
import time import time
import OpenSSL import OpenSSL
@@ -829,22 +830,22 @@ def nginx_restart(nginx_ctl, nginx_conf="/etc/nginx.conf"):
""" """
try: try:
proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf, "-s", "reload"], proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf, "-s", "reload"])
stdout=subprocess.PIPE, proc.communicate()
stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
if proc.returncode != 0: if proc.returncode != 0:
# Maybe Nginx isn't running # Maybe Nginx isn't running
nginx_proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf], # Write to temporary files instead of piping because of communication issues on Arch
stdout=subprocess.PIPE, # https://github.com/certbot/certbot/issues/4324
stderr=subprocess.PIPE) with tempfile.TemporaryFile() as out:
stdout, stderr = nginx_proc.communicate() with tempfile.TemporaryFile() as err:
nginx_proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf],
if nginx_proc.returncode != 0: stdout=out, stderr=err)
# Enter recovery routine... nginx_proc.communicate()
raise errors.MisconfigurationError( if nginx_proc.returncode != 0:
"nginx restart failed:\n%s\n%s" % (stdout, stderr)) # Enter recovery routine...
raise errors.MisconfigurationError(
"nginx restart failed:\n%s\n%s" % (out.read(), err.read()))
except (OSError, ValueError): except (OSError, ValueError):
raise errors.MisconfigurationError("nginx restart failed") raise errors.MisconfigurationError("nginx restart failed")