John is an experienced consultant specialising in Enterprise Java, Web Development, and Open Source technologies, currently based in Sydney, Australia. Well known in the Java community for his many published articles, and as author of Java Power Tools and Jenkins: The Definitive Guide, and founder of the open source Thucydides Automated Acceptance Test Library project, John helps organisations to optimize their Java development processes and infrastructures and provides training and mentoring in agile development, automated testing practices, continuous integration and delivery, and open source technologies in general. John is the CEO of Wakaleo Consulting, and runs several Training Courses on open source Java development tools and best practices. John is a DZone MVB and is not an employee of DZone and has posted 125 posts at DZone. You can read more from them at their website. View Full User Profile

Starting a Hudson Slave on a Unix Machine Without SSH

  • submit to reddit

One great feature about Hudson is the support for distributed builds. Distributed builds can be used to absorb load or for specialized build jobs such as system or functional testing or automated deployments. In this article, we look at a special case - what happens when you need to start a Unix Hudson slave from the slave machine itself.

The best way to start a Hudson slave on a Unix build box is to use SSH. This is very convenient (all you need is a valid SSH account on the slave machine), and can be initiated automatically as required from the Hudson master. However, in some organizations, SSH is not installed on the machines, which makes this approach impossible.

If you can't use SSH, you can still start the slave by running a command on the command line. Hudson provides a special JAR file, called slave.jar, for this purpose. You can get this file from your Hudson server using a URL like (where "" is the URL you are running Hudson on).

To start the slave agent, you invoke the slave.jar file as shown here:

java -jar slave.jar -jnlpUrl

Of course, you will also want to stop the slave agent. A more complete script, that lets you both start and stop the slave agent, is shown here:


 wget $HUDSON_MASTER/jnlpJars/slave.jar
 START = java -jar slave.jar -jnlpUrl $HUDSON_MASTER/computer/test-slave/slave-agent.jnlp 
 nohup $START > hudson.log 2>&1 &
 echo "Hudson slave started"

 kill `ps -ef | grep hudson | grep slave | grep -v grep | awk '{ print $2 }'`
 echo "Hudson slave stopped"

 numproc=`ps -ef | grep hudson | grep slave | grep -v grep | awk  | wc -l`
 if [ $numproc -gt 0 ]; then
  echo "Hudson slave is running..."
  echo "Hudson slave is stopped..."


# See how we were called.
case "$1" in
 echo $"Usage: $0 {start|stop|status|restart}"
 exit 1

exit 0
This script will work will under most Linux distros. Some Unix variants, such as HP, don't have wget installed by default, so you will need to either find an equivalent or (a work-around that I've been known to use) store the slave.jar file under version control and check it out. In this case, it is important to keep the JAR file stored in Subverion in sync with the version of Hudson you are running. For example, an HP-friendly variant of this script using Subversion might look like this:
 svn up
 START = java -jar slave.jar -jnlpUrl $HUDSON_MASTER/computer/test-slave/slave-agent.jnlp 
 nohup $START > hudson.log 2>&1 &
 echo "Hudson slave started"mr_}

This script is now ready to be installed as a service on your Unix slave machine.


Published at DZone with permission of John Ferguson Smart, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Alex(JAlexoid) ... replied on Sun, 2010/06/06 - 6:01pm

One problem though. If you don't have SSH then how are you suppose to access the command line on the server?
SSH is an acronym for "Secure SHell".

Mladen Girazovski replied on Mon, 2010/06/07 - 4:17am in response to: Alex(JAlexoid) Panzin

Sounds strange, but some companies will not allow SSH, no matter what, you can easily get an rshell access though, or access an virtual machine (VMWare, etc.) through the host console.

Michael Eric replied on Wed, 2012/09/26 - 3:46pm

Great article, John, and I am trying to adapt it for my use.
Running the script on RHEL gives me a problem with the 'status' command, where the 'awk' sans arguments causes the gawk interpreter to fail.
I've googled the awk-with-no-args idiom and cannot figure out what it is supposed to do. Can you give a clue?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.