在Ubuntu上运行NodeJS作为服务

时间:2016-08-04 17:35:18

标签: node.js ubuntu google-api-nodejs-client

我尝试将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:Unknown stanza

4-

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

2 个答案:

答案 0 :(得分:2)

我是用暴发户做到的:

  1. 安装新贵var_dump( str_replace( ['/', '-', '.'], '', ucwords( $acceptContentType, '/-.' ) ) );
  2. 创建.conf文件以启动Node.js program sudo apt-get install upstart
  3. 修改您创建的sudo vim /etc/init/servicelocator.conf并插入以下文字:
  4. 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

答案 1 :(得分:0)

我的最佳答案

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和wirte :wq

5- sudo apt-get install upstart

6- sudo start servicelocator