Skip to main content
 首页 » 编程设计

python之使用 conda env 的 apache-airflow systemd 文件

2024年12月31日29TianFang

我正在尝试使用 systemd 在 Ubuntu 16.04 文件上运行 apache-airflow。我大致跟着this tutorial并安装/设置以下内容:

  • Miniconda 2,64 位
  • 已安装 gcc(sudo apt-get install gcc)
  • Conda环境,使用教程的yml文件

在以下 conda 环境中:

  • 导出 AIRFLOW_HOME="/home/ubuntu/airflow"

当我测试 Airflow 时,一切正常:

airflow webserver --port 8080 

但是每当我尝试使用 systemd 文件启动 Airflow 时,它都会失败。据我正确理解,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 守护进程时,status 返回以下错误:

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'. 

非常感谢您的帮助!

请您参考如下方法:

以下是适用于虚拟环境的 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