Is there benefit to using Monit instead of a basic Upstart setup?

前端 未结 2 447
南笙
南笙 2020-12-12 09:44

I\'m configuring my server to run node.js as a daemon. I\'ve setup Upstart to handle startup and shutdown of node, which works wonderfully. The next step is to make sure tha

相关标签:
2条回答
  • 2020-12-12 10:14

    I highly recommend using both Monit AND upstart. Upstart makes it easy to deamonize node.js and Monit comes packed with tons of useful app checks including memory usage, http requests, cpu usage, ...

    This is an example of the most basic setup you can get. You could also easily add another monit config (with the same start and stop script) but using the PID file and monitoring process stats.

    For the below configuration create a simple local-only request handler in your app that just responds with status 200 if all is well.

    Monit config:

    check host app_name with address 127.0.0.1
        start "/sbin/start app_name"
        stop "/sbin/stop app_name"
        if failed port 80 protocol HTTP
            request /ok
            with timeout 5 seconds
            then restart
    

    Upstart script (/etc/init/app_name):

    description "app_name"
    
    start on startup
    stop on shutdown
    
    script
        # Node needs HOME to be set
        export HOME="path/to/node/app"
    
        exec sudo -u nodejs /usr/local/bin/node path/to/node/app/server.js production 2>>/var/log/app_name.error.log >>/var/log/app_name.log
    end script
    
    0 讨论(0)
  • 2020-12-12 10:15

    Given that Upstart just checks the PID, a tool like Monit that makes an actual request will provide you an answer of app sanity more faithfully. A process may happily be running but stuck in some way such that it is not serving requests.

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