gpt4 book ai didi

node.js - 将 pm2 与 ansible 结合使用

转载 作者:太空宇宙 更新时间:2023-11-03 22:45:48 24 4
gpt4 key购买 nike

我正在尝试通过 ansible 使用 pm2 启动 Node 程序。问题是 pm2 start 命令在 ansible 下不是幂等的。再次运行就报错。

这是我的ansible游戏

- name: start the application
become_user: ubuntu
command: pm2 start app.js -i max
tags:
- app

现在,如果我第一次运行它,那么它会正常运行,但是当我再次运行它时,我会收到错误消息,告诉我脚本已经在运行。

解决此错误并通过 ansible 正确处理 pm2 的正确方法是什么。

最佳答案

在启动脚本之前,您应该删除以前的脚本,如下所示:

 - name: delete existing pm2 processes if running
command: "pm2 delete {{ server_id }}"
ignore_errors: True
become: yes
become_user: rw_user


- name: start pm2 process
command: 'pm2 start -x -i 4 --name "{{server_id}}" server.js'
become: yes
become_user: rw_user
environment:
NODE_ENV: "{{server_env}}"

关于node.js - 将 pm2 与 ansible 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45152620/

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