3

I'm trying to install monit on an Ubuntu 12.04 server. I have it set up, and configured (i think), but i'm not sure what user it's supposed to run as.

My user on the server is called deploy, and my monitrc file looks like this:

$ ls -l /etc/monit/monitrc
-rwx------ 1 deploy deploy 10229 2015-07-30 12:38 /etc/monit/monitrc

ie, it's owned by the user i log into the server with. I've started the monit daemon, and i can see it running with ps and i can log into the web interface for it.

What i'm unsure about is how to give it priveleges to restart processes. For example, nginx: if i want to restart nginx myself i need to do

sudo /etc/init.d/nginx restart

Does this mean that monit needs to do sudo as well in order to restart it? Or, should i configure monit with its own user, and set that user up so that it can restart nginx (and any other services which monit needs to restart or access) without sudo?

thanks, Max

Max Williams
  • 1,067
  • 2
  • 16
  • 32

1 Answers1

5

Yes, monit either needs to run sudo, or to be running as the root user. Configuring monit as its own user with the correct permissions is also viable however it is probably the most involved of the potential solutions.

Generally running sudo from scripts is not viable as it will prompt for a password. It is possible to stop sudo prompting for a password in specific situations by editing /etc/sudoers. The answer to this question explains a suitable approach.

Michael Shaw
  • 641
  • 3
  • 7
  • Many thanks - i did this `$ sudo chown root:root /etc/monit/monitr` then `$ kill -9 ` then `$ sudo monit` and it seems to be running happily now, and can restart nginx. – Max Williams Jul 31 '15 at 08:40