gpt4 book ai didi

bash - centos+nodejs+永远(启停)

转载 作者:太空宇宙 更新时间:2023-11-03 17:17:39 28 4
gpt4 key购买 nike

美好的一天,我对永久启动\停止脚本有一些问题。

中央操作系统 6.2
内核 2.6.32-220.el6.x86_64
node.js v0.6.19
npm v 1.1.24
永远@0.9.2

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

/etc/密码
Node :x:501:501::/usr/sbin/nologin:/bin/bash:/usr/local/bin/node:/usr/local/bin/forever:/usr/local/bin:/usr/local/lib/node_modules/forever/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 创建启停脚本并将其命名为 node

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

#!/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]$

我哪里错了?

最佳答案

尝试

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

关于bash - centos+nodejs+永远(启停),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11208549/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com