Skip to content

Commit

Permalink
Allow PID file path to be relative when daemonize a process (schedule…
Browse files Browse the repository at this point in the history
…r, kerberos, etc) (#13232)

Closes #13200.

Currently, if the PID file path provided is relative,
the process silently fails to launch.

This fix ensures the PID path specified to be
a normalized absolutized path eventually (expand with cwd),
no matter the given value is relative or absolute.
  • Loading branch information
XD-DENG authored Dec 22, 2020
1 parent aa00e9b commit 93e4787
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions airflow/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,11 @@ def setup_locations(process, pid=None, stdout=None, stderr=None, log=None):
stdout = os.path.join(settings.AIRFLOW_HOME, f'airflow-{process}.out')
if not log:
log = os.path.join(settings.AIRFLOW_HOME, f'airflow-{process}.log')

if not pid:
pid = os.path.join(settings.AIRFLOW_HOME, f'airflow-{process}.pid')
else:
pid = os.path.abspath(pid)

return pid, stdout, stderr, log

Expand Down
17 changes: 17 additions & 0 deletions tests/utils/test_cli_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ def test_cli_create_user_supplied_password_is_masked(self, given_command, expect
command = json.loads(command.replace("'", '"'))
self.assertEqual(command, expected_command)

def test_setup_locations_relative_pid_path(self):
relative_pid_path = "fake.pid"
pid_full_path = os.path.join(os.getcwd(), relative_pid_path)
pid, _, _, _ = cli.setup_locations(process="fake_process", pid=relative_pid_path)
self.assertEqual(pid, pid_full_path)

def test_setup_locations_absolute_pid_path(self):
abs_pid_path = os.path.join(os.getcwd(), "fake.pid")
pid, _, _, _ = cli.setup_locations(process="fake_process", pid=abs_pid_path)
self.assertEqual(pid, abs_pid_path)

def test_setup_locations_none_pid_path(self):
process_name = "fake_process"
default_pid_path = os.path.join(settings.AIRFLOW_HOME, f"airflow-{process_name}.pid")
pid, _, _, _ = cli.setup_locations(process=process_name)
self.assertEqual(pid, default_pid_path)


@contextmanager
def fail_action_logger_callback():
Expand Down

0 comments on commit 93e4787

Please sign in to comment.