Running and managing nodejs applications on single server

前端 未结 5 604
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 21:19

Is there a good way to run and manage multiple nodejs apps on a single server?

I\'ve been looking at haibu and nodester, but they seem a little complex for what I am try

相关标签:
5条回答
  • 2021-01-31 21:44

    I wrote an app nodegod that I use for a handful deployments of maybe 10 apps each.

    • nodegod reads an app list from json. It has an internal state machine for each app that handles the app life cycle in a safe manner including restarts, and the web page features stop/start/debug.

    • The web interface uses web sockets, so that you can manage remote servers over ssh.

    • As you deploy over rsync, apps restart automatically.

    • Because nodegod monitors the stdout of other apps, you can capture an app's final breath like segfault and malloc errors.

    • I use a fork of http-proxy in front of a slew of express instances, so any number of apps can share a single server port per dns for both http and web sockets.

    I wrote a haraldops module to read app configuration from outside the source tree. With that you can monitor and get emails whenever something's up with an app.

    App configurations I keep in a git repo in the file system.

    It's not rocket science, and it all fits very nicely together. Only node and json: SIMPLE gets more done.

    0 讨论(0)
  • 2021-01-31 21:52

    We're constantly trying to improve forever and haibu at Nodejitsu. Seems like the approach you're looking for here is a .forever configuration file for complex options. This feature has been on our backlog for a while now

    https://github.com/nodejitsu/forever/issues/124

    Check back. I consider it pretty high priority after the next round of performance improvements.

    0 讨论(0)
  • 2021-01-31 21:55

    If your server has upstart, just use it. I have no luck with forever and similar. If you want to proceed with upstart, roco would be nice as deployment solution:

    roco deploy:setup:upstart
    roco deploy
    
    0 讨论(0)
  • 2021-01-31 22:09

    I use Supervisord & Monit, more details and configuration example here: Process Management at Bringr.

    Moreover you can specify environnement variable directly from the supervisord configuration file (see sub-process environment). But I personally prefer to add these variables directly inside a ~/.bashrc on each machine.

    If the port number isn't going to change for each application (but change between production & development environment). I'll recommend to specify them inside a config.json (or directly inside package.json). And the config.json will contain a different port number for each application depending on the environnement:

    {
     myapp:{
      production:{port:8080},
      development:{port:3000}
     }
    }
    

    And inside myapp.js:

     var config = require('./config');
     app.listen(config.myapp[process.env.NODE_ENV].port)
    

    With process.env.NODE_ENV declared in ~/.bashrc.

    0 讨论(0)
  • 2021-01-31 22:10

    These days I've taken to using dokku which is a OSS clone of heroku. Deploying is as simple as making sure your package.json contains a start script. For example:

    "scripts": {
      "start": "node index.js"
    }
    

    Sample App

    0 讨论(0)
提交回复
热议问题