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) (#4400)

Due to issues with piping and Nginx on Arch.
(cherry picked from commit 5fa2080)
  • Loading branch information
bmw committed Mar 22, 2017
1 parent f671398 commit b7152e0
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 b7152e0

Please sign in to comment.