I want to run a Node.js server with daemontools on Debian (Jessie) but my script running under supervise is constantly restarted. This is the run script that I'm using (/etc/service/node/run):
#!/bin/bash
exec setuidgid nodeuser bash -c './node'
The script executes the following script as user nodeuser, where I load NVM, change into my code directory, and execute the Node.js server:
#!/bin/bash
# Load NVM because we are in a non-interactive shell
export NVM_DIR="/home/nodeuser/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
# Run server
cd /path/to/code
exec node server.js
When I start the service with sudo svc -u /etc/service/node, the process is restarted all the time and ps faux shows the following process hierarchy (the depth of the hierarchy is always changing):
/bin/sh /usr/bin/svscanboot /etc/service/
\_ svscan /etc/service
\_ supervise node
\_ /bin/bash ./node
\_ /bin/bash ./node
\_ /bin/bash ./node
\_ /bin/bash ./node
\_ /bin/bash ./node
| \_ /bin/bash ./node
| \_ /bin/bash ./node
| | \_ /bin/bash ./node
| | \_ /bin/bash ./node
| \_ /bin/bash ./node
| \_ tail -n1
\_ /bin/bash ./node
\_ tail -n1
Do you have an idea what's going on there? When I execute the script manually with ./run, the server starts as expected and shows its output in the console.
EDIT
I found out that the service works only after rebooting. Once I restart it with sudo svc -du /etc/service/node, it behaves like described above.