Table Of ContentEarly Praise for Deploying JRuby
Deploying with JRuby is the definitive text on getting JRuby applications up and
running. Joe has pulled together a great collection of deployment knowledge, and
the JRuby story is much stronger as a result.
➤ Charles Oliver Nutter
JRuby Core team member and coauthor, Using JRuby
Deploying with JRuby answers all of the most frequently asked questions regarding
real-world use of JRuby that I have seen, including many we were not able to
answer in Using JRuby. Whether you’re coming to JRuby from Ruby or Java, Joe
fills in all the gaps you’ll need to deploy JRuby with confidence.
➤ Nick Sieger
JRuby Core team member and coauthor, Using JRuby
This book is an excellent guide to navigating the various JRuby deployment op-
tions. Joe is fair in his assessment of these technologies and describes a clear
path for getting your Ruby application up and running on the JVM.
➤ Bob McWhirter
TorqueBox team lead at Red Hat
Essential reading to learn not only how to deploy web applications on JRuby but
also why.
➤ David Calavera
Creator of Trinidad
Deploying with JRuby is a must-read for anyone interested in production JRuby
deployments. The book walks through the major deployment strategies by providing
easy-to-follow examples that help the reader take full advantage of the JRuby
servers while avoiding the common pitfalls of migrating an application to JRuby.
➤ Ben Browning
TorqueBox developer at Red Hat
Deploying with JRuby is an invaluable resource for anyone planning on using
JRuby for web-based development. For those who have never used JRuby, Joe
clearly presents its many advantages and few disadvantages in comparison to
MRI.
➤ Toby Crawley
TorqueBox developer at Red Hat
Within half an hour of picking up this book I found a solution to a deployment
problem I’ve had for months. Loaded with solid insight and relevant examples,
this book is a must-have if you’re looking for an approach to deployment that
doesn’t involve holding your breath.
➤ Bryan Powell
Founder of Metabahn, creator of Pakyow
Deploying with JRuby
Deliver Scalable Web Apps Using the JVM
Joe Kutner
The Pragmatic Bookshelf
Dallas, Texas • Raleigh, North Carolina
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, and The Pragmatic
Programmers, LLC was aware of a trademark claim, the designations have been printed in
initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer,
Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade-
marks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes
no responsibility for errors or omissions, or for damages that may result from the use of
information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create
better software and have more fun. For more information, as well as the latest Pragmatic
titles, please visit us at http://pragprog.com.
The team that produced this book includes:
Brian P. Hogan (editor)
Potomac Indexing, LLC (indexer)
Kim Wimpsett (copyeditor)
David J Kelly (typesetter)
Janet Furlow (producer)
Juliet Benda (rights)
Ellie Callahan (support)
Copyright © 2012 The Pragmatic Programmers, LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form, or by any means, electronic, mechanical, photocopying,
recording, or otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN-13: 978-1-934356-97-5
Encoded using the finest acid-free high-entropy binary digits.
Book version: P1.0—July 2012
Contents
Acknowledgments . . . . . . . . . . . ix
Preface . . . . . . . . . . . . . . xi
1. Getting Started with JRuby . . . . . . . . . 1
1.1 What Makes JRuby So Great? 2
1.2 Introducing Warbler 4
1.3 Preparing Twitalytics for JRuby 7
1.4 Configuring Warbler for Twitalytics 13
1.5 Wrapping Up 18
2. Creating a Deployment Environment . . . . . . . 19
2.1 Creating a Virtual Server 19
2.2 Provisioning with Puppet 22
2.3 Packaging the Deployment Environment 33
2.4 Using Alternative Platforms 33
2.5 Wrapping Up 35
3. Deploying an Archive File . . . . . . . . . 37
3.1 Provisioning a Server 38
3.2 Installing Apache Tomcat 39
3.3 Creating the Deployment Script 43
3.4 Using Precompiled Assets with Warbler 48
3.5 Deploying to the Cloud 50
3.6 Wrapping Up 54
4. Creating a Trinidad Application . . . . . . . . 57
4.1 What Is Traditional Deployment? 58
4.2 Getting Started with Trinidad 58
4.3 Adding Trinidad Extensions 60
4.4 Choosing Alternatives to Trinidad 73
4.5 Wrapping Up 74
Contents • vi
5. Deploying a Trinidad Application . . . . . . . 75
5.1 Provisioning a Server 75
5.2 Installing Trinidad as a Service 78
5.3 Hot-Deploying with Capistrano 82
5.4 Configuring Apache 90
5.5 Choosing Alternative Deployment Strategies 94
5.6 Wrapping Up 100
6. Creating a TorqueBox Application . . . . . . . 103
6.1 What Is an Application Server? 104
6.2 Getting Started with TorqueBox 106
6.3 Creating a Deployment Descriptor 109
6.4 Using the Management Console 111
6.5 Scheduling a Recurring Job 111
6.6 Creating a Long-Running Daemon 115
6.7 Running Background Jobs 118
6.8 Pushing to the Browser with Stomplets 125
6.9 Testing a TorqueBox Application 131
6.10 Wrapping Up 132
7. Deploying a TorqueBox Application . . . . . . . 133
7.1 Choosing a Deployment Strategy 134
7.2 Creating a Deployment Environment 135
7.3 Installing TorqueBox 138
7.4 Deploying an Archive File 142
7.5 Wrapping Up 147
8. Clustering a TorqueBox Application . . . . . . 149
8.1 Creating the Cluster 151
8.2 Installing the Apache Cluster Module 153
8.3 Deploying to the Cluster 155
8.4 Using High-Availability Jobs and Services 155
8.5 Using Session Replication 158
8.6 Running in Domain Mode 160
8.7 Wrapping Up 161
9. Managing a JRuby Deployment . . . . . . . . 163
9.1 Configuring the Runtime 163
9.2 Inspecting the Runtime with JMX 167
9.3 Managing the Runtime with JMX 170
9.4 Creating a Management Bean 173
vii • Contents
9.5 Profiling an Application 175
9.6 Wrapping Up 179
10. Using a Continuous Integration Server . . . . . . 181
10.1 Installing Jenkins 182
10.2 Creating a Git Depot 182
10.3 Creating a Jenkins Job 184
10.4 Archiving Artifacts with Jenkins 187
10.5 Wrapping Up 188
Index . . . . . . . . . . . . . . 191
Acknowledgments
It’s a remarkable feeling to have other people offer their time and energy to
help improve a project that is your own creation. I have been fortunate enough
to experience this feeling multiple times over the course of writing this book,
so it is important that I try to thank the people who helped make it possible.
I must first thank the reviewers of my book who do not know me. I was
shocked by the attention to detail and wise feedback they provided in making
my book a finished product. Thank you to Jeff Holland, Matt Margolis, Stephen
Wolff, Sam Rose, Tibor Simic, Frederico Tomassetti, Charley Stran, Ian Dees,
Kevin Gisi, Wil Moore III, and the dozens of people who reported errata while
this book was in beta. I consider you all to be my friends!
Thank you to my wonderful colleagues for their experience, wisdom, and
editorial feedback as I worked on this project. They helped me in both the
proposal process and the review process: Lyle Johnson, Matt Blackmon,
Joshua Rufer, Bryan Powell, Bret Young, Matt Smith, and Robert Miller. This
paragraph does not do our friendship justice. Thank you.
I would also like to thank the staff at the Pragmatic Bookshelf: Susannah
Pfalzer, Dave Thomas, Andy Hunt, and probably a whole bunch of other
people I don’t know about. Above all, thank you to Brian P. Hogan, my editor.
You have been fair and kind in dealing with much of the crude prose I’ve
thrown your way. Thank you for helping me with this book and to become a
better writer.
It is also important that I thank the creators of the technologies I have written
about. This book would not have been possible without their hard work.
Thank you to Charles Nutter, Thomas Enebo, Nick Seiger, and the rest of the
JRuby team. You are the most amazing group in all of the open source world.
Thank you to David Calavera and Karol Bucek of the Trinidad project. Even
during the holiday season, these brilliant programmers made themselves
available to answer my questions. Thank you to Ben Browning, Toby Crawley,
Bob McWhirter, Lance Ball, Jim Crossley, Marek Goldmann, and the rest of
Description:Deploy using the JVMs high performance while building your apps in the language you love. JRuby is a fast, scalable, and powerful JVM language with all the benefits of a traditional Ruby environment. See how to consolidate the many moving parts of an MRI-based Ruby deployment onto a single JVM proce