Skip to content

Commit

Permalink
Merge f92b65a into f671398
Browse files Browse the repository at this point in the history
  • Loading branch information
bmw committed Mar 22, 2017
2 parents f671398 + f92b65a commit e4823de
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions certbot-nginx/certbot_nginx/configurator.py
Original file line number Diff line number Diff line change
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 e4823de

Please sign in to comment.