的centos + +的NodeJS永远(startstop)

时间:2012-06-26 13:37:18

标签: bash node.js centos forever

美好的一天,我有一个永远的开始\停止脚本的问题。

CentOS 6.2
内核2.6.32-220.el6.x86_64
nodejs v0.6.19
npm v 1.1.24
forever@0.9.2

我创建了运行我的脚本的nologin用户

/ etc / passwd
节点:X:501:501 :: / usr / sbin目录/ NOLOGIN:/斌/庆典:在/ usr / local / bin目录/节点:在/ usr / local / bin目录/永远:在/ usr / local / bin目录:在/ usr /本地/ LIB / node_modules /永远/ bin中

我创建脚本并命名为hello2.js

  #!/bin/bash
echo "aight" 

并尝试运行

  [max@localhost Desktop]$ forever start hello2.js
    info: Forever processing file: hello2.js
    [max@localhost Desktop]$ forever list
    info: Forever processes running
    data: uid command script forever pid logfile uptime
    data: [0] n4EB node hello2.js 2675 2728 /home/max/.forever/n4EB.log 0:0:0:0.130

一切都好。接下来我为hello2.js创建了启动 - 停止脚本,并将其命名为节点

===========================

#!/bin/bash

#proccessname: node

USER=node
PWD=node
node=node
forever=forever

start() {

         forever start -l forever.log -o out.log -e err.log /home/max/Desktop/hello2.js

            }

stop(){

      /usr/local/bin/forever stopall
     }

  restart() {
   stop
   start
    }
    status(){
    /usr/local/bin/forever list
    }

    #see how we were called
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    stop
    start
    ;;
    status)
    status
    ;;
    *)
    echo $ "usage $0 {start | stop | status | restart}"
    exit 1
    esac
    exit 0

========================================= 让它可执行。

接下来我想看看这是如何工作的

[max@localhost Desktop]$ ./node
$ usage ./node {start | stop | status | restart}

[max@localhost Desktop]$ ./node start
info: Forever processing file: /home/max/Desktop/hello2.js

[max@localhost Desktop]$ ./node status
**info: No forever processes running**

但是

[max@localhost Desktop]$ forever start hello2.js
info: Forever processing file: hello2.js
[max@localhost Desktop]$ forever list
info: Forever processes running
data: uid command script forever pid logfile uptime
data: [0] n4EB node hello2.js 2675 2728 /home/max/.forever/n4EB.log 0:0:0:0.130
[max@localhost Desktop]$
我错了吗?

1 个答案:

答案 0 :(得分:0)

尝试

nohup forever start -l forever.log -o out.log -e err.log /home/max/Desktop/hello2.js &