start-stop-daemon が期待通りに動作しない

start-stop-daemon が期待通りに動作しない

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

これで問題が解決することを願っています

関連情報