Summary: In this post I share my experience in running Jenkins and Artifactory servers as unix daemons and monitor their availability. If any of this servers down, monitoring part can send alert or restart the server. This setup will provide your team with robust and reliable Continuous Integration Server and Artifactory repository. You can apply this priciples to another applications like tomcat, cruisecontrol or any other you want to run and monitor.
- Jenkins – Continuous Integration Server
- Artifactory – open source artifact repository
- Monit – open source monitoring utility
- daemonize – script to run program as unix daemon
Continuous Integration is a cornerstone of agile software development and any project where quality of code and speed of development are important. Continuous Integration, in its simplest form, involves a tool that monitors your version control system for changes.
Whenever a change is detected, this tool automatically compiles and tests your application. If something goes wrong, the tool immediately notifies the developers so that they can fix the issue immediately. Specialized software, called Continuous integration servers allow development teams to monitor their project in version control and provide feedback instantly by building, compiling and checking the code.
One of the most popular, open source CI server is Jenkins. Originally called Hudson,it is an open source Continuous Integration tool written in Java. Boasting a dominant market share, Jenkins is used by teams of all sizes, for projects in a wide variety of languages and technologies, including .NET, Ruby, Groovy, Grails, PHP and more, as well as Java.
Jenkins comes bundled as a WAR file that you can run directly using an embedded servlet container. Jenkins uses the lightweight Winstone servlet engine to allow you to run the server out of the box, without having to configure a web server yourself. This is probably the easiest way to get started, allowing you to be up and running with Jenkins in a matter of minutes. It is also a very flexible option, and provides some extra features unavailable if you deploy Jenkins to a conventional application server. In particular, if you are running Jenkins as a stand-alone server, you will be able to install plugins and upgrades on the fly, and restart Jenkins directly from the administration screens.
You can start jenkins simply by:
java -jar jenkins.war
or java -jar jenkins.war –httpPort=8081
The jenkins server then run as foreground or background process.
Artifactory is a artifact repository manager and acts as a proxy between your build tool (Maven, Ant, Ivy, Gradle etc.) and the outside world.
It caches remote artifacts so that you don’t have to download them over and over again.also you can deploy your own artifact into repository for sharing between projects, storing buils artifacts, and for build release management. Artifactory can be deployed to any servlet container, but it come bundled with Jetty container and the fastest way to get started is just run it.
Run as daemon
We want to run Jenkins and Artifactory as background processes, daemons. The easier way to do it is to use daemonize – a very simple program that allows you to launch Jenkins (or any arbitrary program) as a daemon. For people without much Unix experience, this is recommended.
1. Download and install daemonize script from https://github.com/bmc/daemonize/downloads
2. if you downloaded gz file then
tar -xvf release-1.7.2.tar
sudo make install
then change to your jenkins directory and create a script with command line:
chmod 755 startjenkins.sh
java -jar jenkins.war –httpPort=8085 –javaHome=$JAVA_HOME
save the file and start it as daemon using daemonize script:
daemonize [-a] [-c directory] [-e stderr] [-o stdout] [-p pidfile] [-l lockfile] [-u user] [-v] startjenkins.sh
daemonize -c /v01/jenkins/artifactory-22.214.171.124 -E JAVA_HOME=/v01/jenkins/jdk1.6.0_26 -e /v01/jenkins/artifactory.err /v01/jenkins/artifactory-126.96.36.199/bin/artifactory.sh
Monitoring with Monit:
Monit is a free open source utility for managing and monitoring, processes, files, directories and filesystems on a UNIX system.
Monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses too much resources. You can use Monit to monitor files, directories and filesystems for changes, such as timestamp changes, checksum changes or size changes. You can also monitor remote hosts; Monit can ping a remote host and can check TCP/IP port connections and server protocols. Monit is controlled via an easy to use control file based on a free-format, token-oriented syntax. Monit logs to syslog or to its own log file and notifies you about error conditions and recovery status via customizable alert
Let download monit and install monit:
tar -xvf monit-5.2.5.tar
sudo gmake install
Monit configured using his own configuration file.documentation is available here.
Installation come with monitrc file to get you started. Alter configuration options and start monit.
My configuration are as follow:
check host jenkins.artstor.org with address jenkins.artstor.org if failed port 80 protocol http then alert heck host artifactory.artstor.org with address artifactory.artstor.org if failed url http://artifactory.artstor.org/artifactory/webapp/home.html then alert
It means alert me via email when servers are down. I am planning to add server start command if process are down.
Save configuration file and start monit
If you decided to run jenkins and artifactory on you JeEE server like tomcat, glassfish or jboss, monit is still a way to go and monitor server availability and restart in case it is down.
Monit has it’s own http interface, usually on port 2812 – so you can monitor processes from web browser.
I hope this help you to create a robust build server for your continuous integration, continuous delivery jorney.