#!/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?
May开发者_JAVA技巧be boot level is wrong or order number, or something else?
Thanks ;)
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 <you@yoursite.example>"
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
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 ...
精彩评论