根据FAQ,从推荐的运行分离进程的方法中,唯一适合我的是screen
,因为我无法在服务器上安装程序,并且似乎无法使nohup工作。我想:
- 运行(命令),使命令继续运行而不阻塞。
- 知道我正在运行的进程的pid,以便我可以稍后杀死它。
到目前为止,没有任何nohup重定向和screen -md command
的组合对我有效。
特别是,当直接在服务器上执行而不是通过fabric的run功能时,运行该命令行确实有效。当函数返回时,我认为进程已关闭,我没有时间查看它:
nohup /opt/logstash/bin/logstash agent -f /home/unicryo/PVSS_projects/GenerateErrors/logstash_conf/logstash-config-minimum.cfg >> test.out 2>&1 &
您无法nohup
进程,因为Fabric不支持它。
我强烈建议通过进程管理器运行这个命令(参见Fabric的文档建议),因为它更容易管理(例如service logstash stop
,而不是在屏幕会话中找到正在运行的命令),而且更干净,但是你应该能够通过Fabric获得以下内容:
run("screen -d -m '/opt/logstash/bin/logstash agent -f /home/unicryo/PVSS_projects/GenerateErrors/logstash_conf/logstash-config-minimum.cfg'")