TransWikia.com

start-stop-daemon not working as expected

Server Fault Asked by mhingston on December 27, 2021

I can’t figure out why start-stop-daemon is not running the script below. What am I doing wrong? start-stop-daemon reports that it will start node when using the –test flag, but when I actually run the process isn’t started.

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]).

One Answer

The start-stop-daemon start command uses --exec to determine the binary file to execute (in your case /opt/iojs/bin/node). In order to indicate arguments to this command should be added with -- (in your case àpp.js)

So you should call it like that:

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

I hope this will solve your problem

Answered by Dedalo on December 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP