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 127.0.0.1
?? ?? 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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: