Start nginx if it's not already running

This commit is contained in:
yan
2015-05-08 12:34:48 -07:00
parent 4dc566a871
commit 1533eea351
2 changed files with 26 additions and 5 deletions
@@ -545,11 +545,18 @@ def nginx_restart(nginx_ctl):
stdout, stderr = proc.communicate() stdout, stderr = proc.communicate()
if proc.returncode != 0: if proc.returncode != 0:
# Enter recovery routine... # Maybe Nginx isn't running
logging.error("Nginx Restart Failed!") nginx_proc = subprocess.Popen([nginx_ctl],
logging.error(stdout) stdout=subprocess.PIPE,
logging.error(stderr) stderr=subprocess.PIPE)
return False stdout, stderr = nginx_proc.communicate()
if nginx_proc.returncode != 0:
# Enter recovery routine...
logging.error("Nginx Restart Failed!")
logging.error(stdout)
logging.error(stderr)
return False
except (OSError, ValueError): except (OSError, ValueError):
logging.fatal( logging.fatal(
@@ -259,6 +259,20 @@ class NginxConfiguratorTest(util.NginxTest):
mocked.returncode = 0 mocked.returncode = 0
self.assertTrue(self.config.restart()) self.assertTrue(self.config.restart())
@mock.patch("letsencrypt.client.plugins.nginx.configurator."
"subprocess.Popen")
def test_nginx_restart_fail(self, mock_popen):
mocked = mock_popen()
mocked.communicate.return_value = ('', '')
mocked.returncode = 1
self.assertFalse(self.config.restart())
@mock.patch("letsencrypt.client.plugins.nginx.configurator."
"subprocess.Popen")
def test_no_nginx_start(self, mock_popen):
mock_popen.side_effect = OSError("Can't find program")
self.assertRaises(SystemExit, self.config.restart)
@mock.patch("letsencrypt.client.plugins.nginx.configurator." @mock.patch("letsencrypt.client.plugins.nginx.configurator."
"subprocess.Popen") "subprocess.Popen")
def test_config_test(self, mock_popen): def test_config_test(self, mock_popen):