2016-03-23 140 views
1

殺死一個任務的最好方法是什麼?我將kafka作爲常規可執行文件運行,而不是作爲服務運行。當我向它發送殺戮時,需要一段時間才能完成並關閉。在發送kill命令以確保服務實際停止之前,我希望能夠繼續等待。在Ansible中殺死一個任務

到目前爲止,這是我的,我不知道如何可靠地做到這一點。

--- 
- name: Stopping Kafka 
    command: "bin/kafka-server-stop.sh config/server.properties" 
    args: 
    chdir: "{{base_apps}}/kafka/kafka_2.11-0.9.0.1" 
    ignore_errors: yes 

感謝

+0

也許嘗試把「nohup斌/ kafka-server-stop.sh配置/ server.properties」 –

+0

不會馬上踢出去嗎? – browskie

回答

5

這可以用wait_for模塊可能解決。

隨着wait_for模塊,可以做這樣的事情:

--- 
- name: Stopping Kafka 
    command: "bin/kafka-server-stop.sh config/server.properties" 
    args: 
    chdir: "{{base_apps}}/kafka/kafka_2.11-0.9.0.1" 
    ignore_errors: yes 

# wait until the lock file is removed 
- wait_for: path=/var/lock/kafka.lock state=absent 

這樣Ansible將繼續與鎖文件已被刪除後,才發揮作用。 wait_for模塊提供了一些其他檢查條件,請查看模塊文檔。