2

I have a jenkins server which logs into my production server via ssh and is supposed to restart some services with systemctl restart myservice.service

I've read similar issues and the most common solution was this:

jenkins ALL = NOPASSWD: /bin/systemctl restart myservice.service, /bin/systemctl restart myservice2.service

and insert it into the sudoers file.

I have also added

Defaults:jenkins !requiretty

My deploy file does this:

sudo /bin/systemctl restart myservice.service

and then despite my efforts I still get the following error:

sudo: no tty present and no askpass program specified

I've read about using -t when ssh'ing but I'm unsure how I would do that since I do multiple commands and some are not sudo commands.

So does anybody have a good solution for letting jenkins restart my services? I would like to avoid jenkins using root as its primary user.

Edit:

This was an issue on my side. My jenkins ssh'd into another server and is not logged in as "jenkins" so I was changing permissions for the wrong user. The solution with

jenkins ALL = NOPASSWD: /bin/systemctl restart myservice.service, /bin/systemctl restart myservice2.service

works fine aslong as its the right user.

closed as off-topic by Jeff Schaller, RalfFriedl, G-Man, JigglyNaga, Archemar Nov 14 '18 at 17:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, RalfFriedl, G-Man, JigglyNaga, Archemar
If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.