我在 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)
有没有办法避免这个错误并在不提供密码的情况下运行服务?