title: Forever Node JS startup or stop/starting
body: <p>I'm fairly new to all of this, so I apologize.  My search has not yielded me an answer yet and I'm still testing around.</p>
  
  <p>I have an Node JS app thats started by Forever on Ubuntu 12.04 LTS.  Several requirements I'm trying to figure out:</p>
  
  <ol>
  <li>Start automatically on boot</li>
  <li>Being able to restart the app manually</li>
  </ol>
  
  <p>I configured an Upstart script and it works fine, but I have no way of stopping the process correctly.  I think the issue is because Upstart is looking for a PID and Forever creates a PID but doesn't tell Upstart?  So when I try to stop, it doesn't know how to kill the correct process.  </p>
  
  <p>Here's a sample of what I'm trying to do:</p>
  
  <pre><code>#start on startup
  #stop on shutdown
  
  expect daemon
  
  env NODE_BIN_DIR=""
  env NODE_PATH=""
  env APPLICATION_DIRECTORY=""
  env APPLICATION_START=""
  env NODE_ENV=""
  
  #pre-start script
  #sleep 15
  #end script
  
  script
      PATH=$NODE_BIN_DIR:$PATH
      cd /vol01/web/iin
      exec sudo -u ubuntu forever -a -l $LOG -e $eLog  start $APPLICATION_START
  end script
  
  pre-stop script
      PATH=$NODE_BIN_DIR:$PATH
      exec forever stop $APPLICATION_START
  end script
  </code></pre>
  
  <p>I'm beginning to think the best way for me to go about this is to run a cron job on boot that would run a script to run the forever node.  This script would include stopping the application and starting and I could invoke the script manually.  Thoughts?</p>