启动 node.js 服务器时 Ansible 挂起 [英] Ansible hangs when starting node.js server

查看:39
本文介绍了启动 node.js 服务器时 Ansible 挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 ansible playbook 中启动我的 node.js 应用程序.现在,最终指令如下所示:

I would like to start my node.js app in an ansible playbook. Right now, the final directive looks like this:

  - name: start node server
    shell: chdir=${app_path} npm start&

问题是 ansible 永远不会从这里返回.我怎样才能让它继续?

The problem is that ansible never returns from this. How can I make it continue?

推荐答案

Forever 似乎是最简单的以及启动和守护 Node.js 应用程序的最简单方法.目前,没有永久的 Ansible 模块,但您仍然可以使用以下 play 永久安装并运行您的应用:

Forever seems to be the simplest and easiest way of starting and daemonizing Node.js apps. Currently, there's no Ansible module for forever, but you can still use the following plays to install forever and run your app:

- name: "Install forever (to run Node.js app)."
  npm: name=forever global=yes state=present

- name: "Check list of Node.js apps running."
  command: forever list
  register: forever_list
  changed_when: false

- name: "Start example Node.js app."
  command: forever start /path/to/app.js
  when: "forever_list.stdout.find('/path/to/app.js') == -1"

这完全是幂等的,对我来说效果很好.您可以为 Ansible 编写一个 forever 小模块来为您完成这些工作(例如 service 模块),但现在可以使用.

This is completely idempotent, and works great for me. You could program a little forever module for Ansible to do this stuff for you (like the service module), but this works for now.

我有一个关于如何启动节点的完整示例.在 Server Check.in 的博客上使用 Forever and Ansible 的 Node.js 应用.

这篇关于启动 node.js 服务器时 Ansible 挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆