Dendrobates
Dendrobates

Reputation: 3534

apache-airflow systemd file using a conda env

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:

Within the following conda environment:

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!

Upvotes: 2

Views: 2728

Answers (3)

Achilleus
Achilleus

Reputation: 1944

Answer given by @kaxil kinda worked for me! But with slight modifications.

I have my Airflow installed(Using Anaconda)and is at the location:

#-> whereis airflow
airflow: /root/anaconda3/bin/airflow

Adding the below line in airflow-webserver.service file solved the issue for me.

ExecStart=/usr/bin/bash -c 'source /root/anaconda3/bin/activate ; airflow webserver --pid /run/airflow/webserver.pid'

I got another error after it saying, Error: /run/airflow doesn't exist. Can't create pidfile. , Adding the below under [Service] solved that issue as well

RuntimeDirectory=airflow
RuntimeDirectoryMode=0775

Upvotes: 0

Dendrobates
Dendrobates

Reputation: 3534

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.

Upvotes: 0

kaxil
kaxil

Reputation: 18884

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

Upvotes: 4

Related Questions