3
#!/bin/sh exec node /opt/nodejs/first/app.js 1>>/opt/nodejs/first/log/output 2>>/opt/nodejs/first/log/error 

This shell script throws an error:

exec: 2: node: not found 

I'm trying to launch it on system boot:

sudo update-rc.d autostart.sh defaults 95 

I'm doing something wrong?

Maybe boot level is wrong or order number, or something else?

Thanks ;)

2 Answers 2

4

You need to set your PATH environment variable to include the directory where your node binary lives. For starting on boot, what OS are you running? I suggest Ubuntu where you can use the upstart system. Here's a simple upstart script to make a node server work as a daemon.

description "start and stop your node.js server" version "1.0" author "You <[email protected]>" start on startup respawn env NODE_ENV=production env PATH=/path/to/node/bin chdir /path/to/your/app/root exec su -c 'node app/server.js' www-data >> var/log/stdout.log 2>&1 
Sign up to request clarification or add additional context in comments.

Comments

2

I don't know node, but the typical error here is that the PATH variable at the time of execution of the script does not contain the path to your program. The easiest fix is to simply use the full path:

#!/bin/bash exec /path/to/node ... 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.