首页 > 解决方案 > 使用 conda env 的 apache-airflow systemd 文件

问题描述

我正在尝试apache-airflow使用 systemd 在 Ubuntu 16.04 文件上运行。我大致按照本教程安装/设置了以下内容:

在以下 conda 环境中:

当我测试气流时,一切正常:

airflow webserver --port 8080

但是每当我尝试使用 systemd 文件启动气流时,它都会失败。据我正确理解,systemd 文件使用了 conda 环境。我的 systemd 文件如下所示:

[Unit]
Description=Airflow webserver daemon

[Service]
User=ubuntu
Group=ubuntu
Type=simple
ExecStart=/home/ubuntu/miniconda2/envs/airflow-tutorial/bin/airflow webserver --port 8080
Restart=on-failure
RestartSec=5s
PrivateTmp=true

[Install]
WantedBy=multi-user.target

当我启动/启用 systemd 守护程序时,状态返回以下错误:

airflow-webserver.service - Airflow webserver daemon
   Loaded: loaded (/etc/systemd/system/airflow-webserver.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Thu 2018-09-13 08:59:00 UTC; 1s ago
  Process: 18410 ExecStart=/home/ubuntu/miniconda2/envs/airflow-tutorial/bin/airflow webserver --port 8080 (code=exited, status=1/FAILURE)
 Main PID: 18410 (code=exited, status=1/FAILURE)

Sep 13 08:59:00 ip-172-31-46-255 systemd[1]: airflow-webserver.service: Main process exited, code=exited, status=1/FAILURE
Sep 13 08:59:00 ip-172-31-46-255 systemd[1]: airflow-webserver.service: Unit entered failed state.
Sep 13 08:59:00 ip-172-31-46-255 systemd[1]: airflow-webserver.service: Failed with result 'exit-code'.

高度赞赏帮助!

标签: pythonpython-2.7ubuntuairflow

解决方案


以下是airflow-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]
PIDFile=/run/airflow/webserver.pid
EnvironmentFile=/etc/default/airflow
User=airflow
Group=airflow
Type=simple
ExecStart=/usr/bin/bash -c 'source /usr/local/airflow/venv/bin/activate ; airflow webserver --pid /run/airflow/webserver.pid'
Restart=on-failure
RestartSec=5s
PrivateTmp=true

[Install]
WantedBy=multi-user.target

推荐阅读