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,6 +545,13 @@ def nginx_restart(nginx_ctl):
stdout, stderr = proc.communicate() stdout, stderr = proc.communicate()
if proc.returncode != 0: if proc.returncode != 0:
# Maybe Nginx isn't running
nginx_proc = subprocess.Popen([nginx_ctl],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = nginx_proc.communicate()
if nginx_proc.returncode != 0:
# Enter recovery routine... # Enter recovery routine...
logging.error("Nginx Restart Failed!") logging.error("Nginx Restart Failed!")
logging.error(stdout) logging.error(stdout)
@@ -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):