简体   繁体   English

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

[英]How do I programatically restart a system service(not apache) from apache in linux?

I need to simple way to allow an end user to restart tomcat from a web page served from apache on the same box. 我需要以简单的方式允许最终用户从同一个盒子上的apache提供的网页重启tomcat。

We're trying to make it easy for our QC department to deploy a new version of our webapp to apache. 我们正在尝试让我们的QC部门轻松地将新版本的webapp部署到apache。 We're using samba, but we need an easy way for them to stop / start the tomcat server before/after the deployment. 我们正在使用samba,但我们需要一种简单的方法让他们在部署之前/之后停止/启动tomcat服务器。

This would only be for internal qc boxes. 这只适用于内部qc盒。 Is there an existing solution for this? 是否有现成的解决方案? or would it be easier to write a few quick php application to handle this? 或者更容易编写一些快速的PHP应用程序来处理这个?

Like Skip said, but don't run the CGI as root. 像Skip所说,但不要以root身份运行CGI。 Instead, have the CGI call sudo. 相反,让CGI调用sudo。 You can give your web server permission to run /etc/init.d/tomcat restart only in the sudoers file. 您可以授予Web服务器仅在sudoers文件中运行/etc/init.d/tomcat restart权限。

I've actually done this at work; 我实际上是在做这件事; the relevant part of the CGI looks like this: 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

Here is an example line from /etc/sudoers (use visudo to edit, of course): 这是/ etc / sudoers的示例行(当然使用visudo进行编辑):

ALL     ALL=(root) NOPASSWD: /etc/init.d/tomcat5.5 restart

That allows everyone to restart tomcat. 这允许每个人重启tomcat。 You could limit it to Apache only if you'd like. 只有你愿意,你才能将它限制在Apache。

I would use a CGI script. 我会使用CGI脚本。 Set it up to run as root and call '/etc/init.d/tomcat restart' (or however you restart tomcat on your box). 将其设置为以root身份运行并调用'/etc/init.d/tomcat restart'(或者在您的盒子上重启tomcat)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM