Repository: incubator-airflow Updated Branches: refs/heads/v1-8-test f0d072cfb -> aef7dd0a5
[AIRFLOW-1121][AIRFLOW-1004] Fix `airflow webserver --pid` to write out pid file After AIRFLOW-1004, --pid option is no longer honored and the pid file is not being written out. This PR fixes it. Closes #2249 from sekikn/AIRFLOW-1121 (cherry picked from commit 8d643897cf6171d110e7139fb31c3d4d47c3acca) Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/aef7dd0a Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/aef7dd0a Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/aef7dd0a Branch: refs/heads/v1-8-test Commit: aef7dd0a53411f3edb2333cb36a457056e5ab652 Parents: f0d072c Author: Kengo Seki <sek...@apache.org> Authored: Wed Apr 19 12:31:10 2017 -0700 Committer: Chris Riccomini <criccom...@apache.org> Committed: Thu Apr 20 15:22:21 2017 -0700 ---------------------------------------------------------------------- airflow/bin/cli.py | 3 ++- tests/core.py | 36 ++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/aef7dd0a/airflow/bin/cli.py ---------------------------------------------------------------------- diff --git a/airflow/bin/cli.py b/airflow/bin/cli.py index e4755c7..8e92ea1 100755 --- a/airflow/bin/cli.py +++ b/airflow/bin/cli.py @@ -776,6 +776,7 @@ def webserver(args): '-t', str(worker_timeout), '-b', args.hostname + ':' + str(args.port), '-n', 'airflow-webserver', + '-p', str(pid), '-c', 'airflow.www.gunicorn_config' ] @@ -786,7 +787,7 @@ def webserver(args): run_args += ['--error-logfile', str(args.error_logfile)] if args.daemon: - run_args += ['-D', '-p', str(pid)] + run_args += ['-D'] if ssl_cert: run_args += ['--certfile', ssl_cert, '--keyfile', ssl_key] http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/aef7dd0a/tests/core.py ---------------------------------------------------------------------- diff --git a/tests/core.py b/tests/core.py index 4fd2f08..c36c6c2 100644 --- a/tests/core.py +++ b/tests/core.py @@ -1398,6 +1398,14 @@ class CliTests(unittest.TestCase): os.remove('variables1.json') os.remove('variables2.json') + def _wait_pidfile(self, pidfile): + while True: + try: + with open(pidfile) as f: + return int(f.read()) + except: + sleep(1) + def test_cli_webserver_foreground(self): import subprocess @@ -1417,18 +1425,26 @@ class CliTests(unittest.TestCase): @unittest.skipIf("TRAVIS" in os.environ and bool(os.environ["TRAVIS"]), "Skipping test due to lack of required file permission") + def test_cli_webserver_foreground_with_pid(self): + import subprocess + + # Run webserver in foreground with --pid option + pidfile = tempfile.mkstemp()[1] + p = subprocess.Popen(["airflow", "webserver", "--pid", pidfile]) + + # Check the file specified by --pid option exists + self._wait_pidfile(pidfile) + + # Terminate webserver + p.terminate() + p.wait() + + @unittest.skipIf("TRAVIS" in os.environ and bool(os.environ["TRAVIS"]), + "Skipping test due to lack of required file permission") def test_cli_webserver_background(self): import subprocess import psutil - def wait_pidfile(pidfile): - while True: - try: - with open(pidfile) as f: - return int(f.read()) - except IOError: - sleep(1) - # Confirm that webserver hasn't been launched. self.assertEqual(1, subprocess.Popen(["pgrep", "-c", "airflow"]).wait()) self.assertEqual(1, subprocess.Popen(["pgrep", "-c", "gunicorn"]).wait()) @@ -1436,7 +1452,7 @@ class CliTests(unittest.TestCase): # Run webserver in background. subprocess.Popen(["airflow", "webserver", "-D"]) pidfile = cli.setup_locations("webserver")[0] - wait_pidfile(pidfile) + self._wait_pidfile(pidfile) # Assert that gunicorn and its monitor are launched. self.assertEqual(0, subprocess.Popen(["pgrep", "-c", "airflow"]).wait()) @@ -1444,7 +1460,7 @@ class CliTests(unittest.TestCase): # Terminate monitor process. pidfile = cli.setup_locations("webserver-monitor")[0] - pid = wait_pidfile(pidfile) + pid = self._wait_pidfile(pidfile) p = psutil.Process(pid) p.terminate() p.wait()