LINUX php服务重启不工作


LINUX php service restart not work

我需要帮助,我有webinterface运行这一节在php:

  $cmd="/usr/sbin/sudo /usr/sbin/service networking stop"
exec($cmd, $mes);
print_r($mes);  #this is emptz message
$cmd="/sbin/ifconfig"
exec($cmd, $mes);
print_r($mes); 

print_r (mes);为停止服务是空的print_r (mes)美元;对于ifconfig=array有关于接口的所有信息(但都是向上而不是向下,所以上面的消息不能很好地工作(这个服务仍然运行))

这个脚本是通过守护用户运行的。

这是我的视觉效果:

# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root    ALL=(ALL:ALL) ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
www-data ALL =NOPASSWD: /bin/nc, /bin/cp, /bin/chmod, /bin/chown, /etc/init.d/, /usr/sbin/service
deamon ALL = NOPASSWD: /bin/cp, /bin/chmod, /bin/chown, /etc/init.d/, /usr/sbin/service, /home/optokonlmcp/sss.php, /sbin/ifconfig

你知道为什么这个php脚本不工作吗?提前谢谢你

BR可

SOLUTIONS:

  1. 为root创建脚本(root:root)和命令我需要做的(sudo/usr/sbin/service)命令必须包含sudo

  2. 将脚本添加到visudo+所有在我的脚本中提到的命令中:Visudo包含:

    daemon ALL=NOPASSWD:/usr/bin/sudo,/path_my_script/script.sh

  3. 诅咒脚本必须有打开规则,所以我更改了755的规则。

  4. 现在你可以尝试运行脚本与守护进程,我使用以下命令:sudo -u daemon/patch_of_script/script.sh

  5. 最后一点是在php中添加命令:exect("sudo/path/./script.sh")

    现在我可以通过php重新启动网络。谢谢你!BR可

exac($cmd, $mes);替换为exec($cmd, $mes);