我不明白为什么 start-stop-daemon 没有运行下面的脚本。我做错了什么?start-stop-daemon 报告说,使用 --test 标志时它将启动节点,但当我实际运行时,该进程并未启动。
root@server:~# cat /var/www/a/app.js
var http = require("http")
var fs = require("fs")
fs.writeFileSync("app.pid", process.pid)
http.createServer(function(req, res)
{
res.writeHead(200, {"Content-Type": "text/plain"})
res.end("Test")
}).listen(3000)
console.log("App A is running, PID", process.pid)
root@server:~# node /var/www/a/app.js
App A is running, PID 18517
^Z
[1]+ Stopped node /var/www/a/app.js
root@server:~# pidof node
18517
root@server:~# kill -9 `pidof node`
root@server:~# fg
-su: fg: job has terminated
[1]+ Killed node /var/www/a/app.js
root@server:~# rm /var/www/a/app.pid
root@server:~# start-stop-daemon --start --pidfile /var/www/a/app.pid --chdir /var/www/a --chuid www-data:www-data --background --exec /opt/iojs/bin/node app.js --test
Would start /opt/iojs/bin/node app.js (as user www-data[33], and group www-data[33]).
root@server:~# start-stop-daemon --start --pidfile /var/www/a/app.pid --chdir /var/www/a --chuid www-data:www-data --background --exec /opt/iojs/bin/node app.js
root@server:~# pidof node
root@server:~# start-stop-daemon --start --pidfile /var/www/a/app.pid --chdir /var/www/a --chuid www-data:www-data --background --exec app.js --test
Would start app.js (as user www-data[33], and group www-data[33]).
答案1
start-stop-daemonstart
命令用于--exec
确定要执行的二进制文件(在您的情况下/opt/iojs/bin/node
)。为了指示此命令的参数,应添加--
(在您的情况下àpp.js
)
因此你应该这样称呼它:
start-stop-daemon --start --pidfile /var/www/a/app.pid --chdir /var/www/a --chuid www-data:www-data --background --exec /opt/iojs/bin/node -- app.js
我希望这能解决你的问题