Restarting apache with Jenkins or Phing
Asked Answered
G

1

5

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?

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...

...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
Gawk answered 1/8, 2011 at 9:44 Comment(4)
There is an issue with spawning new process in Jenkins. I guess restarting apache falls into this category as a new process id will be created. Have you tried adding the restart to a post-build task? I'm just wondering why you are restarting Apache after doing compression and phpdepend tasks anyway? Are you rebuilding vhost configs or something as well?Water
I'm using APC. If I don't restart, sometimes I get a white screen of death. If you know a way around that problem with APC, let me know :) But do they have a plugin for restarting apache as a post-build task?Gawk
I actually just found the plugin, thanks for the tip! But if I can get a fix for the white screen of death problem without restarting apache, that would be great!Gawk
Never come across that APC issue but I'd look into it and try and fix it rather than code around it with apache restarts. Good luck!Water
W
5

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

sudo phing restartapache

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

<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 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.

Water answered 1/8, 2011 at 10:50 Comment(3)
got it working with some exceptions. Take a look at the description for the new info.Gawk
Granting blanket permission for jenkins to run anything is a bad idea. See this answer here for how to improve your solution.Hanford
Thanks. I have updated my answer with your improved solution.Water

© 2022 - 2024 — McMap. All rights reserved.