"Error: /run/airflow doesn't exist. Can't create pidfile." when using systemd for Airflow webserver
"Error: /run/airflow doesn't exist. Can't create pidfile." when using systemd for Airflow webserver
我已根据 this 使用 systemd 将我的 Airflow 设置配置为 运行。这几天很好,但它引发了一些我无法弄清楚如何修复的错误。 运行 sudo systemctl start airflow-webserver.service
并没有真正做任何事情,但 运行ning 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.
调度程序似乎工作正常,正如在 运行ning systemctl status airflow-scheduler.service
和 journalctl -f
之后验证的那样。
这是以下 systemd 文件的设置:
/usr/lib/systemd/system/airflow-webserver.服务
[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
在此错误之前,我将 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
看起来您是 运行 调度程序而不是网络服务器:
ExecStart=/bin/airflow scheduler
您可能想要执行以下操作:
ExecStart=/bin/airflow webserver -p 8080 --pid /run/airflow/webserver.pid
也许您只是复制粘贴了错误的文件,在这种情况下请分享正确的文件 (airflow-webserver.service),以便我们帮助您解决此问题。
我也遇到了这个问题,并且能够通过在 airflow-webserver.service
单元文件的 [Service]
下提供运行时目录参数来解决这个问题:
[Service]
RuntimeDirectory=airflow
RuntimeDirectoryMode=0775
我无法弄清楚如何让它单独与 /etc/tmpfiles.d/airflow.conf
一起工作。
配置文件 /etc/tmpfiles.d/airflow.conf
由 systemd-tmpfiles-setup
服务在启动时使用。因此,服务器重启应该会创建 /run/airflow 目录。无法根据 https://github.com/systemd/systemd/issues/8684.
重新启动此服务
如上 link 所建议,将 airflow.conf
复制到 /etc/tmpfiles.d/
后,应该会创建 运行 sudo systemd-tmpfiles --create
和 /run/airflow
.
我已根据 this 使用 systemd 将我的 Airflow 设置配置为 运行。这几天很好,但它引发了一些我无法弄清楚如何修复的错误。 运行 sudo systemctl start airflow-webserver.service
并没有真正做任何事情,但 运行ning 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.
调度程序似乎工作正常,正如在 运行ning systemctl status airflow-scheduler.service
和 journalctl -f
之后验证的那样。
这是以下 systemd 文件的设置:
/usr/lib/systemd/system/airflow-webserver.服务
[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
在此错误之前,我将 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
看起来您是 运行 调度程序而不是网络服务器:
ExecStart=/bin/airflow scheduler
您可能想要执行以下操作:
ExecStart=/bin/airflow webserver -p 8080 --pid /run/airflow/webserver.pid
也许您只是复制粘贴了错误的文件,在这种情况下请分享正确的文件 (airflow-webserver.service),以便我们帮助您解决此问题。
我也遇到了这个问题,并且能够通过在 airflow-webserver.service
单元文件的 [Service]
下提供运行时目录参数来解决这个问题:
[Service]
RuntimeDirectory=airflow
RuntimeDirectoryMode=0775
我无法弄清楚如何让它单独与 /etc/tmpfiles.d/airflow.conf
一起工作。
配置文件 /etc/tmpfiles.d/airflow.conf
由 systemd-tmpfiles-setup
服务在启动时使用。因此,服务器重启应该会创建 /run/airflow 目录。无法根据 https://github.com/systemd/systemd/issues/8684.
如上 link 所建议,将 airflow.conf
复制到 /etc/tmpfiles.d/
后,应该会创建 运行 sudo systemd-tmpfiles --create
和 /run/airflow
.