【问题标题】:Ansible task to start mongod service hangs forever启动 mongod 服务的 Ansible 任务永远挂起
【发布时间】:2018-07-25 18:56:32
【问题描述】:

此任务在 60 秒后失败,删除异步和轮询只会导致它永远挂起。如果它再次运行剧本,则任务成功完成。这是在 CentOS 7 上运行的

- name: Start mongod service
  async: 60
  poll: 10
  service:
    enabled: yes
    name: mongod
    state: running

失败了! => {"changed": false, "msg": "异步任务未完成 在要求的时间内”}

【问题讨论】:

    标签: mongodb ansible


    【解决方案1】:

    我建议对 mongodb 使用 systemd 配置,然后使用模块 systemd 而不是 service 模块。

    系统示例

    [Unit]
    Description=MongoDB Database Service
    Wants=network.target
    After=network.target
    
    [Service]
    Type=simple
    PermissionsStartOnly=true
    ExecStartPre=/bin/mkdir -p /var/lib/mongod
    ExecStartPre=/bin/chown mongodb:mongodb /var/lib/mongod
    ExecStart=/usr/bin/mongod --config /etc/mongod.conf
    ExecReload=/bin/kill -HUP $MAINPID
    Restart=always
    User=mongodb
    Group=mongodb
    
    [Install]
    WantedBy=multi-user.target
    

    任务:

    - name: Make sure a service is running
      systemd:
        state: started
        name: mongodb
    

    systemd 配置来源:github

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多