im runnig an http server using nodejs. i want also the server to run forever, even when my machine restarts,i want node to run again upon restart. so i created a script to put in the
/etc/init.d/
here is the script
#! /bin/sh -e
set -e
PATH=/usr/local/bin/node:/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/opt/node-v0.4.7/examples/app.js
case "$1" in
start) forever start $DAEMON ;;
stop) forever stop $DAEMON ;;
force-reload|restart)
forever restart 开发者_高级运维$DAEMON ;;
*) echo "Usage: /etc/init.d/node {start|stop|restart|force-reload}"
exit 1 ;;
esac
exit 0
however when i run
/etc/init.d/node
i keep getting the same error saying
/etc/init.d/node: 13: Syntax error: word unexpected (expecting ")")
can you guys see the error ? i'm sure it's probably some easy syntax error but it's kinda late and i'm really tired. thanks for the help
I changed the shebang from:
#! /bin/sh -e
To:
#! /bin/bash
And now that script works for me.
You can create upstart service in Ubuntu(if you use it).
Create myapp.conf in /etc/init and write something like:
start on startup
respawn
exec node /path/to/your/script.js
Then your app will start after reboot and you can manage it via start and stop commands.
And look at forever node.js module
精彩评论