用Jenkins或Phing重启apache

时间:2022-10-06 19:49:49

I'm currently using Phing and Jenkins to automate builds and deployment for my CodeIgniter app. One problem I'm having trouble with is restarting the apache service. I tried in Phing but there isn't enough permissions. What is the best way to restart?

我目前正在使用Phing和Jenkins为我的CodeIgniter应用程序自动构建和部署。我遇到的一个问题是重启apache服务。我在Phing尝试但是没有足够的权限。重启的最佳方法是什么?

EDIT:

编辑:

After adding jenkins into the sudoer file and exec'ing the service httpd restart, Jenkins throws: Process leaked file descriptors. Below is a snippet of the Phing output via Jenkins. It says a workaround is to install daemonize. Not sure what that means...

将jenkins添加到sudoer文件并执行服务httpd restart后,Jenkins抛出:处理泄露的文件描述符。下面是Jenkins的Phing输出片段。它说一个解决方法是安装daemonize。不确定那是什么意思...

...Build_test > compress:

     [echo] YUI Compression started
     [echo] Replacing normal JS with compressed files.
     [echo] Replacing normal CSS with compressed files.
     [echo] chmoding assets
     [echo] YUI Compression ended

Build_test > pdepend:


Build_test > httpd_restart:

     [echo] Stopping httpd: [  OK  ]
     [echo] Starting httpd: [  OK  ]


BUILD FINISHED

Total time: 13.1424 seconds

Process leaked file descriptors. See http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build for more information
[JDepend] JDepend plugin is ready
[JDepend] Found 68 classes in 1 packages
Finished: SUCCESS

1 个解决方案

#1


5  

If you're on Linux you can run Phing with the sudo command to allow it enough privileges to restart apache.

如果您使用的是Linux,则可以使用sudo命令运行Phing,以便为其提供足够的权限来重启apache。

sudo phing restartapache

Assuming that restartapache is an exec task that calls the apache restart command. Eg:

假设restartapache是​​一个调用apache restart命令的exec任务。例如:

<target name="restartapache" description="Restarts the web server">
    <exec command="/etc/init.d/apache2 restart" />
</target>  

To avoid the sudo command prompting for a password you can update your sudo permissions for whatever user account you are running your build under (this example demonstrates turning off the sudo password prompt for the jenkins user):

要避免sudo命令提示输入密码,您可以更新您运行构建的任何用户帐户的sudo权限(此示例演示关闭jenkins用户的sudo密码提示):

sudo visudo

Then add the following lines:

然后添加以下行:

Defaults:jenkins !requiretty,!lecture
jenkins ALL=NOPASSWD:/etc/init.d/apache2

The above has been edited to improve security according to this answer so that Jenkins is only allowed to restart apache without a password and nothing else.

根据这个答案,上面的内容已经过编辑以提高安全性,因此只允许Jenkins在没有密码的情况下重启apache。

#1


5  

If you're on Linux you can run Phing with the sudo command to allow it enough privileges to restart apache.

如果您使用的是Linux,则可以使用sudo命令运行Phing,以便为其提供足够的权限来重启apache。

sudo phing restartapache

Assuming that restartapache is an exec task that calls the apache restart command. Eg:

假设restartapache是​​一个调用apache restart命令的exec任务。例如:

<target name="restartapache" description="Restarts the web server">
    <exec command="/etc/init.d/apache2 restart" />
</target>  

To avoid the sudo command prompting for a password you can update your sudo permissions for whatever user account you are running your build under (this example demonstrates turning off the sudo password prompt for the jenkins user):

要避免sudo命令提示输入密码,您可以更新您运行构建的任何用户帐户的sudo权限(此示例演示关闭jenkins用户的sudo密码提示):

sudo visudo

Then add the following lines:

然后添加以下行:

Defaults:jenkins !requiretty,!lecture
jenkins ALL=NOPASSWD:/etc/init.d/apache2

The above has been edited to improve security according to this answer so that Jenkins is only allowed to restart apache without a password and nothing else.

根据这个答案,上面的内容已经过编辑以提高安全性,因此只允许Jenkins在没有密码的情况下重启apache。