小编yoy*_*oyo的帖子

允许用户在没有密码的情况下运行 systemctl/systemd 服务

我在 linux 中有一个服务,appSevice 当我使用这些命令启动和停止时,它可以工作:

sudo systemctl start appSevice.service;
sudo systemctl stop  appSevice.service;
Run Code Online (Sandbox Code Playgroud)

但是当我尝试从 JAVA 代码执行这些时,例如:

Runtime.getRuntime().exec(new String[]{"systemctl", "stop", "appService.service"});
Run Code Online (Sandbox Code Playgroud)

...它不起作用,我收到此错误:

>  Failed to stop appService.service: Interactive authentication required
Run Code Online (Sandbox Code Playgroud)

这是我的服务:

[Service]
Type=simple
ExecStart=/opt/soft/v1/launchAppService.ksh start
User=Jms-User
Restart=on-abort
Run Code Online (Sandbox Code Playgroud)

有没有办法避免这个错误并在不提供密码的情况下运行服务?

linux java

5
推荐指数
1
解决办法
2904
查看次数

标签 统计

java ×1

linux ×1