Monit lesson learned: use “as uid”, not sudo

15 Aug

Been setting up monit to auto-restart node if there's a problem.

Not wanting to run Node as root, I tried a sudo in the restart rule, but it failed. Log message:
?? Error: Could not execute sudo

Tried using "as uid" instead and it works. Here's the full working stanza:

?? check host appname with address
?? ?? start program = "/usr/local/bin/node /path/to/app.js"
?? ?? ?? as uid??theusername??and gid theusername
?? ?? stop program ??= "/usr/bin/pkill -f 'node /path/to/app.js'"
?? ?? if failed port 3000 protocol HTTP
?? ?? ?? ?? request /
?? ?? ?? ?? with timeout 10 seconds
?? ?? ?? ?? then restart


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: