“错误:/run/airflow 不存在。无法创建 pidfile。” 将 systemd 用于 Airflow 网络服务器时

Cza*_*ing 5 amazon-ec2 systemd airflow airflow-scheduler

我已经根据这个配置了我的气流设置来与 systemd 一起运行。好几天了,但它引发了一些我不知道如何修复的错误。运行sudo systemctl start airflow-webserver.service除了运行之外并没有真正做任何事情airflow webserver(但是,为了我们的目的需要使用 systemd)。

要了解错误是什么,我运行sudo systemctl status airflow-webserver.service,它给出了以下状态和错误:

Feb 20 18:54:43 ip-172-31-25-17.ec2.internal airflow[19660]: [2019-02-20 18:54:43,774] {models.py:258} INFO - Filling up the DagBag from /home/ec2-user/airflow/dags
Feb 20 18:54:43 ip-172-31-25-17.ec2.internal airflow[19660]: /home/ec2-user/airflow/dags/statcan_1410009501.py:33: SyntaxWarning: name 'pg_hook' is assigned to before global declaration
Feb 20 18:54:43 ip-172-31-25-17.ec2.internal airflow[19660]: global pg_hook
Feb 20 18:54:43 ip-172-31-25-17.ec2.internal airflow[19660]: /usr/lib/python2.7/site-packages/airflow/utils/helpers.py:346: DeprecationWarning: Importing 'PythonOperator' directly from 'airflow.operators' has been deprecated. Please import from 'airflow.operators.[operat...irely in Airflow 2.0.
Feb 20 18:54:43 ip-172-31-25-17.ec2.internal airflow[19660]: DeprecationWarning)
Feb 20 18:54:43 ip-172-31-25-17.ec2.internal airflow[19660]: /usr/lib/python2.7/site-packages/airflow/utils/helpers.py:346: DeprecationWarning: Importing 'BashOperator' directly from 'airflow.operators' has been deprecated. Please import from 'airflow.operators.[operator...irely in Airflow 2.0.
Feb 20 18:54:43 ip-172-31-25-17.ec2.internal airflow[19660]: DeprecationWarning)
Feb 20 18:54:44 ip-172-31-25-17.ec2.internal airflow[19660]: [2019-02-20 18:54:44,528] {settings.py:174} INFO - setting.configure_orm(): Using pool settings. pool_size=5, pool_recycle=1800
Feb 20 18:54:45 ip-172-31-25-17.ec2.internal airflow[19660]: [2019-02-20 18:54:45 +0000] [19733] [INFO] Starting gunicorn 19.9.0
Feb 20 18:54:45 ip-172-31-25-17.ec2.internal airflow[19660]: Error: /run/airflow doesn't exist. Can't create pidfile.
Run Code Online (Sandbox Code Playgroud)

调度程序似乎工作正常,在运行systemctl status airflow-scheduler.service和后验证journalctl -f

以下是以下 systemd 文件的设置:

/usr/lib/systemd/system/airflow-webserver.service

[Unit]
Description=Airflow scheduler daemon
After=network.target postgresql.service mysql.service redis.service rabbitmq-server.service
Wants=postgresql.service mysql.service redis.service rabbitmq-server.service

[Service]
EnvironmentFile=/etc/sysconfig/airflow
User=ec2-user
Type=simple
ExecStart=/bin/airflow scheduler
Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

/etc/tmpfiles.d/airflow.conf

D /run/airflow 0755 airflow airflow
Run Code Online (Sandbox Code Playgroud)

/etc/sysconfig/airflow

AIRFLOW_CONFIG= $AIRFLOW_HOME/airflow.cfg
AIRFLOW_HOME= /home/ec2-user/airflow
Run Code Online (Sandbox Code Playgroud)

在出现此错误之前,我将气流安装从根目录移动到主目录。不确定它是否会影响我的设置,但把它放在这里以防万一。

任何人都可以对错误以及如何修复它提供任何解释吗?我已尽力按照指示配置 systemd,但也许我遗漏了什么?

编辑2:

抱歉,我粘贴了错误的代码。所以这是我的气流 webserver.service 代码

[Unit]
Description=Airflow webserver daemon
After=network.target postgresql.service mysql.service redis.service rabbitmq-server.service
Wants=postgresql.service mysql.service redis.service rabbitmq-server.service

[Service]
EnvironmentFile=/etc/sysconfig/airflow
User=ec2-user
Type=simple
ExecStart=/bin/airflow webserver --pid /run/airflow/webserver.pid
Restart=on-failure
RestartSec=5s
PrivateTmp=true

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

cho*_*rbs 8

我也遇到了这个问题,并且能够通过[Service]airflow-webserver.service单元文件中提供运行时目录参数来解决这个问题:

[Service]
RuntimeDirectory=airflow
RuntimeDirectoryMode=0775
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何让它/etc/tmpfiles.d/airflow.conf独自工作。