A
A
Alexey Sosnovsky2015-12-21 20:06:38
Nginx
Alexey Sosnovsky, 2015-12-21 20:06:38

What happens to a process when using monit?

There is such a situation. Nginx + NodeJS + Monit
set up everything in the right way.
nginx

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        root /usr/share/nginx/html;
        index index.php index.html index.htm;
        server_name localhost;
        location / {
                proxy_read_timeout 120s;
                proxy_pass http://127.0.0.1:3000;
                proxy_set_header Host $host;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Real-IP $remote_addr;
        }

/etc/init/cloacker.conf
#cloacker.conf
description "node app"
author      "username"

start on startup
stop on shutdown

script
    export HOME="/root"

    echo $$ > /var/run/cloacker.pid
    exec /usr/bin/node /var/www/cloacker/app >> /var/log/cloacker.sys.log 2>&1
end script

pre-start script
    # Date format same as (new Date()).toISOString() for consistency
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/cloacker.sys.log
end script

pre-stop script
    rm /var/run/cloacker.pid
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/cloacker.sys.log
end script

/etc/monit/conf.d/cloacker.conf
check process cloacker with pidfile /var/run/cloacker.pid
        start program = "/sbin/start cloacker"
        stop program = "/sbin/stop cloacker"
        if failed host localhost port 3000 then restart

It looks like it should work, BUT!
if we start it just
# start cloacker
everything works, the node processes requests and nothing falls, but it’s worth running it like this
# monit start cloacker
, messages fall into the log
tail -n 100 -f /var/log/cloacker.sys.log
    at Function.process_params (/var/www/cloacker/node_modules/express/lib/router/index.js:330:12)
[2015-12-21T17:02:43.173Z] (sys) Stopping
[2015-12-21T17:02:43.228Z] (sys) Starting
Example app listening at http://:::3000
TypeError: Cannot read property 'split' of undefined
    at IpDecoder.set6 (/var/www/cloacker/node_modules/mmdb-reader/src/IpDecoder.js:39:16)
    at IpDecoder.set (/var/www/cloacker/node_modules/mmdb-reader/src/IpDecoder.js:21:10)
    at Reader.lookup (/var/www/cloacker/node_modules/mmdb-reader/src/Reader.js:636:11)
    at /var/www/cloacker/app.js:15:25
    at Layer.handle [as handle_request] (/var/www/cloacker/node_modules/express/lib/router/layer.js:95:5)
    at next (/var/www/cloacker/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/var/www/cloacker/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/var/www/cloacker/node_modules/express/lib/router/layer.js:95:5)
    at /var/www/cloacker/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/var/www/cloacker/node_modules/express/lib/router/index.js:330:12)
[2015-12-21T17:02:44.311Z] (sys) Stopping
[2015-12-21T17:02:44.367Z] (sys) Starting
Example app listening at http://:::3000
TypeError: Cannot read property 'split' of undefined
    at IpDecoder.set6 (/var/www/cloacker/node_modules/mmdb-reader/src/IpDecoder.js:39:16)
    at IpDecoder.set (/var/www/cloacker/node_modules/mmdb-reader/src/IpDecoder.js:21:10)
    at Reader.lookup (/var/www/cloacker/node_modules/mmdb-reader/src/Reader.js:636:11)
    at /var/www/cloacker/app.js:15:25
    at Layer.handle [as handle_request] (/var/www/cloacker/node_modules/express/lib/router/layer.js:95:5)
    at next (/var/www/cloacker/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/var/www/cloacker/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/var/www/cloacker/node_modules/express/lib/router/layer.js:95:5)
    at /var/www/cloacker/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/var/www/cloacker/node_modules/express/lib/router/index.js:330:12)
[2015-12-21T17:02:45.458Z] (sys) Stopping
[2015-12-21T17:02:45.512Z] (sys) Starting

Well, of course, in the browser, I periodically get to an unresponsive page
where I did something wrong, I don’t know, but I still want to track and fix the moment when the application falls

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question