我如何以编程方式从linux中的apache重启系统服务(而不是apache)?

ScA*_*er2 5 php linux apache cgi restart

我需要以简单的方式允许最终用户从同一个盒子上的apache提供的网页重启tomcat.

我们正在尝试让我们的QC部门轻松地将新版本的webapp部署到apache.我们正在使用samba,但我们需要一种简单的方法让他们在部署之前/之后停止/启动tomcat服务器.

这只适用于内部qc盒.是否有现成的解决方案?或者更容易编写一些快速的PHP应用程序来处理这个?

der*_*ert 8

像Skip所说,但不要以root身份运行CGI.相反,让CGI调用sudo.您可以授予您的Web服务器/etc/init.d/tomcat restart仅在sudoers文件中运行的权限.

我实际上是在做这件事; CGI的相关部分如下所示:

#!/usr/bin/perl
use CGI;
use IPC::Run3;
my $CGI = new CGI;

my $output;
if (defined $CGI->param('go') && 'restart' eq $CGI->param('go')) {
    run3 [ qw(sudo /etc/init.d/tomcat5.5 restart) ], \undef, \$output, \$output;
}

print <<EOF
Content-type: text/html

Blah, blah, blah, HTML form, displays $output at some point.
EOF
Run Code Online (Sandbox Code Playgroud)

这是/ etc/sudoers的示例行(当然使用visudo进行编辑):

ALL     ALL=(root) NOPASSWD: /etc/init.d/tomcat5.5 restart
Run Code Online (Sandbox Code Playgroud)

这允许每个人重启tomcat.只有你愿意,你才能将它限制在Apache.