0

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?

1 Answer 1

0

Just in case if someone else will experience the same type of issue: I didn't get any error message for these things, so I decided to put everything into a script file and then give the permission for running the script file with sudo rights. In that case I got this error message: "sudo: sorry, you must have a tty to run sudo" Using that I could hunt down the issue with this solution: https://unix.stackexchange.com/questions/122616/why-do-i-need-a-tty-to-run-sudo-if-i-can-sudo-without-a-password

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .