gpt4 book ai didi

linux - ansible 启动进程,如果没有使用 ps 运行

转载 作者:太空宇宙 更新时间:2023-11-04 12:40:10 25 4
gpt4 key购买 nike

我正在使用 ansible 启动 namenode 进程,如果它没有运行,我正在使用 jps 检查进程并使用 service_namenode_status 检查状态并启动使用 service_namenode_start 的过程知道如何正确使用它吗...?

  - name: Check if Namenode is running
shell: jps | grep " NameNode" | grep -v grep
ignore_errors: yes
changed_when: false
register: service_namenode_status

- name: Report status of Namenode
fail:
msg: |
Service NameNode is not running.
Return code from `jps | grep " NameNode" | grep -v grep`:
{{ service_namenode_status.rc }}
when: service_namenode_status.rc != 0
register: service_namenode_start

- name: Start Namenode
command: su - hdfs -c "/usr/hdp/current/hadoop-client/sbin/hadoop-daemon.sh --config $HADOOP_CONF_DIR start namenode"
tags: namenode
when: service_namenode_status.rc != 0

输出:

TASK [namenode : Check if Namenode is running] *********************************
fatal: [server1.hdp.vagrant.data.uc]: FAILED! => {"changed": false, "cmd": "jps | grep \" NameNode\" | grep -v grep", "delta": "0:00:00.192755", "end": "2016-11-09 10:59:10.360552", "failed": true, "rc": 1, "start": "2016-11-09 10:59:10.167797", "stderr": "", "stdout": "", "stdout_lines": [], "warnings": []}
...ignoring

TASK [namenode : Report status of Namenode] ************************************
fatal: [server1.hdp.vagrant.data.uc]: FAILED! => {"changed": false, "failed": true, "msg": "Service NameNode is not running.\nReturn code from `jps | grep \" NameNode\" | grep -v grep`:\n1 \n"}

NO MORE HOSTS LEFT *************************************************************

RUNNING HANDLER [metastore : restart postgresql] *******************************
to retry, use: --limit @/Users/krisdigitx/myLab/hdp/provisioning/site.retry

PLAY RECAP *********************************************************************
server1.hdp.vagrant.data.uc : ok=86 changed=32 unreachable=0 failed=1

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

最佳答案

试试这个:

- name: Check if Namenode is running
tags: namenode
shell: jps | grep " NameNode" | grep -v grep
ignore_errors: yes
changed_when: false
register: service_namenode_status

- name: Start Namenode
tags: namenode
command: su - hdfs -c "/usr/hdp/current/hadoop-client/sbin/hadoop-daemon.sh --config $HADOOP_CONF_DIR start namenode"
when: service_namenode_status.rc == 1

我的改变是:

  1. 我在第一部分添加了“tags: namenode”行;如果要过滤此标签,则需要收集寄存器值

  2. 我删除了您的第 2 部分并直接进入第 3 部分。

类似的配置正在为我解决类似的问题。

关于linux - ansible 启动进程,如果没有使用 ps 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40505591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com