Restart apache with Jenkins or Phing

I am currently using Phing and Jenkins to automate build and deployment for my CodeIgniter application. One of the issues I ran into is restarting the apache service. I tried in Phing, but not enough permissions. What is the best way to reboot?

EDIT:

After adding jenkins to the sudoer file and starting the httpd restart service, Jenkins throws: processes the missing file descriptors. Below is a snippet of Phing's release via Jenkins. It talks about installing 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 
+5
source share
1 answer

If you are running Linux, you can run Phing with the sudo command to allow it enough privileges to restart apache.

 sudo phing restartapache 

Assuming restartapache is an exec task that invokes the apache restart command. For instance:

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

To avoid asking the sudo command for a password, you can update sudo permissions for any user account that is running your build (this example demonstrates disabling the sudo password request for jenkins):

 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 in accordance with this answer so that Jenkins will allow restarting apache without a password and nothing more.

+5
source

All Articles