我需要一个简单的方法来允许最终用户从同一个盒子上的 apache 提供的网页重新启动 tomcat。
我们正在努力使我们的 QC 部门能够轻松地将我们的 web 应用程序的新版本部署到 apache。我们正在使用 samba,但我们需要一种简单的方法让他们在部署之前/之后停止/启动 tomcat 服务器。
这仅适用于内部质量控制箱。有没有现成的解决方案?或者编写一些快速的 php 应用程序来处理这个问题会更容易吗?
最佳答案
如 Skip 所说,但不要以 root 身份运行 CGI。相反,让 CGI 调用 sudo。您可以仅在 sudoers 文件中授予 Web 服务器运行 /etc/init.d/tomcat restart
的权限。
我在工作中确实这样做过; 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
这是来自/etc/sudoers 的示例行(当然使用 visudo 进行编辑):
ALL ALL=(root) NOPASSWD: /etc/init.d/tomcat5.5 restart
这样大家就可以重启tomcat了。如果您愿意,您可以将其限制为 Apache。
关于php - 如何以编程方式从 Linux 中的 Apache 重新启动系统服务(不是 Apache)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/349884/