通过http请求远程启动服务

时间:2018-08-24 12:00:12

标签: http authentication debian systemd

我有一个以用户www-data身份运行的systemd服务“ myservice”。我想通过http请求启动/停止/重新启动此服务。问题是,由于缺少身份验证,我得到了一个错误:

  

无法重新启动myservice.service:需要交互式身份验证。   有关详细信息,请参见系统日志和“ systemctl status myservice.service”。

首先,我请求一个php脚本,调用restartService.sh:

$exec_command = "../restartService.sh";

restartService.sh只是一个命令:

systemctl restart myservice.service

restartService.sh的所有者和组是ww数据:

-rwxr-xr-x 1 www-data  www-data    41 Aug 24 12:42 restartService.sh

有解决方案的建议吗?

1 个答案:

答案 0 :(得分:0)

您可以使用sudo配置为www-data用户授予运行systemctl restart yourservice的权限,而无需授予其以root用户身份运行任何其他命令的权限。