apache-airflow systemd file using a conda env

你。 提交于 2019-12-11 02:06:50

问题


I'm trying to run apache-airflow on a Ubuntu 16.04 file, using systemd. I roughly followed this tutorial and installed/setup the following:

  • Miniconda 2, 64-bit
  • Installed gcc (sudo apt-get install gcc)
  • Conda environment, using the yml file of the tutorial

Within the following conda environment:

  • export AIRFLOW_HOME="/home/ubuntu/airflow"

When I test Airflow, everything works fine:

airflow webserver --port 8080

But whenever I try to launch airflow using a systemd file, it fails. The systemd file makes use of the conda environment, as far as I understand correctly. My systemd file looks as follows:

[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

When I start/enable the systemd daemon, status returns the following error:

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

Help is highly appreciated!


回答1:


The following is airflow-webserver.service that works for me with a virtual environment:

[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



回答2:


One completetely different, but much easier solution which worked for me:

  1. Add new sudo user with sudo rights, for example airflow
  2. Install apache-airflow in environment as airflow user
  3. Run airflow daemon using: airflow webserver --port 8080 -D

This runs airflow as daemon background process. You can just switch back to other user and continue creating dags, etc.



来源:https://stackoverflow.com/questions/52310217/apache-airflow-systemd-file-using-a-conda-env

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!