supervisord 放弃 nodejs 进入 FATAL 状态

Posted

技术标签:

【中文标题】supervisord 放弃 nodejs 进入 FATAL 状态【英文标题】:supervisord gave up nodejs entered FATAL state 【发布时间】:2016-07-30 02:29:48 【问题描述】:

我正在将节点应用程序部署到 aws eb,这是我的 Dockerfile

FROM    ubuntu:14.04

RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Install base packages
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
    zsh \
    vim \
    git \
    curl \
    build-essential \
    nodejs \
    npm \
    supervisor

RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

RUN mkdir -p /var/run/sshd /var/log/supervisor

COPY build/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

RUN mkdir -p /app
ADD api/ /app

RUN cd /app && npm install

WORKDIR /app

EXPOSE 8090

CMD ["/usr/bin/supervisord"]

这是我的supervisord.conf

[supervisord]
nodaemon=true

[program:nodejs]
directory=/app
command=node server.js web
autorestart = true
stdout_logfile=/var/log/%(program_name)s.log
stderr_logfile=/var/log/%(program_name)s.log

这是我的stdouterr.log

/usr/lib/python2.7/dist-packages/supervisor/options.py:295: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
'Supervisord is running as root and it is searching '
2016-04-08 16:48:37,892 CRIT Supervisor running as root (no user in config file)
2016-04-08 16:48:37,892 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
2016-04-08 16:48:37,909 INFO RPC interface 'supervisor' initialized
2016-04-08 16:48:37,909 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2016-04-08 16:48:37,910 INFO supervisord started with pid 1
2016-04-08 16:48:38,912 INFO spawned: 'nodejs' with pid 11
2016-04-08 16:48:39,332 INFO exited: nodejs (exit status 8; not expected)
2016-04-08 16:48:40,334 INFO spawned: 'nodejs' with pid 13
2016-04-08 16:48:40,732 INFO exited: nodejs (exit status 8; not expected)
2016-04-08 16:48:42,736 INFO spawned: 'nodejs' with pid 15
2016-04-08 16:48:43,414 INFO exited: nodejs (exit status 8; not expected)
2016-04-08 16:48:46,419 INFO spawned: 'nodejs' with pid 17
2016-04-08 16:48:47,288 INFO exited: nodejs (exit status 8; not expected)
2016-04-08 16:48:48,289 INFO gave up: nodejs entered FATAL state, too many start retries too quickly

此时任何建议都会有所帮助。

【问题讨论】:

您的节点应用程序崩溃了吗?请尝试使用最小的节点应用程序。还可以尝试从节点打印到标准输出以调试内部出了什么问题。 你说得对,@AssafLavie 我的节点应用程序崩溃了,因为我的节点和 npm 版本没有设置正确。 【参考方案1】:

正如 cmets 中的 @AssafLavie 所说,节点应用程序崩溃了。它崩溃的原因是因为我必须将nodenpm 版本设置为我的package.json 文件中的指定版本。

我的Dockerfile 现在看起来像

FROM    ubuntu:14.04

RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Install base packages
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
    zsh \
    vim \
    git \
    curl \
    build-essential \
    nodejs \
    npm \
    supervisor

RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

# Added the following 5 lines

RUN npm install -g n

RUN n 5.0.0

RUN rm /usr/bin/node
RUN ln -s /usr/local/bin/node /usr/bin/node

RUN npm install npm@3.8.5 -g

# End of the added lines to specify node and npm versions

RUN mkdir -p /var/run/sshd /var/log/supervisor

COPY build/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

RUN mkdir -p /app
ADD api/ /app

RUN cd /app && npm install

WORKDIR /app

EXPOSE 8090

CMD ["/usr/bin/supervisord"]

【讨论】:

以上是关于supervisord 放弃 nodejs 进入 FATAL 状态的主要内容,如果未能解决你的问题,请参考以下文章

supervisor常用命令

supervisord部署多项目

supervisor部署python项目

Centos7 中使用Supervisor守护进程

supervisord 小记

停止supervisord:关闭