Search code examples
celeryairflowsystemd

Unable to start celery worker from airflow using systemd


I am trying to set up airflow using systemd. Normally when I do it using screens everything works perfectly. But when I start the service service airflow-worker start I get the following error.

Mar 02 08:52:57 IP systemd[1]: Started Airflow celery worker daemon.
Mar 02 08:52:57 IP airflow[16162]: [2019-03-02 08:52:57,489] {settings.py:174} INFO - settings.configure_orm(): Using pool settings. pool_size=5, pool_recycle=1800, pid=16162
Mar 02 08:52:57 IP airflow[16162]: [2019-03-02 08:52:57,969] {__init__.py:51} INFO - Using executor CeleryExecutor
Mar 02 08:52:58 IP airflow[16162]: Traceback (most recent call last):
Mar 02 08:52:58 IP airflow[16162]:   File "/bin/airflow", line 32, in <module>
Mar 02 08:52:58 IP airflow[16162]:     args.func(args)
Mar 02 08:52:58 IP airflow[16162]:   File "/home/ubuntu/.local/lib/python2.7/site-packages/airflow/utils/cli.py", line 74, in wrapper
Mar 02 08:52:58 IP airflow[16162]:     return f(*args, **kwargs)
Mar 02 08:52:58 IP airflow[16162]:   File "/home/ubuntu/.local/lib/python2.7/site-packages/airflow/bin/cli.py", line 1066, in worker
Mar 02 08:52:58 IP airflow[16162]:     sp = subprocess.Popen(['airflow', 'serve_logs'], env=env, close_fds=True)
Mar 02 08:52:58 IP airflow[16162]:   File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
Mar 02 08:52:58 IP airflow[16162]:     errread, errwrite)
Mar 02 08:52:58 IP airflow[16162]:   File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
Mar 02 08:52:58 IP airflow[16162]:     raise child_exception
Mar 02 08:52:58 IP airflow[16162]: OSError: [Errno 20] Not a directory
Mar 02 08:52:58 IP systemd[1]: airflow-worker.service: Main process exited, code=exited, status=1/FAILURE
Mar 02 08:52:58 IP systemd[1]: airflow-worker.service: Failed with result 'exit-code'.

Following is the sequence in which I start the service:

service airflow-webserver start

service airflow-worker start

service airflow-scheduler start

service airflow-flower start

I am referring to the following documentation. http://site.clairvoyantsoft.com/installing-and-configuring-apache-airflow/

P.S: rabbitmq and Postgres are running fine in the background.


Solution

  • I was able to solve my issue by doing the following:

    1. Created a file at vim /etc/sysconfig/airflow

    2. Added environment variable

    AIRFLOW_CONFIG=/home/ubuntu/airflow/airflow.cfg
    AIRFLOW_HOME=/home/ubuntu/airflow
    PATH=/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/.local/bin/
    
    
    1. Restarted the worker