【问题标题】:"Error: /run/airflow doesn't exist. Can't create pidfile." when using systemd for Airflow webserver“错误:/run/airflow 不存在。无法创建 pidfile。”将 systemd 用于 Airflow 网络服务器时
【发布时间】:2019-02-20 19:22:37
【问题描述】:

我已根据this 将我的 Airflow 设置配置为使用 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.

调度程序似乎工作正常,在运行systemctl status airflow-scheduler.servicejournalctl -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

/etc/tmpfiles.d/airflow.conf

D /run/airflow 0755 airflow airflow

/etc/sysconfig/airflow

AIRFLOW_CONFIG= $AIRFLOW_HOME/airflow.cfg
AIRFLOW_HOME= /home/ec2-user/airflow

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

任何人都可以对错误提供任何解释以及如何解决它吗?我尽我所能尽可能地按照指示配置 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

【问题讨论】:

    标签: amazon-ec2 airflow systemd airflow-scheduler


    【解决方案1】:

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

    [Service]
    RuntimeDirectory=airflow
    RuntimeDirectoryMode=0775
    

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

    【讨论】:

    • @chorbs,您能否详细说明为什么这对您有用?
    • @Newskooler 这是我第一次使用 systemd,所以我知道意味着专家,但我认为这告诉 systemd 创建具有权限 0775 的目录 /run/airflow,并且当你不这样做时指定此项,将不会创建目录,或者不会创建具有足够许可权限的目录
    • 这正是它的作用。它使/etc/tmpfiles.d/airflow.conf 减少了。我不知道为什么它没有像这样添加到气流回购中......
    • 我将 runtimeDirectoryMode 添加到 775,但仍然出现相同的错误
    • 您是否也添加了RuntimeDirectory
    【解决方案2】:

    配置文件/etc/tmpfiles.d/airflow.confsystemd-tmpfiles-setup 服务在启动时使用。因此,服务器重启应该会创建 /run/airflow 目录。按照https://github.com/systemd/systemd/issues/8684 重启这个服务是不可能的。

    按照上面链接的建议,将airflow.conf 复制到/etc/tmpfiles.d/ 后,只需运行sudo systemd-tmpfiles --create/run/airflow 即可创建。

    【讨论】:

      【解决方案3】:

      看起来您正在运行调度程序而不是网络服务器:

      ExecStart=/bin/airflow scheduler

      您可能想要执行以下操作:

      ExecStart=/bin/airflow webserver -p 8080 --pid /run/airflow/webserver.pid

      也许您只是复制粘贴了错误的文件,在这种情况下请分享正确的文件 (airflow-webserver.service),以便我们帮助您解决此问题。

      【讨论】:

      • 抱歉,我粘贴了错误的代码。我在上面更新了它
      猜你喜欢
      • 1970-01-01
      • 2022-09-27
      • 2021-09-08
      • 2019-09-15
      • 2022-10-14
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 2019-05-14
      相关资源
      最近更新 更多