运行 Ubuntu 上的 NodeJS 即服务

Run NodeJS as a Service on Ubuntu

我正在尝试 运行 nodejs 作为此步骤的服务 1- sudo vim servicelocator.conf 2- past this .conf

description "node.js server"
author      "mahmoud elgohary"
# Used to Be: Start on Startup
# until we found some mounts weren't ready yet while booting:
start on started mountall
stop on shutdown

# Automatically Respawn:
respawn
respawn limit 99 5

script
    # Not sure why $HOME is needed, but we found that it is:
    export HOME="/root"

    exec /usr/bin/node /var/lib/nodejsproject/servicelocator/server.js >> /var/log/node.log 2>&1
end script

post-start script
   # Optionally put a script here that will notifiy you node has (re)started
   # /root/bin/hoptoad.sh "node.js has started!"
end script

3- init-checkconf /etc/init/servicelocator.conf

错误:文件/etc/init/servicelocator.conf:语法无效:init:servicelocator.conf:1:未知节

4-

ubuntu@ip-172-31-37-243:/etc/init$ sudo start servicelocator
 start: Unknown job: servicelocator

我和暴发户一起做的:

  1. 安装新贵sudo apt-get install upstart
  2. 创建 .conf 文件以启动您的 Node.js 程序 sudo vim /etc/init/servicelocator.conf
  3. 编辑您创建的 servicelocator.conf 并插入以下文本:
#!upstart
description "servicelocator"

start on runlevel [2345] stop on runlevel [06]

#Automatically Respawn: respawn respawn limit 99 5

exec /usr/bin/node /var/lib/nodejsproject/servicelocator/server.js >> /var/log/node.log

保存并关闭文件。
启动服务:sudo start servicelocator

我的最佳答案步骤

1- 运行 sudo vim servicelocator.conf

2- 通过此配置

description "node.js server"
author      "mahmoud elgohary"

#!upstart
description "servicelocator"
start on runlevel [2345] 
stop on runlevel [06]

# Automatically Respawn:
respawn
respawn limit 99 5

script
    # Not sure why $HOME is needed, but we found that it is:
    export HOME="/root"

    exec /usr/bin/nodejs /var/lib/nodejsproject/servicelocator/server.js >> /var/log/node.log 2>&1
end script

post-start script
   # Optionally put a script here that will notifiy you node has (re)started
   # /root/bin/hoptoad.sh "node.js has started!"
end script

3- 按 Esc 并写入 :wq

5- sudo apt-get install upstart

6-sudo start servicelocator