Centos 7. Usually when I would like to run a sudo command as a non root user, I open up the visudo, and add this line to the right place:
%<userGroup> ALL= NOPASSWD: <command>
when I want to restart a service - in my current case - mongodb.service with the jenkins user I would like to do it like this:
%jenkins ALL= NOPASSWD: /usr/bin/systemctl restart mongod.service
So far so good. Then I switch to the jenkins user like this:
sudo su -s /bin/bash jenkins
Then I test the command and everything works fine. I do the same with the stop/status/start commands too and test them too. Thats all what I would like to do with them. The problem is; when I run the tests with the jenkins, it calls these commands and does nothing. This mongodb is only for testing, so it's fine that it only runs when we need it. So what I would like to know is; how to make it work? Or how to be able to restart/stop/start the service with a service user?