Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js (sudo) and monit

Tags:

node.js

monit

I have created an upstart script in order to daemonize juggernaut (a node.js app) The upstart script is the following

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 run node with sudo (so that I can use Flash sockets). My monit script is the following:

set logfile /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 have start program = "sudo /sbin/start juggernaut" Once I kill juggernaut (node) then 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 clue how can I tell monit to execute a sudo command ?

like image 858
PanosJee Avatar asked Dec 11 '25 04:12

PanosJee


1 Answers

I think you should run nodeJS with dedicated user then remove "exec sudo" from the starting script, and tell monit directly which user you would like to use.

start program = "/sbin/start juggernaut" as uid user-id

like image 127
Pawel Wodzicki Avatar answered Dec 13 '25 11:12

Pawel Wodzicki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!