Skip to content

Instantly share code, notes, and snippets.

@Miserlou
Created January 12, 2012 04:22
Show Gist options
  • Save Miserlou/1598685 to your computer and use it in GitHub Desktop.
Save Miserlou/1598685 to your computer and use it in GitHub Desktop.
/etc/init.d/nodeapp
#!/bin/bash
DIR=/var/www/YOUR_NODE_APP_GOES_HERE
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NODE_PATH=/usr/local/lib/node_modules
NODE=/usr/local/bin/node
test -x $NODE || exit 0
function start_app {
NODE_ENV=production nohup "$NODE" "$DIR/YOUR_APP_SERVER_FILE.js" 1>>"$DIR/logs/YOUR_APP_NAME.log" 2>&1 &
echo $! > "$DIR/pids/YOUR_APP.pid"
}
function stop_app {
kill `cat $DIR/pids/YOUR_APP.pid`
}
case $1 in
start)
start_app ;;
stop)
stop_app ;;
restart)
stop_app
start_app
;;
*)
echo "usage: YOUR_APP_NAME {start|stop}" ;;
esac
exit 0
@freekode
Copy link

@umpitygrumpity an example:

su specuser -c "nohup npm start /home/user/app/ 1>>/home/user/app/out.log 2>&1 &"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment