Zolf
asked on
How to restart Service as root without a password prompt from application
Hello there,
I want to restart my java application which is running on Ubuntu 16.04 as service. But the problem I have is on Ubuntu when I want to restart my java application service, I do as follows
Any help will be appreciated!!
cheers
Zolf
I want to restart my java application which is running on Ubuntu 16.04 as service. But the problem I have is on Ubuntu when I want to restart my java application service, I do as follows
sudo service myapp restart
and then Ubuntu asks for password. Now how can I tell Ubuntu to not ask password when I send this cmd from my application.//Restart application server
router.get("/restartAppService").handler(ctx -> {
/* Build command: sudo service AooService stop */
final ArrayList<String> command = new ArrayList<String>();
command.add("sudo service TutisService restart");
System.out.println("CMD ----"+command.toString());
final ProcessBuilder builder = new ProcessBuilder(command);
try {
builder.start();
} catch (IOException e) {
System.out.println("EXCEPTION WHILE RESTARTING SERVICE----"+e.getMessage());
e.printStackTrace();
}
//System.exit(0);
});
Any help will be appreciated!!
cheers
Zolf
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you're going to be running your Java app on many machines + wish to restart from a central location, create an empty passphrase ssh key + deploy the public key part across all machines.
ASKER
Thanks for your comments.
I tried that but when I test in the terminal by running the restart service without sudo it still asks for password
I tried that but when I test in the terminal by running the restart service without sudo it still asks for password
without sudo? You're meant to be running it with sudo
That's not enough. You need to use NOPASSWD in sudoers as well