将气流调度程序作为守护进程运行的问题

时间:2017-09-28 18:43:07

标签: python amazon-ec2 ubuntu-16.04 airflow apache-airflow

我有一个使用LocalExecutor运行气流1.8.0的EC2实例。根据文档,我预计以下两个命令之一会以守护进程模式引发调度程序:

airflow scheduler --daemon --num_runs=20

airflow scheduler --daemon=True --num_runs=5

但事实并非如此。第一个命令似乎正在运行,但它只返回以下输出,然后返回终端而不产生任何后台任务:

[2017-09-28 18:15:02,794] {__init__.py:57} INFO - Using executor LocalExecutor
[2017-09-28 18:15:03,064] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python3.5/lib2to3/Grammar.txt
[2017-09-28 18:15:03,203] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python3.5/lib2to3/PatternGrammar.txt

第二个命令产生错误:

airflow scheduler: error: argument -D/--daemon: ignored explicit argument 'True'

这很奇怪,因为根据docs --daemon=True应该是airflow scheduler调用的有效参数。

深入挖掘了我this StackOverflow post,其中一个回复建议实施systemd,以便根据this repo提供的代码将气流调度程序作为后台进程处理。

我对脚本的轻微修改后的修改将发布为以下Gists。我正在使用带有Ubuntu 16.04.3的vanilla m4.xlarge EC2实例:

从那里我打电话:

sudo systemctl enable airflow-scheduler
sudo systemctl start airflow-scheduler

没有任何反应。虽然我在这个实例上运行了更复杂的DAG,I am using this dummy case创建了一个简单的测试,它也可以作为一个监听器,让我知道调度程序何时按计划运行。

我一直在使用journalctl -f进行调试。以下是调度程序进程的几行输出。没有明显的问题,但我的任务没有执行,并且没有为测试DAG生成日志,这将帮助我放大错误。问题出在这里吗?

Sep 28 18:39:30 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:30,965] {dag_processing.py:627} INFO - Started a process (PID: 21822) to generate tasks for /home/ubuntu/airflow/dags/scheduler_test_dag.py - logging into /home/ubuntu/airflow/logs/scheduler/2017-09-28/scheduler_test_dag.py.log
Sep 28 18:39:31 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:31,016] {jobs.py:1002} INFO - No tasks to send to the executor
Sep 28 18:39:31 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:31,020] {jobs.py:1440} INFO - Heartbeating the executor
Sep 28 18:39:32 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:32,022] {jobs.py:1404} INFO - Heartbeating the process manager
Sep 28 18:39:32 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:32,023] {jobs.py:1440} INFO - Heartbeating the executor
Sep 28 18:39:33 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:33,024] {jobs.py:1404} INFO - Heartbeating the process manager
Sep 28 18:39:33 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:33,025] {dag_processing.py:559} INFO - Processor for /home/ubuntu/airflow/dags/capone_dash_dag.py finished
Sep 28 18:39:33 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:33,026] {dag_processing.py:559} INFO - Processor for /home/ubuntu/airflow/dags/scheduler_test_dag.py finished

当我手动运行airflow scheduler时,一切正常。由于我的测试DAG的开始日期是9月9日,因此从那时起每分钟都要回填,产生一个运行时间自动收报机。但是,当我使用systemd将调度程序作为守护程序运行时,它完全安静,没有明显的错误来源。

有什么想法?

2 个答案:

答案 0 :(得分:12)

文档可能已过时了?

我通常按以下方式启动Airflow

airflow kerberos -D
airflow scheduler -D
airflow webserver -D

这是airflow webeserver --help输出(来自版本1.8):

  

-D, - damonmon Daemonize而不是在前台运行

请注意,那里没有布尔标志。文档必须修复。

airflow scheduler -D失败时的快速提示:

这包含在评论中,但似乎值得一提。运行气流调度程序时,它将创建文件$AIRFLOW_HOME/airflow-scheduler.pid。如果您尝试重新运行气流调度程序守护程序进程,这几乎肯定会产生文件$AIRFLOW_HOME/airflow-scheduler.err,它会告诉您lockfile.AlreadyLocked: /home/ubuntu/airflow/airflow-scheduler.pid is already locked。如果您的调度程序守护程序确实没有使用,并且您发现自己需要重新启动,请执行以下命令:

sudo rm $AIRFLOW_HOME airflow-scheduler.err  airflow-scheduler.pid
airflow scheduler -D 

这使我的调度程序重回正轨。

答案 1 :(得分:3)

关于通过systemd启动任务:

当以这种方式运行时,我遇到了PATH变量的问题,最初是空的。也就是说,当您写入文件/ etc / sysconfig / airflow:

PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:$PATH

你真的写道:

PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin

因此,变量PATH不包含/bin,它是LocalExecutor用来运行任务的bash实用程序。

所以我不明白为什么在这个文件中你没有指定AIRFLOW_HOME。也就是说,Airflow正在寻找其配置文件的目录。