bin/captain.js
function run() {
  process.env['NODE_PATH'] = resolve(PROJECT_ROOT, '..');

  helpers.countUsers(function(err, count) {
    if(err) { throw err; }
    if(count > 0) {
      _run();
    } else {
      terminal.abort('You need to create at least one user with `captain create_user`');
    }
  });


  function _run() {
    // TODO: Put this in settings
    var logs = join(cwd, 'logs')
      , out = fs.openSync(join(logs, 'out.log'), 'a')
      , err = fs.openSync(join(logs, 'err.log'), 'a');

    if(helpers.isCaptainProject()) {
      var bin = program.watch
        ? resolve(PROJECT_ROOT, 'node_modules', '.bin', 'node-dev')
        : 'node';

      var options = program.fork
        ? { stdio: [ 'ignore', out, err ],  detached: true}
        : { stdio: 'inherit' };

      var child = spawn(bin, [join(cwd, 'index.js')], options);
      var conf = require('captain-core').conf;
      console.log(terminal.cyan('Your application is running at: ') + 'http://%s:%d', conf.host, conf.port);

      if(program.fork) {
        // TODO: Put this in settings
        fs.writeFileSync(join(cwd, 'node.pid'), String(child.pid));
        child.unref();
      }
    } else {
      terminal.abort('Not a Captain project');
    }
  }
}
function run() {
  process.env['NODE_PATH'] = resolve(PROJECT_ROOT, '..');

  helpers.countUsers(function(err, count) {
    if(err) { throw err; }
    if(count > 0) {
      _run();
    } else {
      terminal.abort('You need to create at least one user with `captain create_user`');
    }
  });


  function _run() {
    // TODO: Put this in settings
    var logs = join(cwd, 'logs')
      , out = fs.openSync(join(logs, 'out.log'), 'a')
      , err = fs.openSync(join(logs, 'err.log'), 'a');

    if(helpers.isCaptainProject()) {
      var bin = program.watch
        ? resolve(PROJECT_ROOT, 'node_modules', '.bin', 'node-dev')
        : 'node';

      var options = program.fork
        ? { stdio: [ 'ignore', out, err ],  detached: true}
        : { stdio: 'inherit' };

      var child = spawn(bin, [join(cwd, 'index.js')], options);
      var conf = require('captain-core').conf;
      console.log(terminal.cyan('Your application is running at: ') + 'http://%s:%d', conf.host, conf.port);

      if(program.fork) {
        // TODO: Put this in settings
        fs.writeFileSync(join(cwd, 'node.pid'), String(child.pid));
        child.unref();
      }
    } else {
      terminal.abort('Not a Captain project');
    }
  }
}
Usage: captain run[--watch] [--fork]

Runs captain project

* Use --watch to restart
* Use --fork to create a daemon

When using --fork, captain will redirect
stdout to logs/out.log, stderr to logs/err.log,
and write the process' pid to node.pid.