Node.js (sudo) and monit

I created a script upstart to execute daugonize juggernaut (node.js application) The upstart script is as follows

description "juggernaut server"
author      "panojsee"

start on startup
stop on shutdown

script
    # We found $HOME is needed. Without it, we ran into problems
    #export HOME="/home/ubuntu/src/juggernaut"
    chdir /home/ubuntu/src/juggernaut
    exec sudo /usr/bin/node server.js 2>&1 >> /var/log/node.log
end script

As you can see, I want to start node using sudo (so that I can use Flash sockets). My monit script is as follows:

install the log file /var/log/monit.log

check host juggernaut with address 127.0.0.1
    start program = "/sbin/start juggernaut"
    stop program  = "/sbin/stop juggernaut"
    if failed port 8080 protocol HTTP
        request /
        with timeout 10 seconds
        then restart

Monit does not allow me to run the program = " sudo / sbin / start juggernaut" Once I kill juggernaut (node), monit tries to restart it, but dies with the following message.

[UTC Feb  3 22:48:25] error    : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8080] via TCP
[UTC Feb  3 22:48:25] info     : 'nodejs' trying to restart
[UTC Feb  3 22:48:25] info     : 'nodejs' stop: sudo
[UTC Feb  3 22:48:25] error    : Error: Could not execute sudo
[UTC Feb  3 22:48:25] info     : 'nodejs' start: sudo

Any hint how can I tell monit to execute a sudo command?

+3
source share
3 answers

Just run Monit with sudo and of course add monit to sudoers

+2
source

, nodeJS , "exec sudo" script monit , .

start program = "/sbin/start juggernaut" uid

+3

Check which custom monit works like. Is this user configured to run sudo? Check also if sudo reported any errors (possibly in /var/log/messages).

I found this answer to be very useful in defining monit behavior.

+1
source

Source: https://habr.com/ru/post/1789879/


All Articles