0

I am issuing monit commands from command line and this works

$ sudo monit reload

Now I create a shell script monitreload.sh

#!/bin/bash
monit reload

And then the commands

$ sudo ./monitreload.sh
$ sudo -u ram ./monitreload.sh

The above ones fail with permission denied error.

Pls note /etc/monit/monitrc file is owned by root and the user 'ram' is a valid sudo user. Most of the questions in SO talk about gid and uid usage in monit config like this one or invoking a shell through monit config like this one

What is going wrong here?

promaxdev
  • 455
  • 1
  • 6
  • 19

1 Answers1

0

Based on your sample commands

$ sudo ./monitreload.sh
$ sudo -u ram ./monitreload.sh

The first one should work, you switch to root. But the second should not, you switch to user "ram", and the user "ram" can not reload the configuration as long as Monit was stared by "root".

$ sudo -u ram sudo ./monitreload.sh

If "ram" is authorized to switch to "root", you can add an additional "sudo" in the command to switch from "ram" to "root". Monit will not swich to the "root" user automatically.

lutzmad
  • 339
  • 1
  • 5