systemd를 사용하여 conda 환경 내에서 공기 흐름 실행

systemd를 사용하여 conda 환경 내에서 공기 흐름 실행

일부 예약된 자동화를 실행하기 위해 conda 환경 내에 설치된 Airflow 서버를 구성했습니다. 현재는 스케줄러, 워커, 웹서버를 를 이용하여 직접 실행하고 있는데 nohup, 좀 더 견고하게 관리하려면 systemd를 이용하고 싶습니다.

그러나 systemctl start. 내 .service파일에 다음을 추가했습니다 .

ExecStartPre=. /etc/profile ; /home/shared/miniconda2/bin/conda activate airflow
ExecStart=/home/shared/miniconda2/envs/airflow/bin/airflow webserver --pid /run/airflow/webserver.pid

( 사용자가 아닌 모든 사용자가 액세스할 수 있는 shared/폴더 )/home/

ExecStartairflow실제로 공기 흐름이 활성화되기 위해 설치된 콘다 환경이 필요합니다 . 이를 위해 에 표시된 두 개의 명령을 추가했습니다 ExecStartPre. 두 번째 명령은 실제로 이 환경을 활성화합니다. 이것만 실행하면 가 반환되므로 로드되었는지 CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.확인하기 위해 첫 번째 항목을 추가했습니다 /etc/profile.d/conda.sh.

그러나 Gunicorn 서버를 실행하는 동안에는 여전히 실패합니다.

Running the Gunicorn Server with:
Workers: 4 sync
Host: 0.0.0.0:8080
Timeout: 120
Logfiles: - -
=================================================================
Traceback (most recent call last):
  File "/home/shared/miniconda2/envs/airflow/bin/airflow", line 28, in <module>
    args.func(args)
  File "/home/shared/miniconda2/envs/airflow/lib/python2.7/site-packages/airflow/bin/cli.py", line 844, in webserver
    gunicorn_master_proc = subprocess.Popen(run_args)
  File "/home/shared/miniconda2/envs/airflow/lib/python2.7/subprocess.py", line 390, in __init__
    errread, errwrite)
  File "/home/shared/miniconda2/envs/airflow/lib/python2.7/subprocess.py", line 1025, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

(가독성을 높이기 위해 타임스탬프는 생략했습니다.)

이로 인해 여러 가지 질문이 제기됩니다.

  • 내 서비스가 실패하는 원인은 무엇입니까?
  • 내 설정이 무의미합니까(systemd + conda + airflow)?
  • 말도 안되는 경우 직접 실행하는 것보다 공기 흐름을 더 강력하게 실행하는 더 좋은 방법이 있습니까? 저는 특히 systemd가 제공하는 enable및 옵션 에 관심이 있었습니다 restart.

답변1

지금쯤이면 문제가 해결되셨기를 바랍니다. 참고로 제 해결 방법은 다음과 같습니다.

제가 해결한 방법은 공기 흐름을 시작하기 위한 간접 수준을 추가하는 것이었습니다. 예를 들어 airflow_runner.sh다음과 같은 bash 스크립트가 있습니다.

conda activate airflow-env
$AIRFLOW_BIN/airflow $@

그런 다음 내 시스템 단위 파일에서

ExecStart=PATH_TO_SCRIPT/airflow_runner.sh webserver --pid /run/airflow/webserver.pid

관련 정보