#!/usr/bin/python3 # coding=utf-8 import subprocess import sys import psutil def proc(key): for i in ['hadoop102', 'hadoop103']: if key == 'start': print(f"---------------{i} 节点,日志采集开启------------------------") subprocess.Popen(f"ssh {i} nohup /opt/module/flume/bin/flume-ng agent -n a1 -c /opt/module/flume/conf/ -f " f"/opt/module/flume/job/file_to_kafka.conf >/dev/null 2>&1 &", shell=True).communicate() if key == 'stop': print(f"----------------{i} 节点,日志采集关闭----------------------------------------") result = subprocess.run(['ssh', i, 'jps', '-m'], capture_output=True, text=True) for line in result.stdout.split("\n"): if "file_to_kafka" in line: subprocess.Popen(['ssh', i, 'kill', '-9', line.split()[0]]).communicate() if __name__ == '__main__': if len(sys.argv) < 2: print('参数过少,请重新调用') exit(0) argc = sys.argv[1] proc(argc)
因为flume没有专门的停止脚本。所以需要找出对应的进程号,然后关闭它。但是因为有很多进程都可能叫“Application”,所以不能通过判断进程号的名字关闭,只能通过路径来关闭。关闭那些路径中有file_to_kafka的进程。
标签:flume,__,subprocess,ssh,关闭,进程 From: https://www.cnblogs.com/lhk20213937/p/18036532