
我配置了安裝在 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/
所有用戶都可以訪問的資料夾)
ExecStart
需要airflow
啟動實際安裝airflow的conda環境。為此,我添加了在 中看到的兩個命令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
我希望現在您已經解決了您的問題,但這裡是我的解決方案供參考。
我解決這個問題的方法是添加一定程度的間接來發射氣流。我有一個 bash 腳本,例如airflow_runner.sh
包含以下內容
conda activate airflow-env
$AIRFLOW_BIN/airflow $@
然後在我的 systemd 單元檔案中
ExecStart=PATH_TO_SCRIPT/airflow_runner.sh webserver --pid /run/airflow/webserver.pid