运行 启动后的 apache airflow worker

Run apache airflow worker after boot

我试图在系统启动后通过 rc.local(centos 7) 将 "airflow worker" 设置为 运行。

我已经以 root 身份安装了 python 和 airflow。路径是 /root/airflow/root/anaconda3.

我将此添加到 rc.local:

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
exec 2> /home/centos/rc.local.log  # send stderr from rc.local to a log file
exec 1>&2                      # send stdout to the same log file
set -x                         # tell sh to display commands before execution
export C_FORCE_ROOT="true"
/root/anaconda3/bin/python /root/anaconda3/bin/airflow worker
exit 0

当我手动尝试 运行 时它起作用了 (sh /etc/rc.local)

但是当它在启动后 运行s 时,它崩溃并在日志文件中显示此错误。

好像找不到气流的路径,不过我已经写完整了

+ export C_FORCE_ROOT=true
+ C_FORCE_ROOT=true
+ /root/anaconda3/bin/python /root/anaconda3/bin/airflow worker
Traceback (most recent call last):
  File "/root/anaconda3/bin/airflow", line 37, in <module>
    args.func(args)
  File "/root/anaconda3/lib/python3.7/site-packages/airflow/utils/cli.py", line 75, in wrapper
    return f(*args, **kwargs)
  File "/root/anaconda3/lib/python3.7/site-packages/airflow/bin/cli.py", line 1129, in worker
    sp = _serve_logs(env, skip_serve_logs)
  File "/root/anaconda3/lib/python3.7/site-packages/airflow/bin/cli.py", line 1065, in _serve_logs
    sub_proc = subprocess.Popen(['airflow', 'serve_logs'], env=env, close_fds=True)
  File "/root/anaconda3/lib/python3.7/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/root/anaconda3/lib/python3.7/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'airflow': 'airflow'

开始的地方是更改此行...

/root/anaconda3/bin/python /root/anaconda3/bin/airflow worker

/root/anaconda3/bin/airflow worker

因为你只需要调用你需要的airflow bin并传递给它一个单一的服务。请记住,您可以传递更多参数。但是调用 Python 的版本感觉没有必要。