™ SPONSORED BY

Since 1994: The Original Magazine of the Community AUGUST 2014 | ISSUE 244 | www.linuxjournal.com PROGRAMMING HOW-TO: + OpenGL Build, Develop Programming and Validate Creation of RPMs

USE VAGRANT Sysadmin Cloud for an Easier Troubleshooting Development with dhclient Workflow Tips for PROMISE Becoming a THEORY Web Developer An In-Depth A Rundown Look of Linux for Recreation V

WATCH: ISSUE OVERVIEW

LJ244-Aug2014.indd 1 7/23/14 6:56 PM Get the automation platform that makes it easy to:

Build Infrastructure Deploy Applications Manage

In your data center or in the cloud.

getchef.com

LJ244-Aug2014.indd 2 7/23/14 11:41 AM Are you tiredtiered of of dealing dealing with with proprietary proprietary storage? storage? ®

9%2Ä4MHÆDCÄ2SNQ@FD ZFS Unified Storage zStax StorCore from Silicon - From modest data storage needs to a multi-tiered production storage environment, zStax StorCore

zStax StorCore 64 zStax StorCore 104

The zStax StorCore 64 utilizes the latest in The zStax StorCore 104 is the flagship of the dual-processor Intel® Xeon® platforms and fast zStax product line. With its highly available SAS SSDs for caching. The zStax StorCore 64 configurations and scalable architecture, the platform is perfect for: zStax StorCore 104 platform is ideal for:

‡VPDOOPHGLXPRIILFHILOHVHUYHUV ‡EDFNHQGVWRUDJHIRUYLUWXDOL]HGHQYLURQPHQWV ‡VWUHDPLQJYLGHRKRVWV ‡PLVVLRQFULWLFDOGDWDEDVHDSSOLFDWLRQV ‡VPDOOGDWDDUFKLYHV ‡DOZD\VDYDLODEOHDFWLYHDUFKLYHV

TalkTalk with with an anexpert expert today: today: 866-352-1173 866-352-1173 - http://www.siliconmechanics.com/zstax

LJ244-Aug2014.indd 3 7/23/14 11:41 AM AUGUST 2014 CONTENTS ISSUE 244 PROGRAMMING FEATURES 64 Vagrant 74 An Introduction to How to use Vagrant to create a OpenGL Programming much easier development workflow. Is it difficult to rotate a 3-D cube Richard Delaney in OpenGL? Mihalis Tsoukalos

ON THE COVER ‹/V^;V!6WLU.37YVNYHTTPUNW ‹VYRMSV^W ‹7YVTPZL;OLVY`HU0U+LW[O3VVRW  ‹)\PSK+L]LSVWHUK=HSPKH[L*YLH[PVUVM974ZW  ‹:`ZHKTPU*SV\K;YV\ISLZOVV[PUN^P[OKOJSPLU[W ‹;PWZMVY)LJVTPUNH>LI+L]LSVWLYW ‹(9\UKV^UVM3PU\_MVY9LJYLH[PVUW

Cover Image: © Can Stock Photo Inc. / Krisdog

4 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 4 7/23/14 11:41 AM INDEPTH 90 Promise Theory—What Is It? Promise Theory has been adopted more widely in recent years in connection with Defined Networking as it embodies many of the principles on which networking is based.

Mark Burgess 22 96 Integrating Trac, Jenkins and Cobbler—Customizing Linux Operating Systems for Organizational Needs A process to build, develop and validate creation of RPMs to be included with the Scientific deployed on HPC systems. David Brown COLUMNS 48 30 Reuven M. Lerner’s At the Forge First Steps with Web Development 38 Dave Taylor’s Work the Shell Days Between Dates: the Counting 74 44 Kyle Rankin’s Hack and / Not So Dynamic Updates IN EVERY ISSUE 48 Shawn Powers’ The Open-Source Classroom 8 Current_Issue.tar.gz First Health, Now Recreation 10 Letters 16 UPFRONT 108 Doc Searls’ EOF 28 Editors’ Choice Can We Stop Playing Card Games 60 New Products with Business? 111 Advertisers Index

LINUX JOURNAL (ISSN 1075-3583) is published monthly by Belltown Media, Inc., 2121 Sage Road, Ste. 395, Houston, TX 77056 USA. Subscription rate is $29.50/year. Subscriptions start with the next issue.

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 5

LJ244-Aug2014.indd 5 7/23/14 11:41 AM Executive Editor Jill Franklin [email protected] Senior Editor Doc Searls [email protected] Associate Editor Shawn Powers [email protected] Art Director Garrick Antikajian [email protected] Products Editor James Gray [email protected] Editor Emeritus Don Marti [email protected] Technical Editor Michael Baxter [email protected] Senior Columnist Reuven Lerner [email protected] Security Editor Mick Bauer [email protected] Hack Editor Kyle Rankin lj@greenfly.net Virtual Editor Bill Childers [email protected]

Contributing Editors )BRAHIM (ADDAD s 2OBERT ,OVE s :ACK "ROWN s $AVE 0HILLIPS s -ARCO &IORETTI s ,UDOVIC -ARCOTTE 0AUL "ARRY s 0AUL -C+ENNEY s $AVE 4AYLOR s $IRK %LMENDORF s *USTIN 2YAN s !DAM -ONSEN

Publisher Carlie Fairchild [email protected]

Director of Sales John Grogan [email protected]

Associate Publisher Mark Irgang [email protected]

Webmistress Katherine Druckman [email protected]

Accountant Candy Beauchamp [email protected]

Linux Journal is published by, and is a registered trade name of, Belltown Media, Inc. PO Box 980985, Houston, TX 77098 USA

Editorial Advisory Panel "RAD !BRAM "AILLIO s .ICK "ARONIAN s (ARI "OUKIS s 3TEVE #ASE +ALYANA +RISHNA #HADALAVADA s "RIAN #ONNER s #ALEB 3 #ULLEN +EIR $AVIS s -ICHAEL %AGER s .ICK &ALTYS s $ENNIS &RANKLIN &REY 6ICTOR 'REGORIO s 0HILIP *ACOB s *AY +RUIZENGA s $AVID ! ,ANE 3TEVE -ARQUEZ s $AVE -C!LLISTER s #ARSON -C$ONALD s #RAIG /DA *EFFREY $ 0ARENT s #HARNELL 0UGSLEY s 4HOMAS 1UINLAN s -IKE 2OBERTS +RISTIN 3HOEMAKER s #HRIS $ 3TARK s 0ATRICK 3WARTZ s *AMES 7ALKER

Advertising % -!),: [email protected] URL: www.linuxjournal.com/advertising 0(/.%     EXT 

Subscriptions % -!),: [email protected] URL: www.linuxjournal.com/subscribe MAIL: PO Box 980985, Houston, TX 77098 USA

LINUX is a registered trademark of .

LJ244-Aug2014.indd 6 7/23/14 11:41 AM '14HPCadLinuxJnl.qxp_Layout 1 6/17/14 10:21 AM Page 1

SAVE 11th Annual THE DATE 2014 HIGH PERFORMANCE COMPUTING FOR WALL STREET Show and Conference (Monday) September 22, 2014 RooseveltMadison Ave and 45th Hotel, St, next to Grand NYC Central Station Big Data, Cloud, Linux, Low Latency, Networks, Data Centers, Cost Savings. Wall Street IT professionals and programmers will assemble at this 2014 HPC Show and Conference, Sept. 22. New for 2014 – Database Month programmers to speak on the program. his 11th Annual HPC networking opportunity will assemble 600 Wall Street TIT professionals at one time and one place in New York on September 22. This HPC for Wall Street conference is focused on High Put-through, Low Latency, Networks, Data Centers, lowering costs of operation. Our Show is an efficient one-day showcase and networking opportunity. Leading companies will be showing their newest systems live on-the-show floor. Register in advance for the full conference program which includes general sessions, drill-down sessions, an industry luncheon, coffee breaks, exclusive viewing times in the exhibits, and more. Save $100. $295 in advance. $395 on site. Don’t have time for the full Conference? Attend the free Show. Register in advance at: www.flaggmgmt.com/hpc

Wall Street programmers will lead Show Hours: Mon, Sept 22 8:00 - 4:00 drill-down sessions in the Grand Conference Hours: 8:30 - 4:50 Ballroom program.

September 2013 Sponsors

Media Sponsors

Show & Conference: Flagg Management Inc 353 Lexington Avenue, New York 10016 (212) 286 0333 fax: (212) 286 0086 [email protected] Visit: www.flaggmgmt.com/hpc

LJ244-Aug2014.indd 7 7/23/14 11:41 AM Current_Issue.tar.gz

Chocolate in SHAWN POWERS My Peanut Butter

rogramming always has been that If that sounds silly, that’s because it is! “thing” people did that I never Shell scripting is programming, and if Punderstood. You’ve heard me you’ve ever created sysadmin scripts or lament about my lack of programming even written batch files in Windows, skills through the years, and honestly, your programming skills are better I never thought I’d need to learn. Then than you think. along came the DevOps mentality, and I Kyle Rankin addresses an issue this started introducing programmatic ways month that can be really frustrating if of managing my system administration you’re automating a cloud environment. world. And you know what? If you spin up a server that gets Programming is pretty awesome. assigned a random IP address, how do Reuven M. Lerner starts off the you address it from the rest of your programming issue with a great article on infrastructure? He shows us his method how to begin in the Web development of dealing with that scenario and field. If you’re like me, and have been teaches us about DHCP along the way. ushered into the programmer’s world I decided to continue our summer blindfolded and scared, Reuven has a vacation a bit with my Open-Source great starting point for you. Dave Taylor Classroom column and talk about also teaches us programming as he recreation. Last month, I covered continues his lessons on scripting dates health-related technology, and so and counting days. For some reason, shell this month, I’m discussing mental- scripting doesn’t seem like programming, health-related technology—namely, and I’m far more comfortable doing it. games, TV, books and music. Next month, will be all command line and

V VIDEO: learning, but here I focus on enjoying Shawn Powers runs the technology that is supposed to through the latest issue. make our lives so much easier!

8 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 8 7/23/14 11:41 AM CURRENT_ISSUE.TAR.GZ

Next up is Richard Delaney. If you’ve one-size-fits-all solution to technology ever tried to automate your infrastructure needs. For many use cases, that’s still with something like Chef or Puppet, you true. If your organization needs a custom know that spinning up VMs on demand Linux distribution or needs to develop can be challenging. With Vagrant, something slightly different from what a creating a brand-new virtual machine is mainstream distro offers, that flexibility a simple one-liner. It supports multiple proves to be malleable as well. David virtualization platforms, multiple host Brown walks through customizing a Linux OSes and abstracts the underlying operating system to fit specific needs, process. Richard walks through using including custom development and system Vagrant in your VM infrastructure. modifications. Rather than create a new Mihalis Tsoukalos dives deep into ’buntu variant, David shows how to tweak programming as he shows how to existing distros to meet your needs. create three-dimensional graphics with I’ll admit, programming still is OpenGL. While creating a cube on scary territory for some of us, myself the screen isn’t exactly a contender included. In this issue, we ease into for Game of the Year, the process is some of the “development mindset” an invaluable building “block” for where we are no longer just consumers, developing with OpenGL. If you want to but creators. The beauty of open source manipulate graphics in your applications, is that we get to build on the brilliance Mihalis’ article is a must-read. of others, and knowledge is freely As data centers grow, and IT budgets shared, not guarded like a secret. shrink, managing massive numbers of We’ve also included a plethora of systems gets overwhelming quickly. In non-development content this month. fact, gone are the days when a crusty Whether you’re a sysadmin, a Linux old system administrator (ahem, me) enthusiast or just someone looking to can configure all the servers one by one play some cool games, the August issue and maintain them all him or herself. aims to please. We hope you enjoy this Mark Burgess describes Promise programming issue of Linux Journal.Q Theory, which is a framework on which to design and configure massive Shawn Powers is the Associate Editor for Linux Journal. distributed systems. If you need to He’s also the Gadget Guy for LinuxJournal.com, and he has re-invent the way your data center works, an interesting collection of vintage Garfield coffee mugs. Promise Theory is a great way to think. Don’t let his silly hairdo fool you, he’s a pretty ordinary guy Linux traditionally has been so and can be reached via e-mail at [email protected]. flexible that it often is considered a Or, swing by the #linuxjournal IRC channel on Freenode.net.

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 9

LJ244-Aug2014.indd 9 7/23/14 11:41 AM letters

Thanks David. I have to admit, when I first heard of the XKEYSCORE/NSA stuff, I went to our Web site to see what on earth might have attracted attention. The first thing I saw was a video still shot of me doing the issue intro with a really goofy look on my face. “This is the face of terror”, I said to my wife, who replied with something like, “we’re all doomed.”

We’re happy to have you as a subscriber, and we’ll try to continue with our extremist ways—whatever that might mean!—Shawn Powers I Must Be an Extremist Wow—you should have had the NSA Extremists? declare Linux Journal an extremist ! GLANCE AT THE 8+%93#/2% SNIPPET organization months ago. shows “These variables define terms and websites relating to the I had, sadly, let my subscription (The AmnesicIncognito Live expire a few months ago. However, System) software program, a comsec after reading that Linux Journal mechanism advocated by extremists and its readers are considered on extremist forums.”, followed by: “extremists” by the NSA, I have resubscribed for two years with "$TAILS_terms=word('tails' or 'Amnesiac Incognito automatic renewal after that. ´Live System') and word('linux' or ' USB ' ´or ' CD ' or 'secure desktop' or ' IRC ' or Take that NSA! ´'truecrypt' or ' '); $TAILS_websites=('tails.boum.org/') or And, thanks also for a great publication. ('linuxjournal.com/content/linux*');" Keep those extremist articles about privacy and freedom coming. Note that it is quite likely that extremist —David Both forums do advocate use of Tor and TAILs,

10 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 10 7/23/14 11:41 AM [ LETTERS ]

as do most comsec concerned folks, No More Letters in the Magazine? such as forensic specialists and malware I am disappointed that the Letters investigators, and perhaps, Three portion has moved to the Web site Letter Agencies. Since Linux Journal instead of being printed in Linux is a publicly available and informative Journal. I read LJ off-line with my Kindle forum on Linux items of interest, such and look forward to the Letters every as Tor and TAILs, I would suggest issue. Now that it’s no longer there, I that the proximity of “extremists on have to view it on my desktop, which extremist forums” to “linuxjournal.com/ defeats the purpose. Trying out the content/linux” does not associate Letters link on my Kindle when I’m on- “linuxjournal” with “extremist line does not provide me with content forums”. However, your point is that that is easy to read on the device. access to your Web site in conjunction with the Tor or TAILs query may put I remember this with paper magazines of one on a “watch list” for further old, where they provided “extra content” scrutiny—well, given the forensic and on the Web. I rarely visited them. And if malware workload these days, that will I wanted to, the magazine often wasn’t push the noise-to-signal ratio up quite with me anymore, and I’d forget the link. a bit (no pun intended). Do you think DistroWatch is somewhere on the list? Granted, I can view LJ on my Nexus 10, —Arnold Hayes or my MacBook, but nothing provides THE PLEASURE OF READING THAT IS % )NK It’s so crazy, it’s really hard to tell what the exact reason or triggers we might Also, looking at the link be associated with are. The concept http://www.linuxjournal.com/ at all is just...crazy. I can’t think of a letters, how would I know what was better word. The Linux community the response to what particular issue? and, in kind, the Linux Journal community are obviously advocates I propose an alternative, since you of freedom, but when standing for wanted to allow for comments: the very things that make America PUBLISH THE ,ETTERS TO THE %DITOR IN THE what it is marks us for scrutiny? magazine, with the replies if any, then Again, crazy.—Shawn Powers also provide a permalink to the letter

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 11

LJ244-Aug2014.indd 11 7/23/14 11:41 AM [ LETTERS ]

on the Web. This will: keep tweaking how we do things, and hopefully we’ll find a good solution. Your Q Allow me to read while in a relaxed input is invaluable, because otherwise mood, either the PDF, .epub or we’re just guessing!—Shawn Powers .mobi versions, without the need to switch context and jump to the I See the NSA Is Labeling Linux Web (and from there, go down the Journal as an Extremist Web Site rabbit hole of surfing). If Linux Journal is an American- based company with servers located Q If I’m passionate about a letter, I inside America’s borders, I’m sure can click on the link to see if there THE %LECTRONIC &RONTIER &OUNDATION are more responses. %&& https://www.eff.org) and/or American Civil Liberties Union Q I can comment on my thoughts, if I (ACLU, https://www.aclu.org) would have any on the particular topic. be happy to litigate a case on your behalf against the NSA, for free. With the letters still in my head, I can refer to the actual letter in question in Warrantless spying on an American LJ and click on the link for immediate journal and its users is clearly a violation gratification. of the first and fourth constitutional Amendments—freedom of speech, Since LJ is an electronically delivered association and warrantless surveillance. magazine, you do have possibilities that are within your power to manipulate to The lawsuit would be great publicity make the user’s experience better than for your magazine. Linux Journal what paper publications can do. vs. NSA would be plastered on the —Wari Wahnab front pages of every major news organization across the world. Thank you for the input, Wari. We did shift the Letters out of last issue, but we’ve I believe having a copy of the included them back in this one because of 8+%93#/2% SOURCE CODE SPECIFICALLY letters like yours. As you mention, we’re listing Linux Journal as a “target” trying to make the Letters something selector would give your lawsuit plenty that is interactive in a little more timely of standing for a case against the NSA. manner than once a month. We’ll —Ralf

12 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 12 7/23/14 11:41 AM [ LETTERS ]

Thank you, Ralf. As of this response, we’re Between Dates?” article in the July still just reeling a bit from the notion that  ISSUE HE STATES THAT date our readers, and most likely our staff, are doesn’t work for dates before 1970. being monitored and/or spied on. While we do have an international readership, If you are using the GNU corelib date we are indeed an entirely US-based utility, this is incorrect: magazine. The worrisome part is, if we are targeted, I can only imagine who else $ date +%s '1776-1-1' must be! Scary stuff.—Shawn Powers -6122019600

Days Between Dates Script $ date -d '@-6122019600' Regarding Dave Taylor’s “Days Between Mon Jan 1 00:00:00 MST 1776 $ATES v ARTICLE IN THE *ULY  ISSUE Also, date handles some pretty free- grep '29' => Yes, 1729 was a leapyear, so February 29, form date entries, although the date 1729 is a valid date. has to be a complete date—no attempts grep ' 29' => Oops, 1729 wasn't a leapyear, so February with only a month and year, for example.

only had 28 days. On a separate note, date +%j -d —Jyrki Kajala 'Dec 31, $year' will give you either 365 or 366, depending on whether or Dave Taylor replies: You’re right, the not it’s a leap year. I’m not sure how it addition of a leading space does make this handles years in which there were less invocation more accurate! This problem than 365 days. I suspect it just treats will, of course, show up any time there’s all dates as Gregorian. a “29” in the year, including in 2029, by —Alan Young which time we’ll likely have a different way of figuring out whether it’s a leap Dave Taylor replies: Thanks for the year. “Siri? Is this a leap year?” “Jyrki, you helpful message. As an old-school asked me that 4,503,343 milliseconds ago. Linux and UNIX guy, negative seconds- Why are you asking me again? Have you since-epoch bugs me, but that’s okay, become obsolete?” “AUuuugggghhhh!” because your observation that the %j day-of-the-year value easily can More on the Days Between Dates Script be used to test for leap year is terrific In the sidebar in Dave Taylor’s “Days and one I’m going to borrow!

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 13

LJ244-Aug2014.indd 13 7/23/14 11:41 AM [ LETTERS ]

Removing Letters to the Editor not always have a photo to share from the Digital Magazine with us every month. I was surprised to find that you are —Gerald no longer including the Letters to the %DITOR SECTION IN THE Linux Journal Thanks Gerald! Yes, we shook things up DIGITAL MAGAZINE AS OF THE *ULY  a bit taking out the Letters to the Editor. issue). Since your magazine has They’re (obviously) back this month. gone digital-only, I find that I now We’ll eventually find the perfect mix read it cover to cover (mostly), and I of interactivity and convenience. Last particularly enjoyed the give and take month, was our first step toward that that occurs between the readers and goal. Thank you for letting us know the article writers in the Letters section. your thoughts; it really helps us shape the future! We’ll continue having I realize that I can still read this Photo of the Month as well, as long as interchange on-line, but doing so adds we receive good submissions, so please a little more “friction” to the process send your Linux-related photos to and fails to inform me when there is [email protected].—Shawn Powers feedback on the various topics. Keep Up the Great Work! Since Linux Journal is now available only I just subscribed to LJ two months in digital formats (PDF, .epub and so ago, and I love it! I have been involved on), it seems that removing the Letters with and electronics since I section does not result in much of a cost- was ten years old when I started with savings (possibly a small savings in page THE !PPLE ))% ) ALSO LOVE HIGH POWER layout/markup/design). Do you have a rocketry! I plan on building a Linux more compelling reason for this change? to control a high-power rocket I plan on doing for Level 2 NAR If you feel that this must be a certification soon. Also, I love health permanent change, perhaps you could and fitness, as I was a personal trainer include a sidebar listing the topics of for nine years. Now I train and workout letters received (with links to enable hard-core for myself and train clients accessing them on-line). part time. I am a technology and fitness freak! I love it! I also miss the “Photo of the Month”, although I realize you may I love the PDF format of LJ, as this is

14 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 14 7/23/14 11:41 AM way of the future, since we can eliminate paper clutter and have links to click on when we want At Your Service more information on details. I love it! I have tons of paper books and old magazines that I want to SUBSCRIPTIONS: Linux Journal is available in a variety of digital formats, including PDF, convert to PDF. I started doing it myself with a .epub, .mobi and an on-line digital edition, as well as apps for iOS and Android devices. good Fujitsu scanner, but I have so many, I want Renewing your subscription, changing your e-mail address for issue delivery, paying your to hire someone or some company to scan most invoice, viewing your account details or other of these books for me. subscription inquiries can be done instantly on-line: http://www.linuxjournal.com/subs. E-mail us at [email protected] or reach us via postal mail at Linux Journal, PO Box Keep up all your amazing content in the PDF format! 980985, Houston, TX 77098 USA. Please remember to include your complete name —Christian Lombardo and address when contacting us.

ACCESSING THE DIGITAL ARCHIVE: Welcome aboard, Christian! I’m still struggling Your monthly download notifications will have links to the various formats with my fitness routine. The diet is going well and to the digital archive. To access the digital archive at any time, log in at (40 pounds lost as of today, July 5th), but http://www.linuxjournal.com/digital.

getting motivated to exercise is harder. I still try LETTERS TO THE EDITOR: We welcome your letters and encourage you to submit them to walk as much as possible, but I’d like to be a at http://www.linuxjournal.com/contact or mail them to Linux Journal, PO Box 980985, runner someday. Houston, TX 77098 USA. Letters may be edited for space and clarity.

Thanks for sharing your appreciation for the WRITING FOR US: We always are looking for contributed articles, tutorials and digital publication. The feelings on that subject real-world stories for the magazine. An author’s guide, a list of topics and vary widely from user to user. Thankfully, I think due dates can be found on-line: the tablet/reader market has matured to the http://www.linuxjournal.com/author. point where reading digitally is really a painless FREE e-NEWSLETTERS: Linux Journal editors publish newsletters on both experience.—Shawn Powers a weekly and monthly basis. Receive late-breaking news, technical tips and tricks, an inside look at upcoming issues and links to in-depth stories featured on http://www.linuxjournal.com. Subscribe for free today: http://www.linuxjournal.com/ WRITE LJ A LETTER enewsletters. We love hearing from our readers. Please ADVERTISING: Linux Journal is a great send us your comments and feedback via resource for readers and advertisers alike. Request a media kit, view our current http://www.linuxjournal.com/contact. editorial calendar and advertising due dates, or learn more about other advertising and marketing opportunities by visiting PHOTO OF THE MONTH us on-line: http://ww.linuxjournal.com/ advertising. Contact us directly for further Remember, send your Linux-related photos to information: [email protected] or [email protected]! +1 713-344-1956 ext. 2.

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 15

LJ244-Aug2014.indd 15 7/23/14 11:41 AM UPFRONT NEWS + FUN diff -u WHAT’S NEW IN KERNEL DEVELOPMENT

One problem with Linux has been of the kernel. its implementation of system H. Peter Anvin liked the idea, calls. As Andy Lutomirski pointed but said it would take a lot of OUT RECENTLY ITS VERY MESSY %VEN work to get it right. He mentioned identifying which system calls that he’d been advocating were implemented for which something along the same lines for architectures, he said, was very a long time, dating back to difficult, as was identifying the his work on klibc. mapping between a call’s name and Various other folks liked Andy’s its number, and mapping between idea as well—particularly anyone call argument registers and system involved with user code that call arguments. currently had to deduce system Some user programs like strace call organization piecemeal. David and glibc needed to know this sort Howells remarked that it would of information, but their way of be wonderful if strace could rely gathering it together—although well on Andy’s master list as well. accomplished—was very messy too. And, Michael Kerrisk said the Andy proposed slogging through manpages project also would be the kernel code and writing interested in tracking the progress up a text file that would serve of the master list. as a “master list” of system There’s always a special case that calls, giving the call name, the would benefit from tweaking the corresponding call number, the process scheduler just a little bit supported architectures and beyond The Good. Recently, Khalid other information. Among other Aziz from Oracle submitted some things, this would allow tools code to allow user processes to like glibc to eliminate their ugly claim additional timeslices. Typically, implementations and use a simple the kernel itself controls that sort library to get this information out of resource allocation, because

16 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 16 7/23/14 11:41 AM [ UPFRONT ]

otherwise the system is dependent allowed userspace to transform on the friendliness or well-codedness the kernel’s natural preemptive of user applications. multitasking into a cooperative But, Khalid’s database folks multitasking model, in which had noticed a problem with large processes all had to agree on numbers of threads vying for who would get timeslices, and the same mutex. If one of those when—and some processes could threads had the mutex and was aggressively claim timeslices at the almost ready to give it up, the expense of the others. scheduler might run through the Davidlohr Bueso pointed out whole queue of other processes, that a voluntary preemption model none of which could actually run might work better with the kernel’s because they were all waiting for existing implementation, allowing that one mutex. And like a thumb processes to give up their timeslice in the eye, the process holding to another process voluntarily. the mutex was all set to give it There was no danger from hostile up, but couldn’t, since it had processes there. been preempted. Much better, There were various suggestions Khalid said, would be to allow the for alternatives to Khalid’s design, process holding the mutex to delay but Khalid always pointed out preemption, long enough to give that his way was fastest. But, up that mutex. Then all the other Thomas Gleixner said that “It’s processes could take their turn and a horrible idea. What you are do actual work, rather than spend creating is a crystal ball-based their precious timeslices spinning form of time-bound priority ceiling on an unavailable lock. with the worst userspace interface Khalid said his code showed I’ve ever seen.” a 3–5% speedup relative to the That was the real problem, previous case. But, there was still a apparently. Giving user code the fair bit of reluctance to accept his ability to preempt the normal code into the kernel. scheduling process meant that In particular, H. Peter Anvin neither the kernel nor other pointed out that Khalid’s code userspace processes could predict

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 17

LJ244-Aug2014.indd 17 7/23/14 11:41 AM [ UPFRONT ]

the behavior of the system, or even properly debug problems. They Said It At one point Thomas said, “What you’re trying to do is essentially creating an ABI It is not always the same thing to be which we have to support and maintain a good man and a forever. And that definitely is worth a few good citizen. serious questions.” He added, “If we allow —Aristotle you to special-case your database workload, then we have no argument why we should Life is a reciprocal not do the same thing for real-time workloads exchange. To move forward, you have where the SCHED_FAIR housekeeping thread to give back. can hold a lock shortly to access some —Oprah Winfrey important data in the SCHED_FIFO real-time computation thread. Of course the RT people It is only possible want to avoid the lock contention as much as to live happily you do, just for different reasons.” ever after on a day-to-day basis. Eric W. Biederman also objected to —Margaret Bonnano Khalid’s code, saying, “You allow any task to extend its timeslice. Which means I The greater man the will get the question why does why does greater courtesy. really_important_job only miss its latency —Alfred Lord guarantees when running on the same box Tennyson as sched_preempt_using_job?” And he said, That is not what “Your change appears to have extremely Geek means to me. difficult to debug non-local effects.” We are more than There seems to be a lot of interest in the hobbies that implementing a feature like what Khalid we do or the things has proposed, but there also seems to be that we like. To me, Geek means an security concerns, debugability concerns outsider, a rebel, a and maintainability concerns that make the dreamer, a creator, a whole thing very iffy. But, it’s still possible fighter. It’s a person that Khalid could address those concerns and who dares to love come up with a patch that does what the something that database people want, without the mess. isn’t conventional. —ZACK BROWN —Felicia Day

18 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 18 7/23/14 11:41 AM [ UPFRONT ]

Non-Linux FOSS: a Virtualized Cisco Infrastructure?

We’re all familiar with the idea of virtualized computers. Not only are they a great way to better utilize resources in a server room, but they also allow you to create and destroy servers in the blink of an eye. That’s perfect for a lab or training environment. Unfortunately, it’s always taken a rack of actual hardware to create a training lab for Cisco hardware. Thanks to Screenshot provided by http://www.gns3.net. GNS3 (Graphical Network Simulator 3), that’s no longer the case. Whether you’re actively trying to learn GNS3 is an open-source application to use Cisco devices or just want to try that creates a virtual infrastructure of out some networking scenarios, GNS3 is Cisco (or other) hardware. Not only an incredible tool for sandboxing network can you watch the traffic flow, but you hardware. It does require you to provide also can connect directly to the virtual the IOS firmware (they can’t provide devices and configure them like the Cisco’s operating systems themselves), actual hardware devices they represent. but that’s it. It works under Windows, On the surface, it looks like a Visio along with OS X and Linux. If you’re diagram, but it’s a diagram that actually interested, download a copy today at does something! http://www.gns3.net.—SHAWN POWERS

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 19

LJ244-Aug2014.indd 19 7/23/14 11:41 AM [ UPFRONT ]

IndieBox: for Gamers Who Miss Boxes!

There are lots of cool ideas on the Internet that never really make it out of the “startup” phase. IndieBox has been around only for a few months, but I really, really hope it catches on. Here’s the idea:

Q %VERY MONTH YOU GET a Linux/Mac/Windows- compatible Indie game in the mail. Photo courtesy of http://www.theindiebox.com. Q The games come on a really cool USB drive shaped like boxed games are awesome, Steam a credit card covered in awesome still is really convenient. game art. It’s like a modern-day Nintendo cartridge. As someone who belongs to a “coffee of the month” club, I can assure you that Q Inside the game box (which is also getting a fresh new thing every month in covered in game art), you’ll find the mail is fun and exciting. When that posters, keychains, cardboard cutouts, new thing is a nostalgic trip to my youth, CDs of game music or anything else plus a really fun cross-platform game? the folks at IndieBox can scrape For me, it’s worth the $16.99 a month. together to make the monthly game If you miss the days of buying games in awesome and nostalgic. a box from the department store, you’ll love the IndieBox experience. Check it Q Most months you’ll also get a Steam out at http://www.theindiebox.com. code, because although old-school —SHAWN POWERS

20 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 20 7/23/14 11:41 AM [ UPFRONT ]

Roll Your Own YouTube/ with MediaGoblin

%VERYONE HAS WASTED AN afternoon on YouTube clicking through videos of talking cats, screaming goats and bad-lip- reading renditions of popular movies. Heck, there are plenty of YouTube videos of me doing odd and silly things as well. (Does anyone remember ’Buntu Family Theater?) For important family videos, however, I much prefer to control my own data. I’ve tried over the years to keep an archive of home movies and Screenshot from http://roaming-initiative.com/ such in a folder on a server mediagoblin/u/jeeelo/m/hackers. somewhere, but they never get seen because getting to them in cup of tea, but for me, it’s a great inconvenient. That’s where MediaGoblin compromise between convenience comes in. and data privacy. If you want to give MediaGoblin is an open-source MediaGoblin a try, head over to Web-based application that allows you http://www.mediagoblin.org to host audio, video and photographic and download a copy today. Or, media on your own server. It still check out one of the many publicly allows that media to be easily viewed hosted installations to see if you like via the Web, however, so you get the interface. The screenshot here is the convenience of YouTube with the from http://roaming-initiative.com/ security of hosting files yourself. mediagoblin/u/jeeelo/m/hackers and Hosting your own local version includes an interview that hits home for of YouTube might not be your nerds like us!—SHAWN POWERS

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 21

LJ244-Aug2014.indd 21 7/23/14 11:41 AM [ UPFRONT ]

Getting Good Vibrations with Linux

Vibrations and wave motions describe options. In the main window, there many different physical systems. In will be a starting sine wave form. fact, most systems that dissipate Just to make sure that everything energy do so through waves of one is working, you can click on the start form or another. In this article, I button in the right-hand pane. This take a look at gvb (Good ViBrations, starts the calculations used to model http://www.pietrobattiston.it/gvb), the wave motion and shows each a Linux application you can use to time step in the main display window. visualize and model wave motion You should see the evolution of a and vibrations. basic sine wave happening. Installation should be relatively Let’s use this starting waveform easy. It already should exist in to play with some of the available the packaging system of most calculation options. The first option distributions. For example, on is the speed of the wave. You can -based systems, you can change this while the wave is being install it with this: modeled and animated, so you can see in real time how the wave sudo apt-get install gvb changes with a different speed. Below the start button are three You will notice that a large available options. The calculation number of Python requirements also drop-down lets you change are installed. This gives you an idea the algorithm used to do the of what you need as requirements if calculations. The default is eig, you want to build gvb from source. and the other three methods are Now that you have gvb and its quad, naif and naif matrix. When requirements installed, you can start you select any of the other three it by running the command gvb. methods, the step size option at the When it starts, you will see a main top of the pane becomes active. display window with a pane on the You then can change the size right-hand side with calculation of the steps used in calculating

22 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 22 7/23/14 11:41 AM [ UPFRONT ]

Figure 1. When you first start gvb, you will see a sine wave ready to start modeling.

the wave motion. You can set the shows the waveform itself. Temp number of frames per second to displays a color map representing display. The higher this value is, the the amplitude with different colors. smoother your wave animation will Speed displays the waveform, like be. You probably won’t notice any Wave, but it also includes a series improvement beyond 30 frames per of bars along the wave indicating second, simply due to the limits of the magnitude of the speed at those human vision. points along the wave. This display The last option allows you to helps students get a feeling for how change what graphics are actually fast the different parts of the wave rendered in the display. Wave are moving.

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 23

LJ244-Aug2014.indd 23 7/23/14 11:41 AM [ UPFRONT ]

Before going on, it would be current amplitude of the wave at worth spending a few minutes to some point and calculates how far take a cursory look at the types it should travel based on a linear of calculations gvb can do. The application of the current speed at default calculation method is eig. that point. This method actually uses the The naif matrix method just tries eig() function found in the linalg to speed up the naif method by part of NumPy. This uses the plane treating the wave as a vector rather wave expansion method to get than point by point. Neither of an eigenvalue formulation of the these two methods should be used problem and solve that. for any reason other than to see The naif calculation method is a just how bad they are. naive method. It simply takes the The last method is quad. This

Figure 2. You even can model waves on a membrane with gvb.

24 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 24 7/23/14 11:41 AM [ UPFRONT ]

method expands on the simplistic will find more than a dozen speed calculation of the naif method available options. with a more accurate method. In You also may have noticed that most cases, you simply will want to there is also an entry for two- use the eig method, as it is the most dimensional precooked options. accurate for most situations. That’s right, gvb can model waves Up until now, I’ve only been on a membrane as well. discussing a sinusoidal wave on a If you select one of these string. But really interesting things precooked options, you should happen when you can look at notice that the graphics option is other starting waveforms. There changed to 3-D, and the type of are a series of pre-programmed drawing is changed from rope to waveforms available for you under membrane. Clicking the start the menu entry DispositionA1 button will show you how the dimension: precooked. Here you starting waveform propagates

Figure 3. The advanced window allows you to create your own customized waveforms.

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 25

LJ244-Aug2014.indd 25 7/23/14 11:41 AM [ UPFRONT ]

across the given membrane. Under of the wave you are modeling. the Disposition menu entry, there Selecting the menu entry also are entries for advanced OptionsASave frames as png will one- and two-dimensional systems. pull up a file selection window. You Selecting one of these will pop need to choose a directory to store up a new window where you can all of the image files for each frame set the various parameters for your of the animation. Once this is done own model. and you click the start button, a You still are limited to sinusoidal, PNG file will be written out for each triangular, square and peak waves frame. In order to generate a movie as your base forms. If you have out of those, you need to have something even more complicated FFmpeg installed on your system. in mind, you actually can define the Then, all you have to do is change amplitude and speed at each point directory to the spot where gvb is in a text file. For example, to model writing out these image files and a string, the text file will have three run the command: lines. The first line will contain the shape—in this case, the number ffmpeg -i *.png video.mp4 of points along the string. The second line will contain a series of Now you have a video file that amplitude values, comma-separated, you can share displaying the wave one for each point. The third line evolution that you are modeling. will contain a series of speed As you have seen, gvb can be a very values, comma-separated, one for fun application to use. It especially each point. You next need to end gives students a more intuitive feel the file with a new-line character for how waves behave, in both one at the end. Then, you can read this and two dimensions. The ability into gvb to provide your starting to visualize the speeds for various waveform. This gives you maximum sections also helps conceptualize flexibility. You can do the equivalent the physics involved. Hopefully, the two-dimensional input file if you teachers out there will keep gvb in want to model a membrane rather mind when they are planning their than a string. next science class to help students One final thing you may want to understand wave mechanics. do with gvb is generate a movie —JOEY BERNARD

26 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 26 7/23/14 11:41 AM STOP THEM BEFORE THEY STOP YOU.

LINUX JOURNAL PRESENTS A SPECIAL FREE WEB EVENT: One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems WEDNESDAY, AUGUST 27TH at 11:00AM JOIN THE LINUX JOURNAL SECURITY EXPERTS AND As Linux continues to advance in its take-over of BIT9’S PAUL RIEGLE corporate data centers and institutions, ensuring the FOR A DISCUSSION COVERING: integrity and protection of Linux systems becomes a more critical priority every day. With 60% of the i The rise of Linux advanced world’s websites and an increasing share of most attacks—why signature-based organizations’ mission-critical workloads running on security measures are ineffective Linux, failing to stop malware and other advanced against advanced attacks. threats on Linux can severely negatively impact an i organization’s reputation and bottom line. A brief overview of Bit9 + Carbon Black’s application While Linux contains several features that can control and ETDR solutions. provide enhanced system security and integrity, most organizations either do not implement or only i How to help your organization occasionally ensure proper enforcement. Why? centrally manage and enforce Because they lack 1) real-time visibility into their security policies across large environments and 2) the ability to centrally enforce Linux environments. policy across their entire system.

>> Reserve your spot NOW for this valuable FREE webinar!

LJ244-Aug2014.indd 27 7/23/14 2:14 PM [ EDITORS' CHOICE ]

EDITORS’ Android Candy: CHOICE Oyster—Netflix ★ for Books!

For avid readers who can’t find portability. Sometimes, however, it can the time to visit their local library be difficult to find the book you want or struggle to carry giant tomes of IN A FORMAT YOU CAN READ %NTER /YSTER awesomeness around with them, (http://www.oysterbooks.com). eBooks have become a convenient Netflix has taken movie streaming to way to consume books. Whether it’s the point where it’s more common to on a Kindle, a Nook or in an app on stream a movie than it is to rent a DVD. your phone, eBooks are the ultimate in Heck, many of us have abandoned all

LINUX JOURNAL now available for the iPad and iPhone at the App Store.

linuxjournal.com/ios

For more information about advertising opportunities within Linux Journal iPhone, iPad and Android apps, contact John Grogan at +1-713-344-1956 x2 or [email protected].

LJ244-Aug2014.indd 28 7/23/14 11:41 AM television entertainment options except Netflix. Oyster is an app designed to do the same for books. For $9.95 a month, you get access to more than a half-million books and enjoy unlimited reading on your Android- powered device. The app features cross-device (and cross- platform) location sync, off-line reading and a 30-day free trial with unlimited book reading. Like Netflix, Oyster does use DRM on its titles. Because the books aren’t ever owned by me, I personally don’t have a moral dilemma with DRM in this case, but for some it will be a showstopper. Nevertheless, due to its wide selection, awesome idea and cross-platform availability, Oyster takes this month’s %DITORS #HOICE AWARD —SHAWN POWERS

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 29

LJ244-Aug2014.indd 29 7/23/14 11:41 AM COLUMNS AT THE FORGE

First Steps REUVEN M. LERNER with Web Development Interested in becoming a Web developer? Here are some tips on where to start.

The Web is more than 20 years old, with the growth of the Web, also and a huge number of developers now comes opportunity. During the past work with it. It used to be enough to few months, my consulting work be a “Webmaster”, meaning a jack of has increasingly involved coaching all trades: developer, designer, database individuals who see the potential administrator and system administrator. payoff (financial and personal) for Today, we see increasingly specialized becoming Web developers, and who aspects of Web development—front- want to improve their skills in order end developers, back-end developers, to do so. These people know if they devops professionals and then “full- manage to learn these skills, they’ll be stack developers”, who can do it all, able to find a job, either with a startup or at least claim to. or a large firm—or even better, starting This increased specialization their own on-line businesses. reflects, in large part, the degree to I’ve been exposed to more and which the Web has become huge and more people who know they want essential. Web sites are an important to work with “the Web”, and they part of the world economy, and know they want to develop software, as befits an important part of the but they really don’t understand the economy, they need to be designed, fundamentals or even where to begin. developed and maintained like any So in this article, I describe some of other type of engineering. the basics people should know if they’re But with the specialization, and interested in doing Web development.

30 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 30 7/23/14 11:41 AM COLUMNS AT THE FORGE

Not only are many traditional servers running Linux, but virtualization has become a stable and popular technology, using such systems as Vagrant, an open-source system that lets you develop on a virtual machine and then use that same virtual machine in production.

As a full-stack Web developer myself, Linux is a good thing. However, it’s I think it’s important for anyone not just good, but essential, given working with Web technologies to that Linux powers a surprisingly large have at least a passing knowledge of proportion of the Web. Not only each of these topics: Linux, databases, are many traditional servers running a server-side language and framework, Linux, but virtualization has become a and client-side technologies (HTML, stable and popular technology, using CSS and JavaScript). such systems as Vagrant, an open- If you can learn at least a little source system that lets you develop on of each of those, you’ll be well on a virtual machine and then use that your way to being able to create same virtual machine in production. Web applications. Moreover, you’ll I must admit that I haven’t yet taken probably find that one or more parts the plunge and used Vagrant, but of this technological constellation are each time I have to wrestle with server particularly appealing to you, giving configuration or get something to you a sense of the area in which you work on my employee’s computer that want to specialize. Or, if you find worked fine on mine, Vagrant seems that you enjoy it all, you can be more like an increasingly good option. of a generalist, applying your broad But really, if all you want to do is start knowledge to many different aspects with some Web development, a deep of Web applications. dive into Linux isn’t necessary. Yes, you need to understand some basics, such Linux and Servers as directories, users and permissions, Perhaps it won’t surprise a reader of as well as how to install and run Linux Journal that being familiar with programs. You also should know

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 31

LJ244-Aug2014.indd 31 7/23/14 11:41 AM COLUMNS AT THE FORGE

where your system’s log files are—both how to work with it and feel more general-purpose log files and also those comfortable working with it. produced by your HTTP server. If you’re new to the world of Linux Databases administration, learning such systems There is no requirement that a Web as DNS, SMTP and SSL might well application have a database. However, confuse more than help you; try to in practice, it’s rare for a modern Web rely on third parties for as much of application not to use a database at all. this as possible. (My company’s Web site doesn’t have a Knowing how to use a classic UNIX database, but that’s because it’s mostly TEXT EDITOR SUCH AS %MACS OR VIM for promotional purposes. However, will help a great deal, even if you’re my blog does have a database to store more of a GUI kind of person, simply posts and comments, among other because you won’t always have access things.) I’m an old-school kind of guy, to a GUI. And of course, learning the so I believe that traditional, relational ins and outs of UNIX utilities, such as DATABASES WITH 31, ARE THE RIGHT WAY grep and find, will help tremendously. to go for many Web applications. I would say that you shouldn’t However, I do admit that the learning worry too much about all of the curve—of a client-server protocol, of virtualization and container systems THE 31, QUERY LANGUAGE AND OF THE that exist—not because they are various tricks involved in a relational irrelevant, but because they likely will database—can be steep. confuse and complicate your progress, For this reason alone, many people and those are things you can learn starting off in Web development have over time. If and when you decide to BEGUN TO USE SO CALLED .O31, DATABASES use Vagrant, Docker or Amazon Web such as MongoDB, which allow you Services, you can specialize and learn to store complex documents in a those particulars. format that naturally maps to objects I should add that Linux is a deep and and modern programming languages, complex system, one that takes many WITHOUT THE OVERHEAD OF 31, QUERIES years to understand and internalize I can understand this perspective, and fully. If it seems foreign and difficult IF YOU FEEL THAT LEARNING 31, WOULD BE at first, that’s only natural, but too complex for you, you might indeed over time, you’ll customize your want to go this way. environment, learn more about However, I think there’s a reason why

32 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 32 7/23/14 11:41 AM COLUMNS AT THE FORGE

relational databases continue to be so Programming Languages popular, namely because more than Next comes the most important  YEARS OF RESEARCH AND PRACTICE HAVE choice, but also the one that probably been so beneficial. I personally think causes the greatest number of it’s worth the time and effort to work arguments among developers: the with a relational database, particularly server-side programming language. if you’ll be using a high-level language Longtime readers of this column and object-relational manager (ORM) won’t be surprised to hear that I think that handles most of the queries for Python and Ruby are likely to be your you and, thus, hides many of the best candidates, both because of the queries from you. The long-term languages themselves, and because BENEFITS OF UNDERSTANDING 31, AND the Flask and Sinatra frameworks relational databases, and the flexibility are simple, powerful and well of a normalized relational database, documented, with large communities. are still without peer, in my view. You can create great Web applications This doesn’t mean I think that all with these frameworks—or, if you .O31, IS MEANINGLESS OR WORTHLESS find that you’re cobbling together However, I have found much more too many separate packages, you utility in key-value stores, such as can move up to Django and Rails, 2EDIS THAN IN .O31, DATABASES SUCH frameworks that undoubtedly can as MongoDB, particularly with the handle whatever you throw at them. RECENT ADVANCES IN 0OSTGRE31, WHICH Although I personally prefer Ruby make storing and retrieving JSON for Web development, there’s no objects easy and efficient. doubt that Python is not only capable, If you’re interested in database but that it’s also easier for newcomers technology, a great book to try is to programming to understand. (I say Seven Databases in Seven Weeks, this after having taught two to three BY %RIC 2EDMOND AND *IM 7ILSON Python courses every month for the and published by the Pragmatic last five years.) Programmers. That book, as the An increasingly popular option is title describes, is something of a JavaScript, often using node.js, on the survey course in modern database assumption that it’s a good idea to technology, looking at a number of use the same language on both the different systems and comparing the client (that is, in the browser) and on advantages of each. the server. I haven’t yet found node.js

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 33

LJ244-Aug2014.indd 33 7/23/14 11:41 AM COLUMNS AT THE FORGE

to be a compelling framework, partly be used for Web applications and because of its use of the “reactor” have active, strong communities that pattern, and partly because I’m continue to grow. used to the comforts of other, more The bottom line is, if you already mature frameworks. But given the know a programming language, you huge number of people working should try to leverage that knowledge in JavaScript nowadays, and the and use it to dip your toes into Web understandable interest in reducing development. If you don’t already the number of languages needed feel comfortable with a language, I to engage in Web programming, I suggest trying Python or Ruby. They’re would expect JavaScript to become easy to learn, have large communities an increasingly viable option for and ecosystems, and have multiple Web development in general and for frameworks that can cater to needs newcomers to the field in particular. large and small. Of course, you may There are other options, as well, decide to go in a different direction— such as PHP, which is easy to learn and if you do, the odds are that and has a huge community. However, you’ll be just fine. Learning to be PHP has never impressed or excited a Web developer is generally more me as a language. That said, the fact difficult than learning to develop Web that WordPress now powers about applications in a new language or 10% of the Web indicates that PHP is with a new framework. not going away any time in the near future. Moreover, there are many Front End opportunities to extend, expand and The whole idea of the “front end” work within the WordPress ecosystem. in Web development has been One friend of mine has a very increasingly critical in the last decade. successful business as a WordPress Whereas it was once enough to e-commerce consultant. Given the size know about HTML, and then CSS, of that ecosystem, I expect that he the combination of HTML5, CSS, will have clients and work for about JavaScript and numerous APIs has as long as he would like. made front-end development a Depending on your development complex but vital part of any Web background, experience and taste, application stack. you might want to try something like That said, don’t feel that you need Go, Scala or Clojure, all of which can to understand everything at once when

34 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 34 7/23/14 11:41 AM COLUMNS AT THE FORGE

working on the front end. You will need and shows no signs of stopping. The to learn some HTML, as well as some GROWTH OF %MBERJS AND !NGULARJS basic CSS. And the odds are good that is encouraging and interesting. At you will need to learn some JavaScript the same time, I think these front- as well, although just how much you end frameworks are too complex will learn depends on how much client- FOR BEGINNING PROGRAMMERS J1UERY side work you will need to do and how although somewhat old-fashioned, sophisticated it will need to be. is still a great JavaScript library that Perhaps the biggest boon to makes it easier to manipulate the front-end development in the last DOM in a cross-platform way. few years has been the creation of JavaScript is a vital skill every FRONT END FRAMEWORKS SUCH AS :URB Web developer should have. Foundation and Twitter Bootstrap. The book Eloquent JavaScript, These frameworks make it possible to by Marijn Haverbeke and at focus on the design you want, taking http://eloquentjavascript.net, advantage of the fact that others have is a great introduction to the had to struggle with the same issues JavaScript language, although it before you. I have used Bootstrap on focuses on the language, rather a number of projects and have found than its use in Web development. that it saves me time, while allowing the design to look far better than So, Where Should You Start? otherwise would have been the case. The good news is that Web Bootstrap and Foundation don’t mean development is so diverse, it’s hard that you don’t have to learn CSS, but to make a bad or wrong choice. they dramatically reduce the amount Almost no matter what you choose, of CSS you need in order to get a site there is a community using those up and running. same technologies. JavaScript is also enjoying a surge If you’re a complete newbie, I’d in popularity, partly because Web suggest trying Python, along with applications are becoming more THE &LASK FRAMEWORK THE 0OSTGRE31, sophisticated, and partly because database and the Bootstrap front-end everyone has a JavaScript development FRAMEWORK ALONG WITH J1UERY environment—namely a Web browser. If you feel very comfortable with The number of modules and packages object-oriented programming, or feel for JavaScript is extraordinarily large like you want a bit more flexibility in

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 35

LJ244-Aug2014.indd 35 7/23/14 11:41 AM COLUMNS AT THE FORGE

your code style, you might take a look at of interesting projects for such Ruby with the Sinatra framework—and developers, continues to surge. ALSO 0OSTGRE31, "OOTSTRAP AND J1UERY It doesn’t matter very much what Finally, WordPress development is language or technology you learn; the a good way to get your feet wet in important thing is to learn the Web its own ecosystem. I’m not sure if I’d mindset and try to figure out what say that WordPress is the paradigm niche of this growing industry you of beautiful software development, want to be a part of or benefit from.Q but it’s hard to argue with the market share and plugin ecosystem that has Reuven M. Lerner is a Web developer, consultant and trainer. grown up around this very successful, He recently completed his PhD in Learning Sciences from very user-friendly system. Northwestern University. You can read his blog, Twitter feed and newsletter at http://lerner.co.il. Reuven lives with his wife Conclusion and three children in Modi’in, Israel. It sometimes seems as if all software development is becoming Web development. That’s obviously an Send comments or feedback via exaggeration, but the demand for http://www.linuxjournal.com/contact Web developers, and the number or to [email protected].

Resources

The Python language home page is at http://python.org. The site includes not only software downloads, but also extensive documentation and tutorials.

The Flask home page is at http://flask.pocoo.org. This includes links to the code, documentation, tutorials, examples and an official list of Flask extensions. The Django framework is at https://www.djangoproject.com, also with extensive documentation and code samples.

The home page for PostgreSQL is at http://postgresql.org, and the home page for jQuery is at http://jquery.org.

If you’re interested in the Ruby programming language, go to http://ruby-lang.org. The Sinatra framework is at http://www.sinatrarb.com. The Ruby on Rails framework is at http://rubyonrails.org, including code, tutorials and resources.

36 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 36 7/23/14 11:41 AM /code business "success" do needs :speed needs :scale needs :consistency provider 'getchef.com' end

getchef.com

LJ244-Aug2014.indd 37 7/23/14 11:41 AM COLUMNS WORK THE SHELL Days Between DAVE TAYLOR Dates: the Counting Dave continues developing a script to calculate how many days ago a specific date was—and finds that there are bugs!

In my last article, we began running the completed script at an exploration of date math by 11:59pm will offer a different validating a given date specified result from at 12:01am, just a few by the user, then explored how seconds later. GNU date offers some slick math To start, let’s grab the current capabilities, but has some inherent month, day and year. There’s a neat limitations, the most notable of eval trick we can use to do this: which is that it isn’t on 100% of all

Linux and UNIX systems. eval $(date "+thismon=%m;thisday=%d;thisyear=%Y;dayofyear=%j") So here, let’s continue the development by adding the date This instantiates thismon to the math itself. For this script, the goal current month, thisday to the is to answer the question of how current day of the month, thisyear many days have transpired between to the current year and dayofyear the specified date and the current to the numeric day number into date. The necessary algorithm has the year of the current day, all in a obvious applications in the broader single line—neat. “date A to date B” puzzle, but let’s The user-specified starting date defer that for another time. already is broken down into day of Remember also that we’re talking month, month of year and year, so about dates, not time, so it’s not once the current month, day and COUNTING  HOUR INCREMENTS BUT year are identified, there are four simply the number of days. So parts to the equation:

38 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 38 7/23/14 11:41 AM COLUMNS WORK THE SHELL

1. How many years have transpired * 365. basedays=0

fi

2. How many days were left in the echo "$basedays days transpired between end of $startyear \

starting year. and beginning of this year"

3. How many days have transpired Now that isn’t taking into account since the beginning of this year. leap years, is it? So instead, let’s try doing it differently to tap into the  #OMPENSATE FOR LEAP YEARS IN THE isleap function too: interim period.

if [ $(( $thisyear - $startyear )) -gt 2 ] ; then

The first test demonstrates the # loop from year to year, counting years and adding +1

nuances in this calculation because if # for leaps as needed

we’re calculating the number of days theyear=$startyear

since, say, Nov 15, 1996, and today, while [ $theyear -ne $thisyear ] ; do

*UN   WE DONT WANT TO COUNT isleap $theyear

 n BECAUSE BOTH THE if [ -n "$leapyear" ] ; then

start and end years will be wrong. In elapsed=$(( $elapsed + 1 ))

fact, better math is to use this formula: echo "(adding 1 day to account for $theyear being a leap)"

fi

365 * (thisyear – starting year – 2) elapsed=$(( $elapsed + 365 ))

theyear=$(( $theyear + 1 ))

But, that’s not right either. What done

happens if the starting date is Jun fi   AND THE END DATE IS *UN   4HAT SHOULD THEN PRODUCE A Fast and easy. When I run this zero value, as it also would if the block against 1993 as a starting start date was Mar 1, 2013, even year, it informs me: THOUGH n (ERES MY

first stab at this chunk of code: (adding 1 day to account for 1996 being a leap year)

(adding 1 day to account for 2000 being a leap year)

if [ $(( $thisyear - $startyear )) -gt 2 ] ; then (adding 1 day to account for 2004 being a leap year)

elapsed=$(( $thisyear - $startyear - 2 )) (adding 1 day to account for 2008 being a leap year)

basedays=$(( elapsed * 365 )) (adding 1 day to account for 2012 being a leap year)

else 7670 days transpired between end of 1993 and beginning of this year

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 39

LJ244-Aug2014.indd 39 7/23/14 11:41 AM COLUMNS WORK THE SHELL

For the second step in the algorithm, calculating the number of days from the specified starting date to the end of that particular year, well, that too has an edge case of it being the current year.

For the second step in the algorithm, 4|6|9|11 ) dim=30 ;; calculating the number of days from 2 ) dim=29 ;; # is it a leap year? the specified starting date to the * ) dim=-1 ;; # unknown month end of that particular year, well, that esac too has an edge case of it being the current year. If not, it’s a calculation A logical approach would be that can be done by summing up the to turn this into a short function days of each of the previous months that can do double duty. That’s plus the number of days into the easily done by wrapping it in month of the starting date, then function daysInMonth { and }. subtracting that from the total days With that, it’s a matter of in that particular year (since we have stepping through the remaining to factor in leap years, which means months, although be alert for the we have to consider whether the date leap year calculation we need to do occurs before or after Feb 29), or we IF MONTH   &EB  4HE PROGRAM HAS can do the same basic equation, but February always having 29 days, so sum up the days after the specified if it isn’t a leap year, we need to date. In the latter case, we can be subtract one day to compensate: smart about the leap day by tracking

whether February is included. if [ $thisyear -ne $startyear ] ; then

The basic code assumes we have monthsleft=$(( $startmon + 1 ))

an array of days-per-month for each daysleftinyear=0

of the 12 months or some other way while [ $monthsleft -le 12 ] ; do

to calculate that value. In fact, the if [ $monthsleft -eq 2 ] ; then # February. leapyear?

original script included this snippet: isleap $startyear

if [ -n "$leapyear" ] ; then

case $mon in daysleftinyear=$(( $daysleftinyear + 1 )) # feb 29!

1|3|5|7|8|10|12 ) dim=31 ;; # most common value fi

40 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 40 7/23/14 11:41 AM COLUMNS WORK THE SHELL

fi the case that we’re in the same year,

daysInMonth $monthsleft as you’ll see, we can use “day of year”

daysleftinyear=$(( $daysleftinyear + $dim )) and calculate things differently.

monthsleft=$(( $monthsleft + 1 )) Here’s the block of code:

done

else if [ $startyear -ne $thisyear -a $startmon -ne $thismon ] ; then

daysleftinyear=0 # same year so no calculation needed daysInMonth $startmon

fi if [ $startmon -eq 2 ] ; then # edge case: February

isleap $startyear

The last part is to calculate how if [ -z "$leapyear" ] ; then

many days are left in the starting date’s dim=$(( $dim - 1 )) # dim = days in month

month, again worrying about those fi

pesky leap years. This is only necessary fi

if the start year is different from the daysleftinmon=$(( $dim - $startday ))

current year and the start month is echo "calculated $daysleftinmon days left in the startmon"

different from the current month. In fi

LJ244-Aug2014.indd 41 7/23/14 11:41 AM COLUMNS WORK THE SHELL

Hmm...365*10 = 3650. Add a few days for the leap year, and that seems wrong, doesn’t it?

We have a few useful variables (MM    !DD A that now need to be added to the few days for the leap year, and that “elapsed” variable: daysleftinyear seems wrong, doesn’t it? Like it’s is how many days were left in the one year too many or something? start year, and dayofyear is the Worse, look what happens if I go current day number in the current back exactly two years ago: year (June 3, for example, is day

  &OR CLARITY ) ADD IT LIKE THIS $ sh daysago.sh 6 3 2012

The date you specified -- 6-3-2012 -- is valid. Continuing...

echo calculated $daysleftinyear days left in the specified year 0 days transpired between end of 2012 and beginning of this year

elapsed=$(( $elapsed + daysleftinyear )) calculated 184 days left in the specified year

# and, finally, the number of days into the current year Calculated that 6/3/2012 was 338 days ago.

elapsed=$(( $elapsed + $dayofyear ))

echo "Calculated that $startmon/$startday/$startyear \ Something is definitely wrong.

was $elapsed days ago." That should be 2*365. But it’s not. Bah. Phooey. In my next article, With that, let’s test the script with a we’ll dig in and try to figure out few different inputs: what’s wrong!Q

$ sh daysago.sh 8 3 1980 Dave Taylor has been hacking shell scripts for more than 30

The date you specified -- 8-3-1980 -- is valid. Continuing... years. Really. He’s the author of the popular Wicked Cool Shell

12419 days transpired between end of 1980 and beginning of this year Scripts and can be found on Twitter as @DaveTaylor and more

calculated 28 days left in the startmon generally at his tech site http://www.AskDaveTaylor.com.

calculated 122 days left in the specified year

Calculated that 8/3/1980 was 12695 days ago.

$ sh daysago.sh 6 3 2004

The date you specified -- 6-3-2004 -- is valid. Continuing...

3653 days transpired between end of 2004 and beginning of this year Send comments or feedback via

calculated 184 days left in the specified year http://www.linuxjournal.com/contact

Calculated that 6/3/2004 was 3991 days ago. or to [email protected].

42 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 42 7/23/14 11:41 AM Linux Journal_Layout 1 6/2/14 12:01 PM Page 1

The Best SharePoint Training in the World returns to Boston! Choose from more than 80 classes and tutorials!

September 16-19, 2014 “I really enjoyed it. I can hardly wait to get back to work and start using what I learned. I will encourage employees and The Boston Park Plaza Hotel & Towers co-workers to attend future SPTechCons. The conference had great speakers with relevant subjects, and the whole thing was well organized.” Bolster your career by —Greg Long, Infrastructure Development Manager, ITG, Inc. becoming a SharePoint Master!

“I prefer SPTechCon over Microsoft’s SharePoint Conference • Learn from SharePoint experts, including dozens of in Vegas. I’m definitely goinggoing to tell others to go.” SharePoint MVPs and Certified SharePoint Professionals —Ray Ranson, Senior Architect, RSUI —Ray Ranson, Senior Architect, RSUI • Master document management • Study SharePoint governance • Find out about SharePoint 2013 • Learn how to create applications for SharePoint that solve real business problems

• Exchange SharePoint tips and tricks with colleagues • Test-drive SharePoint solutions in the Exhibit Hall If you or your team needs Microsoft SharePoint training, come to SPTechCon Boston!

Register Early and SAVE! www.sptechcon.com

SPTechCon™ is a trademark of BZ Media LLC. SharePoint® is a registered trademark of Microsoft. A BZ Media Event @SPTechCon

LJ244-Aug2014.indd 43 7/23/14 11:41 AM

COLUMNS HACK AND /

Not So KYLE RANKIN Dynamic Updates Kyle covers some of the headaches and gotchas when deploying servers to cloud environments that hand out completely random IPs.

Typically when a network is under I’ve leaned heavily on dynamic DNS my control, I like my servers to have UPDATES WITHIN MY %# ENVIRONMENTS static IPs. Whether the IPs are truly When a host starts for the first static (hard-coded into network time and gets configured, or any configuration files on the host) or time the IP changes, the host will whether I configure a DHCP server update internal DNS servers with to make static assignments, it’s far the new IP. Generally this approach more convenient when you know a has worked well for me, but it has server always will have the same IP. one complication. If I controlled the Unfortunately, in the default Amazon DHCP server, I would configure it with %# ENVIRONMENT YOU DONT HAVE ANY the IP addresses of my DNS servers. say over your IP address. When you Since Amazon controls DHCP, I have SPAWN A SERVER IN %# !MAZONS $(#0 to configure my hosts to override server hands out a somewhat random the DNS servers they get from DHCP IP address. The server will maintain that with mine. I use the ISC DHCP client, IP address even through reboots as long so that means adding three lines to as the host isn’t shut down. If you halt the /etc/dhcp/dhclient.conf file on a the machine, the next time it comes up, Debian-based system: it likely will be on a different piece of

hardware and will have a new IP. supersede domain-name "example.com";

supersede domain-search "dev.example.com", "example.com";

dhclient Overrides supersede domain-name-servers 10.34.56.78, 10.34.56.79; To deal with this unpredictable IP address situation, through the years, With those options, once the

44 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 44 7/23/14 11:41 AM COLUMNS HACK AND /

network has been restarted (or the though it returns multiple IPs. If you machine reboots), these settings will use ping, you can test this and see that end up in my /etc/resolv.conf: it always pings the host you specify in sortlist, even if a dig or nslookup domain example.com returns multiple IPs in random order. search dev.example.com. example.com In the event that the first host goes nameserver 10.34.56.78 down, if your client has proper support nameserver 10.34.56.79 for multiple A records, it will fail over to the next host in the list. I’ve even gone so far as to add a script under /etc/dhcp/ dhclient Is Not So Dynamic dhclient-exit-hooks.d/ that fires This method of wrangling a bit off after I get a new lease. For of order into such a dynamic fault tolerance, I have multiple ENVIRONMENT AS %# HAS WORKED puppetmasters, and if you were to well for me, overall. That said, it perform a DNS query for the puppet isn’t without a few complications. hostname, you would get back The main challenge with a system multiple IPs. These exit hook scripts like this is that the IPs of my DNS perform a DNS query to try to identify servers themselves might change. the puppetmaster that is closest to No problem, you might say. Since it and adds a little-known setting to I control my dhclient.conf with a resolv.conf called sortlist. The sortlist configuration management system, setting tells your resolver that in the I can just push out the new case when a query returns multiple dhclient.conf. The only problem with IPs to favor the specific IP or subnets this approach is that dhclient does not in this line. So for instance, if the offer any way that I have been able puppetmaster I want to use has an to find to reload the dhclient.conf IP of 10.72.52.100, I would add the configuration file without restarting following line to my resolv.conf: dhclient itself (which means bouncing the network). See, if you controlled sortlist 10.72.52.100/255.255.255.255 the DHCP server, you could update the DHCP server’s DNS settings, and The next time I query the hostname it would push out to clients when that returns multiple A records, it they ask for their next lease. In my always will favor this IP first even case, a DNS server IP change meant

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 45

LJ244-Aug2014.indd 45 7/23/14 11:41 AM COLUMNS HACK AND /

generating a network blip throughout its lease within the next few hours, so the entire environment. the network needed to be bounced on I discovered this requirement the every single host to accept the new hard way. I had respawned a DNS dhclient.conf. My team scrambled to server and pushed out the new IP stage the change on groups of servers to the dhclient.conf on all of my at a time. The real problem was servers. As a belt-and-suspenders less that dhclient changes required approach, I also made sure that the a network blip, but more that the /etc/resolv.conf file was updated by network blip was more like an outage my configuration management system that lasted a few seconds. We have to show the new IP. The change database clusters that don’t take pushed out and everything looked kindly to the network being removed. great, so I shut down the DNS server. At least, they view it (rightly so) as a Shortly after that, disaster struck. failure on the host and immediately I started noticing that a host would trigger failover and recovery of the have internal health checks time out; the database cluster. The hosts seemed host became sluggish and unresponsive, to be taking way longer than they and long after my resolv.conf change should to bounce their network, were should have made it to the host, it triggering cluster failovers, and in seemed it was updating the file again. some cases, required some manual When I examined the resolv.conf on intervention to fix things. faulty systems, I noticed it had the old Fortunately for us, this issue affected IP scheme configured even though the only the development environment, DNS servers with that information were but we needed to respawn DNS servers long gone. What I eventually realized in production as well and definitely was that even though I updated couldn’t handle that kind of disruption dhclient.conf, the dhclient script itself there. I started researching the never grabbed those changes, so after problem and after confirming that there a few hours when it renewed its lease, was no way to update dhclient.conf it overwrote resolv.conf with the old without bouncing the network, I DNS IPs it had configured! turned to why it took so long to restart the network. My dhclient-exit-hook The Blip Heard Round the World script was the smoking gun. Inside the I realized that basically every host in script, I slept for five seconds to make this environment was going to renew sure the network was up and then

46 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 46 7/23/14 11:41 AM COLUMNS HACK AND /

performed a dig request. This meant exit hook, I was able to bounce the that when restarting the network, the network on any host without any ill DNS queries configured for the old IPs effects. The final proof was when I would time out and cause the host to pushed changes to DNS server IPs in pause before the network was up. The production with no issues.Q fix was for me to replace the sleep and dig query with a template containing Kyle Rankin is a Sr. Systems Administrator in the San Francisco a simple echo to append my sortlist Bay Area and the author of a number of books, including The entry to resolv.conf. My configuration Official Server Book, Knoppix Hacks and Ubuntu Hacks. management system would do the He is currently the president of the North Bay Linux Users’ Group. DNS query itself and update the template. With the new, faster script in place, I saw that my network Send comments or feedback via restarts barely caused a network http://www.linuxjournal.com/contact blip at all. Once I deployed that new or to [email protected].

LINUX JOURNAL on your e-Reader

Customized e-Reader editions Kindle and Nook editions FREE for Subscribers now available

LEARN MORE

LJ244-Aug2014.indd 47 7/23/14 11:41 AM COLUMNS THE OPEN-SOURCE CLASSROOM

First Health, SHAWN POWERS Now Recreation What’s more fun than working with Linux? Playing with Linux!

In my last article, I talked about you can’t go outside. Sometimes the various techie ways I personally it’s too sunny, and if you go outside manage the health and exercise you’ll burn. And sometimes, you’re issues in my life. This time, I want to an insomniac, up all night with talk about nerdy entertainment, and nothing to comfort you but the pale how technology influences the fun blue glow of a monitor. Whatever parts of my day-to-day existence. Not excuse you need to tell yourself, that health and exercise aren’t fun— gaming on Linux is better than it’s but, you know what I mean. Let’s ever been (Figure 1). consider these two articles a “summer Steam: Few things have helped vacation” from the server room and the scene as much as command line. For those of you in the folks at Valve providing a native the southern hemisphere, it can be an Linux version of the Steam platform. extended winter break. For my next No, not all games are available for article, I’ll put my virtual work clothes Linux, but there is a surprisingly on and teach some Linux, but here it’s large number that is. Whether you about making technology serve our like to shoot zombies with the entertainment whims. Left-4-Dead franchise or prefer to play Indie games, which often have Games incredible gameplay while sacrificing Let’s face it, sometimes it rains and big-budget special effects, Steam

Few things have helped the Linux gaming scene as much as the folks at Valve providing a native Linux version of the Steam platform.

48 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 48 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

Figure 1. GT Racing has awesome graphics, incredible gameplay and is fairly easy to play.

is a resource for tons of awesome products every day. In this particular games. Download the client and case, however, I’m referring to phones start building your library now: and tablets. Although there certainly http://www.steampowered.com. are epic games available for Android, I (If you don’t like Steam, check out find the quick and challenging games Desura, which is a similar concept: are the most fun. While I personally http://www.desura.com.) never understood the draw of games Android: Just saying “Android” like Flappy Bird, I will admit to hours isn’t really specific enough anymore. lost invested into Google’s mobile operating system is Angry Birds and Candy Crush (Figure getting embedded into more and more 2). In fact, Android is becoming such

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 49

LJ244-Aug2014.indd 49 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

Figure 2. Perhaps the birds are angry that we keep forcing them to hurl themselves at pigs.

a gaming platform, many games are and playing Legend of Zelda with a being cross-compiled for PCs and boxy controller? Well, even if your Android (https://play.google.com/ earliest console gaming memories are store/apps/category/GAME). of Wii Bowling, the latest Android- Ouya, Fire TV and Roku: powered gaming devices should be Remember plugging your Atari reminiscent of those old days, with a 2600 in to the black-and-white modern twist. Gaming and streaming television and playing Pac-Man with entertainment are starting to merge a single-button joystick? No? Fine. together as the platforms mature, Do you remember plugging your and devices like the Roku are proof. Nintendo in to the living-room TV Whether you want to stream old

50 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 50 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

You even can make individual videos available off-line for those rainy camping trips out of cell tower range.

episodes of Star Trek or fling angry kill the time. Healthy? Probably not, birds at naughty pigs, these new console but that was last article’s topic; here devices are easy to use and fun to it’s all about fun. And personally, I play with (http://www.ouya.com, love to watch the TV! http://amazon.com/firetv and Plex: I’ve written in length http://www.roku.com). about Plex and Plexmediaserver in Humble Bundle: I’ve mentioned past issues, so I won’t belabor the the Humble Bundle folks before. point much more. It’s impossible It’s a great organization that sells to talk about Linux-based video- Indie products and raises money watching without bringing up for charities. As it happens, it also one of my favorite consumption supports Linux and Android platforms methods though, so here it is. with most of its game releases. Be Plex is awesome. You can watch sure to read closely, however, because your personal video collection on although the Humble Bundle folks a plane, in a car, in a box, with a try to find developers who support fox—anywhere you happen to be, cross-platform gaming, sometimes your video collection is available to the “bundles” are Windows-only. you. You even can make individual Because there’s typically a new videos available off-line for those bundle every few weeks, it’s not rainy camping trips out of cell tower usually a big deal, however. Just be range. My only remaining frustration careful before you click. with Plex? It doesn’t support playlists. Thankfully, that’s in the works for Video future versions (http://www.plex.tv). I already used the rain excuse, For playback on your own network, and the insomnia excuse is just it’s hard to beat the XBMC interface, depressing, but whatever your which is what I still use on our TVs reason for being inside, watching the (http://www.xbmc.org). television is a time-honored way to Roku and Fire TV: I know, I

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 51

LJ244-Aug2014.indd 51 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

Figure 3. The Amazon Fire TV is a media streamer and a low-end gaming system. The interface is sleek, and if you’re an Amazon user, it will be convenient.

mentioned these in the gaming allow for a number of third-party section, but gaming is really a apps. Both devices support Netflix and secondary function. These are both Hulu, and have a native Plex app! If Android-based streaming devices. you want Plex on a television, it’s hard The Roku has a huge market share, to beat a Roku or FireTV (Figure 3). which is interesting because it doesn’t Backyard Drive-in: It might actually produce or stream content of sound cheesy, but if you’re a little its own. I find that refreshing, because adventurous, an outdoor movie it means the platform doesn’t favor screening is incredibly fun. Make sure one video source over another. The there are blankets for the ground, or Amazon Fire TV, on the other hand, some chairs, and provide bug spray does favor Amazon products. This along with the popcorn. I actually isn’t shocking, but it does admittedly recommend using a yard fogger to

52 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 52 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

Figure 4. Outdoor theaters are just cool! (Photo courtesy of kelemvor: http://backyardtheater.com/forums/index.php?action=profile;u=181.)

keep the bugs at bay. The tech side movie. They almost never last through is fairly simple. Find a light-colored the whole movie, but it’s fun for the building or hang up a white bed WHOLE FAMILY &IGURE   sheet, and use a projector to create your outdoor “theater”. It helps to Music have some good speakers, and tons of Streaming Music: We’ve gotten to popcorn. I find 1980s action movies the point with music that finding ways or cheesy B-rate horror films to be to get songs is super simple. Tools like the best choices, but your tastes will Google Music’s matching program (or likely vary. The fun part for the kids iTunes “Match” subscription service) is waiting until after dark to start the mean our music is always available

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 53

LJ244-Aug2014.indd 53 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

to us from the cloud. Oddly, I don’t on my likes and dislikes, they pick own very much music, because songs I’ll probably enjoy. And, they’re I’m fickle and switch tastes often. usually correct. Like I mentioned, For me, the streaming services like there are tons of platforms for Pandora are ideal, because based music. Rhapsody, Spotify, Last.FM,

Figure 5. My first mobile speaker attempt is a bit sad. Still, it works in a pinch. The next version will be much nicer!

54 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 54 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

Pandora, Google Music—whatever folks at D-Link sent me their newest style of consumption appeals to your model (the DCH-M225), and I’m going particular taste is available. to try to make a proper weekend Music Hardware: I know, you’re project out of building the perfect thinking, “Shawn, ’music hardware’ portable jam center. If it works, I’ll is called ’speakers’”, but I mean more write about it in a future issue. If it than just speakers. For instance, I fails, I’ll probably post sad pictures on like to listen to audiobooks in the our Twitter feed (Figure 5). shower. It means that a good book will sometimes result in running out Books, Mmmm, Books of hot water, but I still enjoy listening I love reading. This is probably not a to them nevertheless. I tried a wide surprise, since I’m a writer, a nerd, variety of Bluetooth-enabled shower socially awkward and get a sunburn speakers, and quite frankly, they from thinking warm thoughts. I’ve all stink. I’m hoping someone has spent a lot of time indoors, and a found one that is loud enough for lot of that time has been in faraway old deaf people like me, but so far, I places with aliens and trolls. When have a drawer full of tinny-sounding I was younger, I had to brave the Bluetooth devices with suction cups. outdoors long enough to walk the If you know of a good Bluetooth couple miles to the local library. Now, speaker designed for the shower, I have an endless supply of alternate please let me know! I’ll be sure to realities at the literal tips of my write about it in a future issue and fingers. And the eBook revolution give you praise and credit! has only just begun! Something I’ve been working on Audible: I must admit, my hectic more recently is a portable speaker lifestyle means that most of my system for the backyard. I could open reading is done while I’m driving my the window and jam a speaker into it, kids from one appointment or sporting but I really want to control the music event to the next. (My kids, unlike from my phone. My current solution is their father, are fairly athletic—I don’t to cram some powered speakers into understand genetics.) Since reading a laundry basket, and connect it to a book while driving is illegal and something like the D-Link WiFi Audio a poor example for my kids, I tend %XTENDER SO ) CAN STREAM WIRELESSLY TO to listen to books more than read wherever I set the basket. In fact, the them. Audible is a great way to get

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 55

LJ244-Aug2014.indd 55 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

the most recent books delivered buy both versions, so you can read seamlessly. The Android app will sync at stoplights if you really prefer the your spot with a Kindle eBook if you written word. I don’t suggest that

Figure 6. The Overdrive app is really slick, but is only as useful as the selection your library offers. (Photo courtesy of http://overdrive.com.)

56 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 56 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

though, as it seems dangerous! access to a number of audiobooks Non-Audible Audiobooks: at a time. The Overdrive app is the The only downside of audiobooks standard method used to access those is the cost. Mind you, the cost is books. Libraries still are sorting out understandable, because the author, DRM issues, and some books are narrator and entire production crew available only on Windows-compatible deserve to be paid for their work, listening devices. That really annoys but it means that instead of $7 for a me, so I tend to find ways to strip the paperback, it’s $25 for a performance. DRM from the books and listen to There are other audiobook resellers, them on whatever darn device I but the selections are never as good want (generally an Android device as Audible, and the prices aren’t running the SmartAudiobook Player much better. Thankfully, there’s http://www.linuxjournal.com/ another option, depending on where content/android-candy-smart- you live—the library. audiobook-player). Again, there Unfortunately, the availability of are moral implications. Nevertheless, audiobooks varies widely from library the library is a great resource for to library. When I lived in a city, my audiobooks. Sometimes, the selection local library had more audiobooks IS AMAZING %VEN IF IT ISNT CONTACT than I ever could listen to, plus, the librarians—sometimes they have a the librarians almost always would budget for ordering more books, but buy a book if I requested they add they’re just waiting for requests. Find it to their library! Now that we’re the app at http://omc.overdrive.com, in a small town, the local library and ask at your local library about its doesn’t have the budget to carry a digital options (Figure 6). large selection. Your library might be able to import physical copies Book Books of audiobooks for you, but the on- I know, for many of you, nothing line digital stuff is really the nicest. ever will replace dead tree pulp and If you have friends or relatives in a ink. I still painfully remember the big city who don’t use their local YEARS OF ,ETTERS TO THE %DITOR SHARING library, perhaps you could work out everyone’s frustration when Linux a deal with them. I’ll leave the moral Journal switched to digital. Thankfully, implications up to you to sort out. eBooks and their reading devices Generally with a library, you get free continue to improve year after year.

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 57

LJ244-Aug2014.indd 57 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

Yes, the same folks who provide the awesome selection of games on a regular basis now also provide eBook bundles.

Now, like with music, there are so it wasn’t until I started buying eBook many ways to get and read eBooks, it bundles from Humble Bundle that I had can be overwhelming. to rethink my eBook collection. The Standard Stores: Amazon Humble Bundle: Yes, the same (Kindle), Barnes & Noble (Nook), folks who provide the awesome Apple (iDevices), Google Play selection of games on a regular basis (Android devices), plus a ton of smaller now also provide eBook bundles. The companies sell eBooks. With most bundles usually contain books from companies, the idea is to lock you in to authors I love, and I really like to their ecosystem, so you always will buy support the charities by purchasing from them instead of bargain shopping books. You pay what you want, and for the best price. This is both good the money gets split among various and bad. Companies like Amazon make charities along with the author. the purchasing and reading experience (As it happens, Linux users are so seamless and pain-free that it’s hard always the top contributors per to go elsewhere, even if a book might capita. Go freedom!) be less expensive from a competitor. These DRM-free eBooks are You’re paying for convenience along just downloads and aren’t part with the book itself. of any cloud ecosystem. That meant It’s certainly possible to install all the I had to come up with some way major apps on your Android device to consolidate my eBook library and read a book on whatever platform in one place. Thankfully, Calibre you could buy it for the cheapest, but (http://www.linuxjournal.com/ most of us tend to like a consistent content/calibre-cloud) is a great tool interface and don’t want our book for managing an eBook collection. selections splintered across various Yes, it means stripping some DRM off cloud accounts. I’m horribly guilty of my Amazon books, but having all my this, and I tend to buy all my books books in one “library” is like a salve from one particular vendor. In fact, for my OCD.

58 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 58 7/23/14 11:42 AM COLUMNS THE OPEN-SOURCE CLASSROOM

The Overdrive Library Again: household problem with a Raspberry Remember the Overdrive program Pi (the digital fireplace in my family for listening to audiobooks from room, for instance). And it’s all I can the library? Well it also does eBooks do not to quit writing this article so and includes an app for reading the I can go build my outdoor, mobile, library-loaned eBooks you check out. wireless speaker system for streaming I do think it allows for an unfortunate music in the backyard. side effect in that going to the library Whatever your favorite Linux is no longer necessary for reading adventure might be, hopefully some books, but that’s just nostalgia on of the things I discussed here make my part. I’m thrilled libraries are those adventures more fun. At the evolving, and I urge you to check out very least, I hope you check out your local library’s digital collection! your local library to see what sort Oyster: Finally, I leave you with of digital offerings it provides. It’s Oyster. You may have read about awesome to see an establishment as it in the UpFront section of this old as the library move into the next ISSUE AS IT WON THIS MONTHS %DITORS phase of free knowledge sharing. Choice award. Oyster is basically Libraries understood the idea of open the Netflix of the book world. With source before the term even meant a $9.95 subscription and an app on SOMETHING %NJOY THE REST OF YOUR your phone and/or tablet, you get summer (or winter!) everyone, and unlimited access to more than a get ready for next issue, when we’re half-million books! Read about it in back in the classroom.Q the UpFront section, or surf over to http://www.oysterbooks.com for Shawn Powers is the Associate Editor for Linux Journal. more details and a free 30-day trial. He’s also the Gadget Guy for LinuxJournal.com, and he has an interesting collection of vintage Garfield coffee mugs. Don’t let Build Your Own Adventure his silly hairdo fool you, he’s a pretty ordinary guy and can be Honestly, after all the years of reached via e-mail at [email protected]. Or, swing by working as a sysadmin, writing for the #linuxjournal IRC channel on Freenode.net. Linux Journal and just being a geek, my favorite Linux pastime is learning. I love to build projects like BirdCam Send comments or feedback via (http://birds.brainofshawn.com). http://www.linuxjournal.com/contact I’m excited every time I can solve a or to [email protected].

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 59

LJ244-Aug2014.indd 59 7/23/14 11:42 AM NEW PRODUCTS

Bitwig Studio Bitwig recently announced innovations complementary to Bitwig Studio, a dynamic software solution for music creation and performance to realize one’s musical ideas at every stage of production. The first innovation is the new Community Controllers section of the application’s Web site, which is dedicated to Bitwig Studio’s capabilities for deep integration with just about any hardware controller. This integration is possible due to the Bitwig Open Conroller API, an open-source JavaScript platform allowing virtually anyone to create, share and collaborate on powerful controller scripts. A wide range of controllers already are available, ranging from those containing only a few knobs or buttons to elaborate keyboards with motorized faders, colored pads, ROTARY ENCODERS WITH ,%$S AND COLOR DISPLAYS ! RELATED INNOVATION IS THE NEW #OMMUNITY Controllers Library, an archive of the latest controller scripts from the Bitwig Community. Bitwig users already have begun hacking, modifying and creating control scripts from scratch, collaborating with others and sharing their work. The two repositories are destined to open a wide range of new integration possibilities with Bitwig Studio. http://www.bitwig.com

Glacier Computer Fusion 7 Glacier Computer believes that its new Fusion 7 Rugged Android Tablet is the device that will cause the industrial marketplace to embrace the Android platform and all of its advantages fully. The Fusion 7 extends the Glacier Computer product line of rugged industrial PCs—including rugged tablets, portable hand-held devices and fixed mounted data collection computers— that typically are used in harsh industrial environments where a standard PC cannot survive. Glacier states that the Fusion 7 is compact, light and feature-rich, enabling businesses and their mobile users to add efficiencies throughout the operation while providing a capital asset with an extended useful life and a superior ROI. The Fusion 7 combines the advanced power management and memory management capabilities of Android enabling more than one million applications to run on the typically rugged Glacier device. To ease transition to the new OS, Glacier is collaborating with The Allen Group and SOTI, which will enable broader adoption of the Android OS within the traditional Windows environments of the industrial marketplace. http://www.glaciercomputer.com

60 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 60 7/23/14 11:42 AM NEW PRODUCTS

CloudMask’s Secure Data Masking for Governments

Governments have unique needs and security requirements, and any loss of confidentiality in government affairs can have far-reaching consequences. To meet these needs, CloudMask has unveiled a Secure Data Masking for Governments solution. The new offering brings the security, performance and scalability of the enterprise-class SaaS CloudMask solution to fulfill the requirements of governments. CloudMask elaborates that its advanced masking technology hNEUTRALIZES THE RISKS OF DATA BREACHES BY ENABLING USERS TO APPLY END TO END %% ENCRYPTION AND tokenization to their data. This occurs at the moment of creation, and data remains protected throughout its lifecycle. This is a very different approach from existing solutions that encrypt data while it is in transit and/or at-storage, while leaving it exposed during server processing.” No VPN, encryption gateway or any other hardware encryption devices are required. The CloudMask solution has been evaluated by the Canadian Federal Government for integration with its security infrastructure and currently is going through Common Criteria Certification to meet the security certification required to operate with governments in 26 countries. http://www.cloudmask.com

BitRock’s InstallBuilder No matter what OS you throw at it, the BitRock’s InstallBuilder packaging and deployment platform can help you build a cross-platform installer for it. InstallBuilder, now in version 9, is a development tool for creating cross-platform installers, native packages, DVDs and CD-ROMs. It provides an intuitive graphical development environment, making it easy to learn and use, and an XML-based project format that allows for collaborative development, version control and integration with automated build and test environments. From one project file and build environment, developers can build installers for Linux, Windows, Mac OS X, Solaris, FreeBSD, HP-UX, AIX, IRIX, IBM iSeries and pSeries and other platforms. The latest version enables the creation of cross-platform installers up to 25% faster and 20% smaller than previous versions. HTML license support, A FEATURE PREVIOUSLY AVAILABLE ONLY FOR 1T IS NOW AVAILABLE FOR ALL )NSTALL"UILDER USERS http://installbuilder.bitrock.com

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 61

LJ244-Aug2014.indd 61 7/23/14 11:42 AM NEW PRODUCTS

Omnibond Systems’ acilos

What is the most logical anagram of “acilos”? It’s “social”, of course, and social media is what Omnibond Systems’ acilos is all about. More precisely, acilos is a so-called personal social-media valet, a personal Web application that helps users aggregate, filter, customize and send updates to social-media feeds from Twitter, Facebook, LinkedIn and Instagram—all in a single, simple interface. The free and open-source acilos grew out of an internal need at Omnibond to deal with the sheer volume of social-media content. The resulting tool was acilos, and due to Omnibond’s commitment to the Open Source community, the company decided to share acilos with the rest of the world. Now acilos’ source is fully accessible and open for contributors to help develop the next levels of personal social interaction and to add their preferred social-media accounts. acilos is available at GitHub, Amazon Web Services and the application’s Web site. http://www.acilos.com

Jordan Tigani and Siddartha Naidu’s Google BigQuery Analytics (Wiley)

$O YOU WANT TO BE AN EXPERT IN 'OOGLE "IG1UERY AND THE "IG1UERY !0) Your tutors to reach that goal are authors Jordan Tigani and Siddartha Naidu, who have penned the new Wiley book title Google BigQuery Analytics 4HE BOOKS CONTENTS DEMONSTRATE HOW TO USE "IG1UERY effectively, avoid common mistakes and execute sophisticated queries against large data sets. Targeted at business and data analysts who want the latest tips on running complex queries and writing code to COMMUNICATE WITH THE "IG1UERY !0) THE BOOK USES REAL WORLD EXAMPLES to demonstrate current best practices and techniques. Other covered topics include explaination and demonstration of streaming ingestion, transformation via Hadoop in Google Compute ENGINE !PP%NGINE DATASTORE INTEGRATION AND USING '6IZ WITH 4ABLEAU TO GENERATE CHARTS OF QUERY RESULTS )N ADDITION TO THE MECHANICS OF "IG1UERY THE BOOK ALSO COVERS THE ARCHITECTURE OF the underlying Dremel query engine, providing a thorough understanding that leads to better query results. A companion Web site includes all code and data sets from the book. http://www.wiley.com

62 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 62 7/23/14 11:42 AM NEW PRODUCTS

CA Technologies’ CA arcserve Unified Data Protection

The upgraded CA arcserve Unified Data Protection (UDP) is so transformative, says IT solution provider CA Technologies, that it renders “point solutions” for backup and recovery obsolete. The company describes CA arcserve UDP as an easy-to-use solution providing cost-effective backup and “Assured Recovery” across mixed IT environments, helping businesses boost the availability of critical systems. The key selling point for the new version is simplicity, reducing the cost and complexity of deploying multiple point solutions. A new unified architecture and recovery point server drive a full range of highly efficient data protection capabilities for physical and virtual environments through a simple, Web-based user console. CA arcserve UDP provides more than 30 new marquee features to give businesses and service providers precise and flexible functionality to meet stringent service-level and recovery objectives. The solution comes in five editions so that customers buy just the right level of protection, all of which support Linux, UNIX and systems. http://www.arcserve.com

Hazelcast Enterprise

/N THE SAME DAY THAT ,ARRY %LLISON ANNOUNCED /RACLES )N -EMORY #OMPUTING STRATEGY THE COMPANY (AZELCAST ANNOUNCED (AZELCAST %NTERPRISE THE COMPANYS OWN COMMERCIAL )N -EMORY Computing solution. Hazelcast provides a radically different vision of In-Memory Computing driven by open-source, commodity hardware and open standards. Hazelcast is a leading open- source In-Memory Data Grid and is available under the Apache . Meanwhile, (AZELCAST %NTERPRISE EXTENDS THE OPEN SOURCE (AZELCAST CORE WITH COMMERCIAL FEATURES AND IS a commercially licensed software offering. The features in the enterprise offering that extend THE (AZELCASE OPEN CORE INCLUDE .%4 AND # CLIENTS OFF HEAP MEMORY IMPROVED 7EB sessions, Tomcat 6 and 7 Web sessions clustering, WAN copy, WAN replication to enterprise and improved security. Hazelcast itself also features the “Stabilizer”, a sophisticated stress and load-testing system for ensuring the reliability of production-scale grid systems. http://hazelcast.com

Please send information about releases of Linux-related products to [email protected] or New Products c/o Linux Journal, PO Box 980985, Houston, TX 77098. Submissions are edited for length and content.

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 63

LJ244-Aug2014.indd 63 7/23/14 11:42 AM FEATURE Vagrant

VAGRANT Revolutionize your development work flow in a programmatic way using the powers of Vagrant. RICHARD DELANEY

64 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 64 7/23/14 11:42 AM ow many times you have fashion. This repeatability encourages been hit by unit tests failing developers to tear down and bring H because of environment up environments more often. The differences between you and other development environment that all team members? How easy is it to team members are developing against build your project and have it ready now can be “stored” in the version for development? Vagrant provides control system in such a way that a method for creating repeatable anyone (new or otherwise) can have development environments across an environment set up after issuing a range of operating systems for a single command. solving these problems. It is a thin Continuous integration systems can layer that sits on top of existing use the same method. Building an technologies that allows people environment and setting up a project working on a project to reproduce in this way allows the developer to development environments with a be sure that once other environments single command: vagrant up. are provisioned in the same way, Vagrant is open-source software, the project will run as it did in and it sees lots of contributions DEVELOPMENT %NVIRONMENT SPECIFIC from its community in every release. unit test failures is a class of problems It was first released in 2010. Its completely removed by Vagrant. founder Mitchell Hashimoto founded Vagrant takes the building and the company HashiCorp to work provisioning of your software from on Vagrant and a number of other tribal knowledge within your team DevOps tools in November 2012. to a reproducible provisioning script HashiCorp has since released a that is stored alongside your code. number of other tools that are worth Others can read your Vagrantfile and checking out, such as Packer, Consul provisioning scripts and have your and Serf. These are for different areas project working on their system in of the development lifecycle. minutes. This helps integrate new Vagrant uses virtual machines from developers into your team quickly. various providers. It allows for easy It is easier to enable cross-team configuration using a Vagrantfile. development within a larger company This allows development teams to as it’s easier to get up and running set up the virtual machine the same with a project. It also allows designers way every time in a programmable or technical writers to get quick

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 65

LJ244-Aug2014.indd 65 7/23/14 11:42 AM FEATURE Vagrant

access to your project without having “shell”, which runs a defined shell to know any technical details about script at boot of the VM as the how to set up your project. root user. More advanced provisioners, such as Salt, Chef Vagrant Technologies and Puppet, also are available. In Originally, Vagrant supported only my workplace, we use Puppet to VirtualBox as a provider. A provider provision our virtual machines so as is the underlying virtualization to better match our development technology that Vagrant will interact systems with machines running in with. At the time of this writing, the production environments. Vagrant supports a wide variety of Depending on the provider, providers, VMware, hyper-v and, Vagrant also allows for “Synced most recently, Docker. Vagrant only Folders”; this allows very easy ships with VirtualBox support by sharing of folders between the host default. Other providers can be and guest machine. This means every added as plugins using Vagrant’s developer on your team can use a plugin system. For the purpose DIFFERENT )$% AND TOOLING THAT RUNS of this article, I use VirtualBox as on the host, and yet develop on the the provider, as it is the default, same guest machine. Vagrant makes and is likely the most accessible these things incredibly easy to set up to everyone. It is not the most as you will see later in the article. performant provider; VMware in most cases out-performs it, and How to Install Vagrant Docker (although it is not a drop-in Vagrant has installers for all of the replacement) is a very exciting main operating systems: Windows, technology in terms of speed and Linux (deb and rpm) and Mac OS X. definitely is worth checking out. This portability across host operating The next configurable part of systems allows developers in a team Vagrant is provisioner support. After to get the same local development a virtual machine has been started, experience on any environment. Vagrant uses “provisioners” to &OR THIS ARTICLE ) USED 5BUNTU  provision the box in a repeatable LTS, and I used the deb file from the way. This is done as part of bringing downloads section of the Vagrant the virtual machine up in most cases. home page. For Linux distributions The simplest type of provisioner is that don’t accept deb or rpm package

66 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 66 7/23/14 11:42 AM types, there is still the ability to run found on the Vagrant or specific older versions of Vagrant, provided providers’ Web sites. Vagrant, by that the distribution has support default, expects a vagrant user for Ruby and Ruby gems, but this on the box and the password (by has been discontinued for newer convention) should be “vagrant”. releases of Vagrant. For the purpose of this article, If you have not already installed you will use a publicly available base VirtualBox, you will need to install box. HashiCorp provide a base box it. This can be done through the FOR 5BUNTU  ,43 4O ADD A BOX package manager, although I used to Vagrant: the packages provided on the Oracle Web site. $ vagrant box add "hashicorp/precise32" This article uses Vagrant 1.6 and 6IRTUAL"OX  This command downloads the box from Vagrant cloud. Vagrant cloud Using Vagrant is a service HashiCorp provides, In this article, I run through setting which among other things offers box up a project using Vagrant, including discovery. Community base boxes are how to write the Vagrantfile, how uploaded and can be used. Vagrant to boot the virtual machine using knows that you are accessing a base Vagrant and interacting with that box from the Vagrant cloud and VM. The first thing you need is the will download it directly from there. base box on which you are going Once downloaded, you will not need to build your project. A base box to download the base box again to is a provider-specific bare-bones use in other Vagrant projects on the operating system disk image with same host. You can see available some basic things installed. Vagrant boxes by using the list command: uses SSH to connect to all its boxes, so an SSH server must be enabled, $ vagrant box list and a specific user must have SSH hashicorp/precise32 (virtualbox, 1.0.0) enabled. There are a number of other requirements to making a Now that the box has been added, Vagrant-compatible box. The process you will craft a basic Vagrantfile. A is too involved for this article, but Vagrantfile is a Ruby file that sets up more specific instructions can be certain variables for your box. Here’s

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 67

LJ244-Aug2014.indd 67 7/23/14 11:42 AM FEATURE Vagrant

Figure 1. VirtualBox Screenshot

a basic Vagrantfile: $ vagrant up

Vagrant.configure("2") do |config| It may take some time for the config.vm.box = "hashicorp/precise32" virtual machine to boot, but when end the command returns to the prompt, you successfully have started your This shows the power of Vagrant— virtual machine. At this time, WITH THIS SIMPLE FILE AN 5BUNTU  it might be worth opening the LTS virtual guest machine can be VirtualBox application so you can created and started on any system see the new virtual machine that has Vagrant supports. To start the Vagrant been created and ensure that it is VM, simply do the following: marked as running.

68 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 68 7/23/14 11:42 AM As I mentioned previously, base sync between the host and the guest boxes for use with Vagrant must be very easily. This is especially useful accessible via SSH. This allows you to when developing software projects attach to your new virtual machine using Vagrant when you want to be simply by doing the following in the able to edit files locally and have those same directory as the Vagrantfile: changes automatically appear in your development VM for testing purposes. $ vagrant ssh It allows developers to run their choice of editor while developing on the same You will be left in a bash prompt platform as anybody else in the team. in the virtual machine. In two commands, you have booted the VM Provisioning and ssh’d in to the VM. One more You’ve seen how to boot a simple thing to note before continuing on virtual machine using Vagrant, so to using Vagrant more powerfully next, let’s look at how to provision is that Vagrant, by default, shares that VM in a repeatable way. As the directory that the Vagrantfile is already mentioned, Vagrant supports located in under the /vagrant folder. a wide range of provisioners, but for To demo this capability, while still in the sake of this article, bash scripts the SSH session, do the following: will be used due to their familiarity. Guest machine: Adding a provisioning step is a matter of adding a single line inside the $ cd /vagrant configure block in the Vagrantfile. $ echo "test" > test The bootstrap also can be an inline script, but for most cases, it makes Host machine: sense to supply a script file that contains the provisioning steps. $ ls Add the following bootstrap.sh script test Vagrantfile to the same directory as the Vagrantfile:

As should be clear, you created a new #!/usr/bin/env bash file “test” on the guest, and the file # provisioning is run as root by default appears in the same directory on the host. Vagrant uses VirtualBox shared # make sure system sources are up to date. folders to allow you to keep files in apt-get update

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 69

LJ244-Aug2014.indd 69 7/23/14 11:42 AM FEATURE Vagrant

When vagrant up is complete, # install a web server you will be able to ssh in to the echo "==== Installing NGINX ====" machine as before. As shown below, apt-get install -y nginx let’s make sure that the provisioning has been successful. Note that nginx echo "==== Start the NGINX Server ====" is now installed on the system and service nginx start running on the system:

This bootstrap script makes sure the $ vagrant ssh system sources are up to date first. $ which nginx It then installs the nginx Web server. /usr/sbin/nginx The provisioning is added to the $ netstat -at | grep http Vagrantfile by adding the following tcp 0 0 *:http *:* LISTEN line to the configure block so that your Vagrantfile now looks like this: The virtual machine has been provisioned, and nginx is set up and Vagrant.configure("2") do |config| started. The Web server can be tested config.vm.box = "hashicorp/precise32" to be working, but it’s more difficult config.vm.provision :shell, :path => "bootstrap.sh" if you have to ssh in to the box to end test this. Next, let’s look at how to configure networking. To use the new provisioning, destroy The first option to access ports the running VM. This will stop and on your virtual machine is port remove the virtual machine. To destroy forwarding. For this example, nginx the VM, simply use the command serves http traffic on port 80. To vagrant destroy. The base box still forward the guest machine port 80 will be available for use after running to port 8080 on the host, add the the destroy command. Now to test following line to the Vagrantfile: the new configuration, simply run

vagrant up. When a provisioning config.vm.network "forwarded_port", guest: 80, host: 8080 step is present in the Vagrantfile, Vagrant automatically will provision As before, destroy the VM and do the box once it has booted. You can another vagrant up. Once the virtual turn off the provisioning by using the machine has been brought up and --no-provision flag. provisioned, the Web server can be

70 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 70 7/23/14 11:42 AM accessed on the host port 8080. the forwarded port once the VM On your favorite browser, visit has been booted and provisioned by http://localhost:8080/ to be greeted Vagrant. For example, using curl: with the nginx home page. This is one of the easier ways to be able to $ curl "http://localhost:8080/html/tester.html" connect to the virtual machine. For example, let’s modify the This example assumes an html bootstrap.sh to link the “html” directory is in your Vagrant directory directory in the Vagrant directory that has a tester.html file in it. to the nginx root directory. This What if you want to provide a would be an example of doing way to access the virtual machine simple static HTML Web site as if it were another machine on development. This could be the network? Vagrant provides a distributed to anybody to modify the very easy way to use VirtualBox HTML on the host and immediately networking to set up the virtual see the results on the guest. machine with a static IP on the same The revised bootstrap looks like this: LAN. Remove the port forwarding line from the Vagrantfile and replace it #!/usr/bin/env bash with the following: # provisioning is run as root by default

config.vm.network "private_network", ip: "192.168.56.20"

# make sure system sources are up to date. apt-get update Once you have re-ran vagrant up, # install a web server your virtual machine will be accessible echo "==== Installing NGINX ====" from your host using the IP address apt-get install -y nginx specified above. In my own projects, I use this private networking to assign echo "==== Start the NGINX Server ====" my static IP a domain by modifying service nginx start the /etc/hosts file. This allows testing of complicated http redirect flows that echo "==== Symlink Test Directory ====" rely on certain domains. ln -s /vagrant/html/ /usr/share/nginx/www/html It also allows multiple Vagrant virtual machines to contact one You can access the html directory another, as it is a shared network through the nginx Web server using between the host and all other virtual

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 71

LJ244-Aug2014.indd 71 7/23/14 11:42 AM FEATURE Vagrant

machines that are on the network. production environment. This is the For distributed projects, being able cause of a lot of production bugs due to control the networking access of to untested component configuration. multiple standalone components all of Vagrant allows you to manage this which have their own Vagrantfile (or all through a single Vagrantfile. If shared) is very powerful. the idea of multiple machines is one Again, in my work environment, that interests you, I also recommend it’s not uncommon to spin up looking closely at the new Docker multiple virtual machines, one for container option for Vagrant. Docker a database, one for an app server is built on top of Linux containers and one for a squid proxy. Running and allows you to spin up machines functional tests against these tests a much faster than VirtualBox. Multiple production-like setup. Vagrant allows machine support in Vagrant is all the you to do this in a simple, easy-to- more powerful if the provider level is repeat way, and the private network much faster to spin up machines. means there is no hassle in setting For multiple machine support, the up intercommunication between the Vagrantfile allows you to configure various components. multiple machines, each having their The last part of Vagrant that I want own configuration. The Vagrantfile to cover is having multiple machines below shows an example of what a in the one Vagrantfile. I already have -Y31, MASTER AND SLAVE 6AGRANTFILE given an example of why you might might look like: want to have multiple Vagrantfiles for

different components, so that they Vagrant.configure("2") do |config|

can be tested/developed on their own config.vm.box = "hashicorp/precise32"

or as a collective. Having multiple

machines in the one Vagrantfile is config.vm.define "master" do |master|

powerful when a single project can master.vm.provision :shell, :path => "master_bootstrap.sh"

have multiple parts that don’t belong master.vm.network "private_network", ip: "192.168.56.20"

on the one machine. Often in a Web end

development project, you will run the config.vm.define "slave" do |slave|

app server and database on the same slave.vm.provision :shell, :path => "slave_bootstrap.sh"

machine for testing but will have slave.vm.network "private_network", ip: "192.168.56.21"

multiple app servers and databases end

when that system gets into the end

72 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 72 7/23/14 11:42 AM %ACH MACHINE IS DEFINED WITH THE consistent IP addresses using one first config block as separate blocks. command—vagrant up. This is They support all of the same options repeatable across the three major as the normal one-machine Vagrant operating systems and a number config blocks. For example, for the of different providers including master here, you define the shell the most popular virtualization provisioning script to be run as well technologies and cloud offerings. as the static IP address to give this This removes so many of the pain virtual machine. This allows you to points from working on systems in test distributed systems in the same local development. There are a lot easy repeatable way as you could of advantages to making the switch with a single machine. to using Vagrant for both local When using a multiple machine development and your continuous configuration like the above, there are integration systems. All developers’ a few changes to the way you have test machines are running the same to run Vagrant commands. Running code and are provisioned in the same vagrant up will bring up both boxes fashion. Test failures are not tied automatically. The master will be to a specific developer’s setup and provisioned first and then the slave. should be reproducable on anyone’s You can choose to bring up only one machine by running vagrant up. of the machines by supplying the This article covered only some of machine name: the amazing capabilities of Vagrant, so I encourage you also to read $ vagrant up master over the brilliant documentation at http://docs.vagrantup.com.Q When the boxes have booted and been provisioned, you also have to Richard Delaney is a software engineer with Demonware specify the machine name when Ireland. Richard works on back-end Web services using using vagrant ssh. Python and the Django Web framework. He has been an avid Linux user and evangelist for the past five years. Conclusion Let’s reflect on what you have achieved here: multiple virtual Send comments or feedback via machines booting, being http://www.linuxjournal.com/contact provisioned automatically and or to [email protected].

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 73

LJ244-Aug2014.indd 73 7/23/14 11:42 AM FEATURE An Introduction to OpenGL Programming

OpenGLAn Introduction to Programming Learn how to create a 3-D cube using triangles.

MIHALIS TSOUKALOS

74 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 74 7/23/14 11:42 AM penGL is a well-known on a Debian 7 system to find all standard for generating 3-D packages that contain the word O as well as 2-D graphics that “opengl”, you’ll get plenty of is extremely powerful and has many output (Figure 1): capabilities. OpenGL is defined and released by the OpenGL Architecture $ apt-cache search opengl Review Board (ARB). This article is a gentle introduction There are many free OpenGL to OpenGL that will help you implementations for Linux, but understand drawing using OpenGL. you need only one. I installed The latest version of OpenGL at the FreeGLUT, because it is the most up time of this writing IS  WHICH USES A different technique for drawing from the one presented here. Nevertheless, the purpose of this article is to help you understand OpenGL philosophy, not teach you how to code using the latest OpenGL version. Therefore, the presented source code can be run on Linux machines that have an older OpenGL version installed.

Installing OpenGL If you run the following command Figure 1. Running apt-cache search opengl

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 75

LJ244-Aug2014.indd 75 7/23/14 11:42 AM FEATURE An Introduction to OpenGL Programming

to date. FreeGLUT is an open-source Finally, you may need to install the alternative to the OpenGL Utility mesa-utils package in order to be able Toolkit (GLUT) library: to use the glxinfo command:

root@mail:~# apt-get install freeglut3 freeglut3-dev libglew-dev # apt-get install mesa-utils

Reading package lists... Done

Building dependency tree The glxinfo command displays

Reading state information... Done useful information about your OpenGL

The following package was automatically installed installation, as you can see in the

and is no longer required: following output:

fonts-liberation

Use 'apt-get autoremove' to remove it. ...

The following extra packages will be installed: GLX version: 1.4

libgl1-mesa-dev libglu1-mesa-dev libice-dev libpthread-stubs0 GLX extensions:

libpthread-stubs0-dev libsm-dev libx11-dev libx11-doc GLX_ARB_get_proc_address, GLX_ARB_multisample,

libxau-dev libxcb1-dev libxdmcp-dev libxext-dev libxt-dev GLX_EXT_import_context, GLX_EXT_texture_from_pixmap,

mesa-common-dev x11proto-core-dev x11proto-input-dev GLX_EXT_visual_info, GLX_EXT_visual_rating,

x11proto-kb-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev GLX_MESA_copy_sub_buffer, GLX_MESA_multithread_makecurrent,

Suggested packages: GLX_OML_swap_method, GLX_SGIS_multisample, GLX_SGIX_fbconfig,

libice-doc libsm-doc libxcb-doc libxext-doc libxt-doc GLX_SGIX_pbuffer, GLX_SGI_make_current_read

The following NEW packages will be installed: OpenGL vendor string: VMware, Inc.

freeglut3 freeglut3-dev libgl1-mesa-dev libglu1-mesa-dev OpenGL renderer string: Gallium 0.4 on llvmpipe

libice-dev libpthread-stubs0 libpthread-stubs0-dev libsm-dev (LLVM 3.4, 128 bits)

libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev OpenGL version string: 2.1 Mesa 10.1.3

libxext-dev libxt-dev mesa-common-dev x11proto-core-dev OpenGL shading language version string: 1.30

x11proto-input-dev x11proto-kb-dev x11proto-xext-dev OpenGL extensions:

xorg-sgml-doctools xtrans-dev ...

0 upgraded, 22 newly installed, 0 to remove and 0 not upgraded.

Need to get 7,651 kB of archives. Mesa is a 3-D graphics library

After this operation, 24.9 MB of additional disk space with an API that is so very similar

will be used. to OpenGL’s, it is pretty much

Do you want to continue [Y/n]? indistinguishable.

9OU ALSO WILL NEED A # COMPILER OpenGL Pipeline to compile the code. Figure 2—taken from the OpenGL

76 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 76 7/23/14 11:42 AM Figure 2. OpenGL Architecture

Shading Language book (aka OpenGL Shading Language has its “The Orange Book”)—shows the roots in C (presenting the OpenGL programmable OpenGL pipeline with Shading Language is beyond the the vertex and fragment processors. scope of this article). As you can imagine, the OpenGL OpenGL does not define a pipeline is complex, but you do windowing layer, because it tries to not have to understand it fully in be platform-neutral and leaves this order to be able to use OpenGL. functionality to the operating system. The Pipeline shows how OpenGL The OS must provide a rendering operates in the background. Newer context that accepts commands as versions of the OpenGL Pipeline are well as a framebuffer that keeps the even more complex! results of the drawing commands. OpenGL is a big state machine. Matrix Algebra is extensively used in Most calls to OpenGL functions 3-D graphics, so it is good for you to modify a global state that you cannot know how to add, multiply, subtract access directly. and divide matrices, although you The OpenGL Shading Language will not need to code such operations code that is intended for execution yourself. It also is useful to become on one of the OpenGL programmable familiar with 3-D coordinates and be processors is called a Shader. The able to sketch on paper the 3-D scene

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 77

LJ244-Aug2014.indd 77 7/23/14 11:42 AM FEATURE An Introduction to OpenGL Programming

you are trying to draw. code. The code in Listing 1, when executed, draws a triangle on-screen Drawing a Triangle using OpenGL. Now it’s time for some real OpenGL The code in Listing 1 for setting up

Listing 1. triangle.cc

// Programmer: Mihalis Tsoukalos // Date: Wednesday 04 June 2014 // // A simple OpenGL program that draws a triangle.

#include "GL/freeglut.h" #include "GL/gl.h"

void drawTriangle() { glClearColor(0.4, 0.4, 0.4, 0.4); glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0, 1.0, 1.0); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

glBegin(GL_TRIANGLES); glVertex3f(-0.7, 0.7, 0); glVertex3f(0.7, 0.7, 0); glVertex3f(0, -1, 0); glEnd();

glFlush(); }

int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("OpenGL - Creating a triangle"); glutDisplayFunc(drawTriangle); glutMainLoop(); return 0; }

78 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 78 7/23/14 11:42 AM OpenGL is large, but you will have to learn it only once. On a Debian 7 system, the following command compiled the triangle.cc OpenGL program without any error messages:

$ g++ triangle.cc -lglut -o triangle

On an Ubuntu Linux system, the same command produced the following error messages:

/usr/bin/ld: /tmp/ccnBP5li.o: undefined reference to symbol

´'glOrtho'

//usr/lib/x86_64-linux-/mesa/libGL.so.1: error adding Figure 3. Drawing a Triangle Using OpenGL

//symbols: DSO missing from command line

collect2: error: ld returned 1 exit status libGL also can pass the OpenGL information to the X Window System, The solution is to compile the if the GLX extension is present. Then, triangle.cc program by linking the X Window System can do software the executable to an additional rendering with the help of Mesa or library (-lGL): use hardware acceleration. The output from the executable mtsouk@mtsouk-VirtualBox:/media/sf_OpenGL.LJ/code$ g++ will produce the triangle shown in ´triangle.cc -lglut -lGL -o triangle Figure 3. The correct compilation of triangle.cc is proof that your Linux The libGL.so library accepts OpenGL system can be used for developing commands and makes sure that they OpenGL applications. are put on the screen in some way. There is more than one way of If your graphics card does not have drawing a triangle using OpenGL, 3-D acceleration, libGL contains a mostly depending on the OpenGL software renderer that gives a 2-D version you are using. Although image as output to the X Window the presented method is an System. This is the case with Mesa. older way of programming

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 79

LJ244-Aug2014.indd 79 7/23/14 11:42 AM FEATURE An Introduction to OpenGL Programming

OpenGL applications, I find it Drawing a Cube Using OpenGL straightforward and easy to Next, let’s program an application understand. Remember, whichever that draws a cube using OpenGL. method you use, the coordinates of You need to construct the cube the triangle will be the same. using triangles. A cube has six faces, Note: keep in mind that the and each face needs at least two most important part of this article triangles to be defined. The reason is the code! I say “at least” is that, generally

Listing 2. cube.cc

// Programmer: Mihalis Tsoukalos glVertex3f(-x, -y, z); // Date: Wednesday 04 June 2014 glVertex3f(x, -y, z); // glVertex3f(-x, y, z); // A simple OpenGL program that draws a colorful cube glEnd(); // that rotates as you move the arrow keys! // // FRONT // g++ cube.cc -lm -lglut -lGL -lGLU -o cube // Using 4 trianges! glBegin(GL_TRIANGLES); #define GL_GLEXT_PROTOTYPES glColor3f(0.1, 0.5, 0.3); #ifdef _ _APPLE_ _ glVertex3f(-x, y, -z); #include glVertex3f(0, 0, -z); #else glVertex3f(-x, -y, -z); #include glEnd(); #endif #include glBegin(GL_TRIANGLES); glColor3f(0.0, 0.5, 0.0); // Rotate X glVertex3f(-x, -y, -z); double rX=0; glVertex3f(0, 0, -z); // Rotate Y glVertex3f(x, -y, -z); double rY=0; glEnd();

// The coordinates for the vertices of the cube glBegin(GL_TRIANGLES); double x = 0.6; glColor3f(0.1, 0.3, 0.3); double y = 0.6; glVertex3f(-x, y, -z); double z = 0.6; glVertex3f(x, y, -z); glVertex3f(0, 0, -z); void drawCube() glEnd(); { // Set Background Color glBegin(GL_TRIANGLES); glClearColor(0.4, 0.4, 0.4, 1.0); glColor3f(0.2, 0.2, 0.2); // Clear screen glVertex3f(0, 0, -z); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glVertex3f(x, y, -z); glVertex3f(x, -y, -z); // Reset transformations glEnd(); glLoadIdentity(); // LEFT // Rotate when user changes rX and rY glBegin(GL_TRIANGLES); glRotatef( rX, 1.0, 0.0, 0.0 ); glColor3f(0.3, 0.5, 0.6); JO5RWDWHI U<  glVertex3f(-x, -y, -z); glVertex3f(-x, -y, z); // BACK glVertex3f(-x, y, -z); glBegin(GL_TRIANGLES); glEnd(); glColor3f(0.4, 0.3, 0.5); glVertex3f(x, y, z); glBegin(GL_TRIANGLES); glVertex3f(x, -y, z); glColor3f(0.5, 0.5, 0.5); glVertex3f(-x, y, z); glVertex3f(-x, y, z); glEnd(); glVertex3f(-x, -y, z); glVertex3f(-x, y, -z); glBegin(GL_TRIANGLES); glEnd(); glColor3f(0.5, 0.3, 0.2);

80 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 80 7/23/14 11:42 AM speaking, you can use more triangles %ACH TRIANGLE REQUIRES THREE DIFFERENT if you want in order to have a vertices to be defined. smoother and more accurate shape, Listing 2 shows the full source code but when drawing a cube, that’s of the cube.cc file. not necessary. As I’m sure you’ve &IGURE  SHOWS TWO DIFFERENT realized, you are going to need 12 screenshots from the cube.cc triangles in total. application. The left screenshot of the A cube also has eight vertices. program just shows a square,

// RIGHT { glBegin(GL_TRIANGLES); if (key == GLUT_KEY_RIGHT) glColor3f(0.2, 0.2, 0.2); { glVertex3f(x, y, z); rY += 15; glVertex3f(x, y, -z); } glVertex3f(x, -y, z); else if (key == GLUT_KEY_LEFT) glEnd(); { rY -= 15; glBegin(GL_TRIANGLES); } glColor3f(0.0, 0.0, 0.0); else if (key == GLUT_KEY_DOWN) glVertex3f(x, -y, -z); { glVertex3f(x, y, -z); rX -= 15; glVertex3f(x, -y, z); } glEnd(); else if (key == GLUT_KEY_UP) { // TOP rX += 15; glBegin(GL_TRIANGLES); } glColor3f(0.6, 0.0, 0.0); glVertex3f(x, y, z); // Request display update glVertex3f(x, y, -z); glutPostRedisplay(); glVertex3f(-x, y, -z); } glEnd();

glBegin(GL_TRIANGLES); int main(int argc, char **argv) glColor3f(0.6, 0.1, 0.2); { glVertex3f(-x, y, z); // Initialize GLUT and process user parameters glVertex3f(x, y, z); glutInit(&argc, argv); glVertex3f(-x, y, -z); glEnd(); // Request double buffered true color window with Z-buffer glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); // BOTTOM glBegin(GL_TRIANGLES); glutInitWindowSize(700,700); glColor3f(0.4, 0.0, 0.4); glutInitWindowPosition(100, 100); glVertex3f(-x, -y, -z); glVertex3f(-x, -y, z); // Create window glVertex3f(x, -y, z); glutCreateWindow("Linux Journal OpenGL Cube"); glEnd(); // Enable Z-buffer depth test glBegin(GL_TRIANGLES); glEnable(GL_DEPTH_TEST); glColor3f(0.3, 0.0, 0.3); glVertex3f(x, -y, -z); // Callback functions glVertex3f(-x, -y, -z); glutDisplayFunc(drawCube); glVertex3f(x, -y, z); glutSpecialFunc(keyboard); glEnd(); // Pass control to GLUT for events glFlush(); glutMainLoop(); glutSwapBuffers(); } return 0; } void keyboard(int key, int x, int y)

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 81

LJ244-Aug2014.indd 81 7/23/14 11:42 AM FEATURE An Introduction to OpenGL Programming

Figure 4. The Graphical Output of cube.cc

because you are looking straight at triangles. Figure 5 shows the the front face of the cube and can’t coordinates of the front face of the see any of the other five faces of cube when four triangles are used the cube. Therefore, the shape you to define it. The point (0,0,-0.6) see on screen looks like it is in 2-D. has been chosen arbitrarily. You just When you start rotating the cube need a point that belongs to the using the arrow keys, you can tell front face of the cube. that it is a 3-D shape. Defining the Vertices: Figure 6 shows the coordinates of the vertices Explaining the Code OF THE CUBE FOR X Y AND %ACH TRIANGLE IS DEFINED BY THREE Z .OTE THAT THE VERTICES THAT VERTICES %ACH VERTEX IS DEFINED WITH define an edge have two out of their the help of a single point (x,y,z). three coordinates exactly the same. %ACH POINT COMES WITH THREE NUMBERS As you can see in Figure 6, (coordinates), because OpenGL uses the coordinates of the four vertices a 3-D space. A cube needs eight that define the front face and vertices to be defined. the respective coordinates of the As an exercise, the front face four vertices that define the back of the cube is made using four face differ only in the value of the

82 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 82 7/23/14 11:42 AM Figure 5. The Coordinates of the Front Face of the Cube

Figure 6. The Vertices of the Cube

z-axis coordinate. Changing Color: You can Defining the Triangles: The change the color of a shape with TRIANGLES ARE BASED ON VERTICES %ACH the glColor3f(...) command. triangle needs three vertices to be The glColor3f(...) command defined. Two triangles are needed for takes three parameters, which defining each face of the cube, except represent the RGB values of the for the front face where four triangles desired color. are used. The following commands Changing Perspective: You can create a color triangle based on the change the perspective of the scene values of x, y and z: with the following commands:

glBegin(GL_TRIANGLES); glRotatef(rX, 1.0, 0.0, 0.0); glColor3f(0.4, 0.0, 0.4); glRotatef(rY, 0.0, 1.0, 0.0); glVertex3f(-x, -y, -z); glVertex3f(-x, -y, z); As the user presses one of the glVertex3f(x, -y, z); four arrow keys, the perspective glEnd(); angle changes accordingly.

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 83

LJ244-Aug2014.indd 83 7/23/14 11:42 AM FEATURE An Introduction to OpenGL Programming

Drawing the Cube: Drawing the arrow keys and acts accordingly: CUBE IS DONE FACE BY FACE %ACH FACE needs two triangles to be drawn void keyboard(int key, int x, int y) except for the front face where four { triangles are used. if (key == GLUT_KEY_RIGHT) Once you get the coordinates { of the triangles correctly, drawing rY += 15; is pretty easy. The drawing of } each triangle starts with the else if (key == GLUT_KEY_LEFT) glBegin(GL_TRIANGLES) command { and finishes with the glEnd() rY -= 15; command. The GL_TRIANGLES } is an OpenGL primitive. Other else if (key == GLUT_KEY_DOWN) primitive types are GL_POINTS, { GL_LINES, GL_LINE_STRIP, rX -= 15; GL_LINE_LOOP, GL_TRIANGLE_STRIP, } GL_TRIANGLE_FAN, GL_QUADS, else if (key == GLUT_KEY_UP) GL_QUAD_STRIP and GL_POLYGON. { %VENTUALLY EVERY PRIMITIVE SHAPE IN rX += 15; OpenGL is represented by one or } more triangles. If you are drawing using triangles // Request display update (GL_TRIANGLES), the order in glutPostRedisplay(); which you put the vertices is not } important. If you are drawing using rectangles (GL_POLYGON), the four The keyboard(...) function is vertices of the rectangle must be registered inside the main(...) drawn in the right order, although function using the following line it does not matter if you draw CW of code: or CCW. If the drawing order is wrong, the rectangle you are trying glutSpecialFunc(keyboard); to draw will have a big hole in it. Using the Arrow Keys: Using Rotating a Cube Automatically the arrow keys is pretty simple. As a bonus, let’s look at how to The following code checks for the make a cube rotate automatically

84 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 84 7/23/14 11:42 AM Drawing using rectangles is easier and requires less code, but complex OpenGL code runs faster when triangles are used.

(Figure 7). and rotateCube.cc are pretty This time, the cube is drawn similar, although the three programs using rectangles. As the cube has perform different tasks. six faces, only six rectangles are The crucial thing here is the needed. Drawing using rectangles usage of the glutTimerFunc(...) is easier and requires less code, but function. It registers a timer complex OpenGL code runs faster callback for the update(...) when triangles are used. function that is going to be Note: every object can be split triggered in a specified number of into triangles, but a triangle milliseconds. The update(...) cannot be split into anything function changes the angle of the other than triangles. scene every time it’s called. Listing 3 shows the source code for rotateCube.cc. Conclusion Note that the main(...) OpenGL programming is not easy, functions of triangle.cc, cube.cc but this article should help you start

Figure 7. The Output of rotateCube.cc

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 85

LJ244-Aug2014.indd 85 7/23/14 11:42 AM FEATURE An Introduction to OpenGL Programming

Listing 3. rotateCube.cc

// Programmer: Mihalis Tsoukalos GLfloat lightPos0[] = {4.0, 0.0, 8.0, 1.0}; // Date: Wednesday 04 June 2014 glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); // glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); // A simple OpenGL program that draws a triangle // and automatically rotates it. glTranslatef(0.5, 1.0, 0.0); // glRotatef(angle, 1.0, 1.0, 1.0); // g++ rotateCube.cc -lm -lglut -lGL -lGLU -o rotateCube glRotatef( angle, 1.0, 0.0, 1.0 ); #include glRotatef( angle, 0.0, 1.0, 1.0 ); #include glTranslatef(-0.5, -1.0, 0.0);

// the GLUT and OpenGL libraries have to be linked correctly // Create the 3D cube #ifdef _ _APPLE_ _ #include // BACK #include glBegin(GL_POLYGON); #else glColor3f(0.5, 0.3, 0.2); #include glVertex3f(x, -y, z); #endif glVertex3f(x, y, z); glVertex3f(-x, y, z); using namespace std; glVertex3f(-x, -y, z); glEnd(); // The coordinates for the vertices of the cube double x = 0.6; // FRONT double y = 0.6; glBegin(GL_POLYGON); double z = 0.6; glColor3f(0.0, 0.5, 0.0); glVertex3f(-x, y, -z); float angle = 0.0; glVertex3f(-x, -y, -z); glVertex3f(x, -y, -z); void drawCube() glVertex3f(x, y, -z); { glEnd(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LEFT // Reset transformations glBegin(GL_POLYGON); glMatrixMode(GL_MODELVIEW); glColor3f(0.5, 0.5, 0.5); glLoadIdentity(); glVertex3f(-x, -y, -z); glVertex3f(-x, -y, z); glTranslatef(0.0, 0.0, -5.0); glVertex3f(-x, y, z); glVertex3f(-x, y, -z); // Add an ambient light glEnd(); GLfloat ambientColor[] = {0.2, 0.2, 0.2, 1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); // RIGHT // Add a positioned light glBegin(GL_POLYGON); GLfloat lightColor0[] = {0.5, 0.5, 0.5, 1.0}; glColor3f(0.0, 0.0, 0.0);

writing OpenGL applications quickly. Mihalis Tsoukalos is a UNIX administrator, a programmer (UNIX If you want to become proficient in and iOS), a DBA and mathematician. You can reach him at OpenGL, keep practicing writing more http://www.mtsoukalos.eu and @mactsouk (Twitter). Contact OpenGL programs. OpenGL is easy to him if you are looking for a UNIX system administrator. start with but difficult to master.

Acknowledgement I would like to thank Dr Nikos Platis Send comments or feedback via for sharing a small part of his OpenGL http://www.linuxjournal.com/contact knowledge with me.Q or to [email protected].

86 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 86 7/23/14 11:42 AM glVertex3f(x, -y, -z); // Initializes 3D rendering glVertex3f(x, -y, z); void initRendering() glVertex3f(x, y, z); { glVertex3f(x, y, -z); glEnable(GL_DEPTH_TEST); glEnd(); glEnable(GL_COLOR_MATERIAL);

// TOP // Set the color of the background glBegin(GL_POLYGON); glClearColor(0.7f, 0.8f, 1.0f, 1.0f); glColor3f(0.6, 0.0, 0.0); glEnable(GL_LIGHTING); glVertex3f(x, y, z); glEnable(GL_LIGHT0); glVertex3f(-x, y, z); glEnable(GL_NORMALIZE); glVertex3f(-x, y, -z); } glVertex3f(x, y, -z); glEnd(); // Called when the window is resized void handleResize(int w, int h) // BOTTOM { glBegin(GL_POLYGON); glViewport(0, 0, w, h); glColor3f(0.3, 0.0, 0.3); glMatrixMode(GL_PROJECTION); glVertex3f(-x, -y, -z); glLoadIdentity(); glVertex3f(-x, -y, z); gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0); glVertex3f(x, -y, z); } glVertex3f(x, -y, -z); glEnd(); int main(int argc, char **argv) glFlush(); { glutSwapBuffers(); glutInit(&argc, argv); } glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(700, 700); // Function for increasing the angle variable smoothly, glutInitWindowPosition(100, 100); // keeps it <=360 glutCreateWindow("OpenGL - Rotating a Cube"); // It can also be implemented using the modulo operator. initRendering(); void update(int value) { glutDisplayFunc(drawCube); angle += 1.0f; glutReshapeFunc(handleResize); if (angle > 360) { // Add a timer for the update(...) function angle -= 360; glutTimerFunc(25, update, 0); } glutMainLoop(); glutPostRedisplay(); return 0; glutTimerFunc(25, update, 0); } }

Resources

OpenGL: http://www.opengl.org

Learning Modern 3D Graphics Programming: http://www.arcsynthesis.org/gltut

OpenGL Superbible, 6th edition, Graham Sellers, Richard S. Wright and Nicholas Haemel, Addison Wesley, ISBN: 0321902947

GLEW: http://glew.sourceforge.net

The Mesa 3D Graphics Library: http://www.mesa3d.org

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 87

LJ244-Aug2014.indd 87 7/23/14 11:42 AM KNOWLEDGE HUB

WEBCASTS Learn the 5 Critical Success Factors to Accelerate IT Service Delivery in a Cloud-Enabled Data Center Today's organizations face an unparalleled rate of change. Cloud-enabled data centers are increasingly seen as a way to accelerate IT service delivery and increase utilization of resources while reducing operating expenses. Building a cloud starts with virtualizing your IT environment, but an end-to-end cloud orchestration solution is key to optimizing the cloud to drive real productivity gains.

> http://lnxjr.nl/IBM5factors

Modernizing SAP Environments with Minimum Risk—a Path to Big Data Sponsor: SAP | Topic: Big Data )S THE DATA EXPLOSION IN TODAYS WORLD A LIABILITY OR A COMPETITIVE ADVANTAGE FOR YOUR BUSINESS %XPLOITING MASSIVE AMOUNTS of data to make sound business decisions is a business imperative for success and a high priority for many firms. With rapid advances in x86 processing power and storage, enterprise application and database workloads are increasingly being moved from UNIX to Linux as part of IT modernization efforts. Modernizing application environments has numerous TCO and ROI benefits but the transformation needs to be managed carefully and performed with minimal downtime. Join this webinar to hear from top IDC analyst, Richard Villars, about the path you can start taking now to enable your organization to get the benefits of turning data into actionable insights with exciting x86 technology.

> http://lnxjr.nl/modsap

WHITE PAPERS White Paper: JBoss Enterprise Application Platform for OpenShift Enterprise Sponsor: DLT Solutions 2ED (ATSš *"OSS %NTERPRISE !PPLICATION 0LATFORM FOR /PEN3HIFT %NTERPRISE OFFERING PROVIDES )4 ORGANIZATIONS WITH A SIMPLE AND STRAIGHTFORWARD WAY TO DEPLOY AND MANAGE *AVA APPLICATIONS 4HIS OPTIONAL /PEN3HIFT %NTERPRISE COMPONENT FURTHER EXTENDS THE DEVELOPER AND MANAGEABILITY BENElTS INHERENT IN *"OSS %NTERPRISE !PPLICATION 0LATFORM FOR ON PREMISE CLOUD ENVIRONMENTS

5NLIKE OTHER MULTI PRODUCT OFFERINGS THIS IS NOT A BUNDLING OF TWO SEPARATE PRODUCTS *"OSS %NTERPRISE -IDDLEWARE HAS BEEN HOSTED ON THE /PEN3HIFT PUBLIC OFFERING FOR MORE THAN  MONTHS !ND MANY CAPABILITIES AND FEATURES OF *"OSS %NTERPRISE Application Platform 6 and JBoss Developer Studio 5 (which is also included in this offering) are based upon that experience.

This real-world understanding of how application servers operate and function in cloud environments is now available in this SINGLE ON PREMISE OFFERING *"OSS %NTERPRISE !PPLICATION 0LATFORM FOR /PEN3HIFT %NTERPRISE FOR ENTERPRISES LOOKING FOR CLOUD benefits within their own datacenters.

> http://lnxjr.nl/jbossapp

88 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 88 7/23/14 11:42 AM KNOWLEDGE HUB

WHITE PAPERS Linux Management with Satellite: Measuring Business Impact and ROI Sponsor: Red Hat | Topic: Linux Management

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to de- ploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

> http://lnxjr.nl/RHS-ROI

Standardized Operating Environments for IT Efficiency Sponsor: Red Hat

4HE 2ED (ATš 3TANDARD /PERATING %NVIRONMENT 3/% HELPS YOU DEFINE DEPLOY AND MAINTAIN 2ED (AT %NTERPRISE ,INUXš AND THIRD PARTY APPLICATIONS AS AN 3/% 4HE 3/% IS FULLY ALIGNED WITH YOUR REQUIREMENTS AS AN EFFECTIVE AND MANAGED process, and fully integrated with your IT environment and processes.

Benefits of an SOE:

3/% IS A SPECIFICATION FOR A TESTED STANDARD SELECTION OF COMPUTER HARDWARE SOFTWARE AND THEIR CONFIGURATION FOR USE ON COMPUTERS WITHIN AN ORGANIZATION 4HE MODULAR NATURE OF THE 2ED (AT 3/% LETS YOU SELECT THE MOST APPROPRIATE solutions to address your business' IT needs.

SOE leads to:

s $RAMATICALLY REDUCED DEPLOYMENT TIME

s 3OFTWARE DEPLOYED AND CONFIGURED IN A STANDARDIZED MANNER

s 3IMPLIFIED MAINTENANCE DUE TO STANDARDIZATION

s )NCREASED STABILITY AND REDUCED SUPPORT AND MANAGEMENT COSTS

s 4HERE ARE MANY BENEFITS TO HAVING AN 3/% WITHIN LARGER ENVIRONMENTS SUCH AS

s ,ESS TOTAL COST OF OWNERSHIP 4#/ FOR THE )4 ENVIRONMENT

s -ORE EFFECTIVE SUPPORT

s &ASTER DEPLOYMENT TIMES

s 3TANDARDIZATION

> http://lnxjr.nl/RH-SOE

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 89

LJ244-Aug2014.indd 89 7/23/14 11:42 AM INDEPTH Promise Theory— What Is It? Mark Burgess describes the idea behind Promise Theory—the framework developed between Oslo University College and the University of Amsterdam during the past decade to solve the problem of configuring distributed systems and services. MARK BURGESS

During the past 20 years, there has out of this dilemma was proposed been a growing sense of inadequacy in 2005 and has acquired a growing about the “command and control” band of disciples in computing model for managing IT systems. and networking. This involves Years in front of the television with the harnessing of autonomous a remote control have left us hard distributed agents. pressed to think of any other way of making machines work for us. From Imposing to Obtaining But, the truth is that point-and-click, Imagine that we want to implement imperative scripting and remote a software design or enact a business execution do not scale very well when process. For cultural reasons, our you are trying to govern the behavior first thought is to want to issue a of a large number of things. list of instructions to all the parts IT installations grow to massive involved to carry out some kind of an size in data centers, and the idea algorithm, but that might not be the of remote command and control, best choice at scale. An algorithm is by an external manager, struggles just a story we tell ourselves about to keep pace, because it is an how we envisage the process in our essentially manual human-centric minds. Often we try to tell the same activity. Thankfully, a simple way story to a computer or to a team of

90 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 90 7/23/14 11:42 AM INDEPTH

people, in the form of a flow chart problems. One of those problems or scripted language. This is one way is that it separates intent from of describing, building or processing implementation, creating uncertainty the design. The algorithm might of outcome. The place where the involve a lot of detail and take the instructions are determined is not form of step-by-step instructions, the place where they must be carried but other approaches use parallelism out, so the instructor does not have or non-linear stories to lay out the the information about conditions job more efficiently. In either case, where the local work needs to take the instructor assumes that all of the place. If two different instructors start parts involved simply will do exactly issuing conflicting instructions to the as they are instructed. Alas, this is same set of parts, there would start a not necessarily true. Remote parts of conflict, which no part of the system a system might be unable to comply would be able to resolve, because with these instructions, or even be none of the parts would have the unwilling to comply, depending on information in one place: intent is their nature and their circumstances. not local to the point of action. The This command and control model instructors might not even be aware is called an obligation model in of each other to resolve the conflict. computer science. It has many Luckily, there is a complementary

Figure 1. Obligation Model vs. Promise Theory

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 91

LJ244-Aug2014.indd 91 7/23/14 11:42 AM INDEPTH

approach to looking at design that kinds of promises we need—that is a fixes these deficiencies, not in terms separate problem. of obligations, but in terms %LECTRONICS ARE BUILT IN THIS WAY AS of promises. is plumbing and other commoditized In a promise-based design, each construction methods. You buy part behaves only according to the components (from a suitable supplier) promises it makes to others. Instead that promise certain properties of instructions from without, we (resistance, capacitance, voltage- have behavior promised from within. current relationships), and you Since the promises are made by “self” combine them based on those (human self or machine self), it means expectations into a circuit that keeps that the decision is always made with a greater promise (like being a radio knowledge of the same circumstances transmitter or a computer). under which implementation will take place. Moreover, if two Example—CSS promises conflict with one another, To offer an example of a promise- the agent has complete information oriented language, think of HTML about those circumstances and and cascading style sheets on the conflicting intentions to be able to Web. One can break up a Web page resolve them without having to ask into labeled and tagged objects like for external help. titles and paragraphs, tables and A promise-oriented view is IMAGES AND SO ON %ACH OF THESE MAY somewhat like a service view. Instead be tagged with a specific identity, of trying to remote-control things simply a type (like title, paragraph, with strings and levers, one makes link and so on). In a Promise Theory use of an ecosystem of promised model, these regions could be viewed services that advertise intent and as “autonomous agents”, which offer a basic level of certainty about through CSS, make promises about how they will behave. Promises are what color, font and spacing they will about expectation management, use to render their content initially and knowing the services and and over time. The HTML file has their properties that will help us regions of the form: to compose a working system. It doesn’t matter here how we get

Title...

components in a system to make the

Text....

92 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 92 7/23/14 11:42 AM INDEPTH

Although these are regions of rather the description of a state to be a text file, this is not substantially CONTINUOUSLY MAINTAINED )N #&%NGINE different from files on a disk. It is just style, we could write this alternative a collection of containers. The CSS form of the HTML style sheet: promises look like this: html: h1.main {color: red; font-size: 12px; } main:: p.main {text-align:justify;} "h1" font_size => "12px", That is, a header h1 in section color => "red"; “main” would be red and use "p" 12-point text. Compare this to files. text_align => "justify"; 4HE CONFIGURATION TOOL #&%NGINE FOR building and maintaining computers, From Promise Theory, we see allows us to keep promises about that these patterns are basically what attributes system resources will the same; thus, one could say that have. For example, instead of colors #&%NGINE IS A KIND OF hSTYLE SHEET FOR and fonts, files can promise to have servers”, in this sense. certain permissions, content and names. One would write: Composition of Promises Promise Theory deals with how to files: think, in this way, about a much wider debian:: range of problems. It was proposed "/etc/passwd" (by myself) in 2005 as a way to perms => mo("root", "644"); formalize how the UNIX configuration ENGINE #&%NGINE INTUITIVELY ADDRESSED The language looks superficially the problem of managing distributed different, but it basically is the infrastructure. Such formal models same kind of declarative association are important in computer science between patterns of objects and what to prove correctness. It has since they promise. The promise a region been developed by myself and Jan makes itself is the one it will render Bergstra, and it is being adopted by for all time, until the promise has an increasing number of others. changed. So this is not a fire-and- This complementary non-command forget push-button command, but way of thinking seems unnatural to

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 93

LJ244-Aug2014.indd 93 7/23/14 11:42 AM INDEPTH

us in the context of infrastructure, languages. However, at scale and but more usual in the context of complexity, human stories are already Web pages. Its strengths are that so hard to tell that the promise it applies equally to human and approach becomes necessary. machine systems, and that it enforces a discipline of documenting the Configuration Management information necessary and sufficient The way we view the world in Promise to implement a design as promises. Theory is as a collection of agents or It is literally actionable (executable) nested containers of things that can keep documentation. One can easily promises. These containers could be: convert to a complementary promise view by changing: Q A part of a file.

"YOU MUST (NOT)..." ---> "I PROMISE TO (NOT) ..." Q A file.

A side effect of documenting the Q A directory (of files). necessary and sufficient conditions for a purpose is that one sees all of Q A partition (of directories). the possible failure modes of a design enumerated as promises: “what if Q A container (or logical partition). that promise is not kept?” Autonomy guarantees no hidden assumptions. Q A virtual machine (or logical machine). The main challenge faced in this view is how to see the desired effect Q A local area network (of machines), etc. emerge from these promises. What story do we tell about the system? In The reference software with this imperative programming languages, KIND OF THINKING IS STILL #&%NGINE the linear story is the code itself. (version 3), as it was designed However, in a promise language, the explicitly in this model, though human story is only implicit in a set of several software systems work in an enabling promises. We have to tell the implicitly promise-oriented fashion. story of what happened differently. Promise thinking permeates the world For some, this is a difficult transition of networking too, where autonomy to make, in the noble tradition of is built into the modus operandi of Prolog and Lisp and other functional the devices. Other examples where

94 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 94 7/23/14 11:42 AM INDEPTH

promises are made to users include the route to scalability. interfaces and APIs, microservices or Autonomy and standalone thinking Service Oriented Architecture (SOA). seem to fly in the face of what we normally learn about programming— Knowledge-Oriented Service Design that is, to share resources, but this Promises turn design and configuration is not necessarily true. Security into a form of knowledge and scalability both thrive under management, by shifting the attention autonomy, and complexity melts away away from what changes (or which when the dependencies between algorithms to enact), onto what parts are removed and all control is interfaces exist between components from within. The near future world and what promises they keep and of mobile and embedded devices will why. The service-oriented style of not tolerate a remote-control model programming, made famous by of management, and the sprawl of the Amazon and Netflix, uses this approach cloud’s server back end will force us for scalability (not only machine to decentralize 3-D-printed micro-data scalability but for scaling human centers, like the electricity substations ownership). It is hailed as a cloud- of today. In this world, I think we can friendly approach to designing systems, expect to see more of the autonomous but Promise Theory also tells us that thinking pervading society.Q it is the route to very large scale. Applications have to be extensible Mark Burgess is the founder, CTO and original author of CFEngine. by cooperation (sometimes called Formerly Professor of Network and System Administration at horizontal scaling through parallelism Oslo University College, he led the way in theory and practice rather than vertical scaling through of automation and policy-based management for 20 years. brute force). Databases like Cassandra In the 1990s, he underlined the importance of idempotent, illustrate how to deal with the issues of autonomous desired state management (“convergence”) scale, redundancy and relativity. and formalised cooperative systems in the 2000s (“promise Perhaps interestingly, biology theory”). He is the author of numerous books and papers on has selected redundant services as Network and System Administration. its model for scaling tissue-based organisms. This offers a strong clue that we are on the right track. Send comments or feedback via Avoiding strong dependencies is a way http://www.linuxjournal.com/contact to avoid bottlenecks, so this shows or to [email protected].

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 95

LJ244-Aug2014.indd 95 7/23/14 11:42 AM INDEPTH Integrating Trac, Jenkins and Cobbler— Customizing Linux Operating Systems for Organizational Needs Developing packages for distributions has been entrusted to distribution maintainers for many years. However, organizations can support their own custom modifications to their favorite distribution. Using methods and tools from the distribution and the broader Open Source community, EMSL (Environmental Molecular Sciences Laboratory) has developed a process to build, develop and validate creation of RPMs to be included with the Scientific Linux distribution deployed on HPC systems. This process helps EMSL meet the HPC users’ needs with rapid turnaround while managing communication between end user and package development. DAVID BROWN

Organizations supporting Linux In practice, bugs and security operating systems commonly have a concerns reported by customers will need to build customized software be prioritized to appropriate levels to add or replace packages on for the distribution maintainers production systems. This need comes who are trying to support all their from timing and policy differences customers. This means that customers between customers and the often need to support patches to fill upstream distribution maintainers. the gap, especially for unique needs,

96 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 96 7/23/14 11:42 AM INDEPTH

until distribution maintainers resolve pieces of software that can be filled THE BUGS %ND3OAP"OX by Trac (http://trac.edgewall.org), Customers who desire to fill Cobbler (http://www.cobblerd.org) the support gap internally should and Jenkins (http://www.jenkins-ci.org). choose tools that the distribution However, these pieces of software maintainers use to build packages do not fill all the gaps present whenever possible. However, from downloading source code to third-party software packages creation of the overlay repository. often present challenges to Further tools and processes are integrate them into the distribution gained by analysis of the upstream properly. Often these packages do distribution’s package management not follow packaging guidelines process and guidelines. and, as a result, do not support The application of the all distribution configurations or Fedora Packaging Guidelines procedures for administration. These (https://fedoraproject.org/wiki/ packages often require more generic Packaging:Guidelines) and its processes to resolve the improper COUNTERPART %0%, 0ACKAGING 'UIDELINES PACKAGING %ND3OAP"OX!GAIN (https://fedoraproject.org/wiki/ From this point on, the tools and EPEL:Packaging) are good references methods discussed in this article are for how to package software for SPECIFIC TO 2ED (AT %NTERPRISE ,INUX 2(%, BASED SYSTEMS APPROPRIATELY 2(%,  4HESE TOOLS AND METHODS ALSO These guidelines call out specifics work with derivative distributions that often are overlooked by like Scientific Linux or Community first-time packagers. Also, tools %NTERPRISE /3 #ENT/3  3OME OF used in the process, such as Mock the tools do include support for (https://fedoraproject.org/wiki/ distributions based on Debian. Projects/Mock), work well with the However, specifics on implementation software mentioned previously. of the process focus on integration Fedora uses other tools to manage WITH 2(%, BASED SYSTEMS building packages and repositories. The build phase of the process These tools are very specific to Fedora (described in “A Process for packaging needs and are not general Managing and Customizing HPC enough for use in our organization. Operating Systems” in the April This is primarily due to technical  ISSUE OF LJ) requires three reasons and features that I go into in

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 97

LJ244-Aug2014.indd 97 7/23/14 11:42 AM INDEPTH

the Jenkins section of this article. RELIGIOUS TOPIC FOR SOME %VERYONE The rest of this article focuses has their favorite software, and these on implementing Trac, Cobbler, two kinds of systems have more than Jenkins, and the gaps between the enough open-source options out there three systems. Some of the gaps are from which people can choose. I want filled using native plugins associated to focus on the features that we have with the three systems. However, FOUND USEFUL AT %-3, TO SUPPORT OUR others are left to be implemented HPC system and how we use them. using scripts and processes requiring The ticket-tracking system works human interactions. There are well for managing small changes points where human interaction is on production systems. These small required to facilitate communication changes may include individual between groups, and other points critical updates, configuration are where the process is missing a changes and requests from users. well implemented piece of software. The purpose of these tickets is to I discuss setup, configuration and record relevant technical information integration of Trac, Cobbler and about the changes for administrators Jenkins, along with some requests for as well as management. This helps community support. all stakeholders understand the cost and priority of the change. These Trac small changes can be aggregated Trac consists of an issue-tracking into milestones, which correspond system and wiki environment to to outage dates. This provides a support software development starting framework to track what projects. However, Trac also works change happens and when on well for supporting the maintenance production systems. of administrative processes and Trac’s wiki has features that are managing change on production required for the process. The first systems. I’m going to discuss is the ability to maintain a history the mapping to apply a software of changes to individual pages. This development process to the is ideal for storing documents and process by which one administers a procedures. Another feature is the production system. ability to reference milestones from I realize that talking about issue within pages. This feature is extremely tracking and wiki software is a useful, since by entering a single

98 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 98 7/23/14 11:42 AM INDEPTH

line in the wiki, it displays all tickets it. Some exceptions are when associated with the milestone in one tickets are considered resolved simple line. These two features help but are waiting for integration maintain the procedures and outage testing. Automated tests could pages in the wiki. be triggered by the ticketing The administrative procedures are system when the ticket’s state is documented in the wiki, and they changed. However, mapping these include but are not limited to software sorts of features to administrative configuration, startup, shutdown procedures for managing production and re-install. The time required systems do not apply. to perform these administrative procedures also should be noted Cobbler in the page. We also make sure Cobbler works well for synchronizing to use the plain-text options for RPM-based repositories and using specifying commands that need to those repositories to deploy systems. be run, as other fonts may confuse The RPMs are synchronized daily readers. In many cases, we have from Jenkins and distribution specified the specific command to maintainers. The other important run in these procedures. For complex feature is to exclude certain systems, creating multiple pages for packages from being synchronized a particular procedure is prudent. locally. These features provide a However, cross links between pages platform to deploy systems that should be added to note when one have specific customized packages part of the procedure from each page for use in the enterprise. should be followed. The initial setup for Cobbler is to Trac’s plugin infrastructure does copy the primary repositories for not have plugins to Jenkins or the distribution of your choice to Cobbler. However, what would be “repos” in Cobbler. The included the point of a plugin going from repositories from Scientific Linux are Trac to continuous integration the base operating system, fastbugs or provisioning? Most software and security. Other distributions have development models keep similar repository configurations ticket systems limited to human (see the Repositories and Locations interaction between the issuer of sidebar). The other repository to the ticket and the people resolving INCLUDE IS %0%, AS IT CONTAINS -OCK

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 99

LJ244-Aug2014.indd 99 7/23/14 11:42 AM INDEPTH

Repositories and Locations Q %XTRA 0ACKAGES FOR %NTERPRISE ,INUX http://dl.fedoraproject.org/pub/epel/6/x86_64 Q Scientific Linux 66 Base: http://ftp1.scientificlinux.org/linux/scientific/6/x86_64/os Q Scientific Linux 6 Security: http://ftp1.scientificlinux.org/linux/scientific/6/x86_64/updates/security Q Scientific Linux 6 Fastbugs: http://ftp1.scientificlinux.org/linux/scientific/6/x86_64/updates/fastbugs Q CentOS 6 Base: http://mirror.centos.org/centos/6/os/x86_64 Q CentOS 6 FastTrack: http://mirror.centos.org/centos/6/fasttrack/x86_64 Q CentOS 6 Updates: http://mirror.centos.org/centos/6/updates/x86_64 Q 2(%,  3ERVER "ASE RHEL X? SERVER  CHANNEL Q 2(%,  3ERVER &AS4RACK RHEL X? SERVER FASTRACK  CHANNEL Q 2(%,  3ERVER /PTIONAL RHEL X? SERVER OPTIONAL  CHANNEL Q 2(%,  3ERVER /PTIONAL &AS4RACK RHEL X? SERVER OPTIONAL FASTRACK  CHANNEL Q 2(%,  3ERVER 3UPPLEMENTARY RHEL X? SERVER SUPPLEMENTARY  CHANNEL

and other tools used to build RPMs. synchronize from a local filesystem, There are other repositories that the “breed” should be set to individual organizations should look rsync, while daily repositories that into, although these four repositories synchronize from the Web should are all that is needed. set their “breed” to yum. This The daily repositories either are configuration, through experience, downloaded from the Web on a daily has been chosen because some basis or synchronized from the local RPMs do not upgrade well with filesystem. The daily repositories get new kernels nor do they have the “keep updated” flag set, while standard update processes normal the test and production repositories to Red Hat or Fedora. do not. For daily repositories that An example of a set of repositories

100 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 100 7/23/14 11:42 AM INDEPTH

Jenkins is a very powerful continuous integration tool used in software development. However, from a system administration view, Jenkins is a mutant cron job on steroids.

would be as follows: options” flags are set on the daily repository to remove them. For Q PHI  X? DAILY ˆ SYNCHRONIZES example, to exclude the kernel package automatically from the local from from being synchronized, add filesystem using rsync once daily. exclude=kernel*. It’s important for administrators to consult both the Q EPEL  X? DAILY ˆ SYNCHRONIZES Cobbler and yum.conf man pages to automatically from the Web using get the syntax right. reposync once daily. Setting up Cobbler in this way allows administrators to deploy systems using Q PHI  X? TEST ˆ SYNCHRONIZES customized critical packages. Cobbler MANUALLY FROM PHI  X? DAILY also is used in future phases where using rsync. the repositories are used to deploy the test and production clusters. The Q EPEL  X? TEST ˆ SYNCHRONIZES repositories and their relationships are MANUALLY FROM EPEL  X? DAILY all Cobbler needs to support package using rsync. building, the test cluster and the production cluster. Q PHI  X? PROD ˆ SYNCHRONIZES MANUALLY FROM PHI  X? TEST Jenkins using rsync. Jenkins is a very powerful continuous integration tool used in software Q EPEL  X? PROD ˆ SYNCHRONIZES development. However, from a MANUALLY FROM EPEL  X? TEST system administration view, Jenkins using rsync. is a mutant cron job on steroids. Jenkins handles periodic source To exclude critical packages from code checkout from source code the upstream distribution, the “yum management (SCM) repositories and

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 101

LJ244-Aug2014.indd 101 7/23/14 11:42 AM INDEPTH

Table 1. Packaging vs. Development

SOFTWARE DEVELOPMENT RPM PACKAGING Download source code from SCM. Download released source, spec file and patches. Run the build process. Build the RPMs using Mock. Run the testing suite. Validate the RPMs using rpmlint. Publish test results. Save validation output for inspection. Save source code package to repository. Save built RPMs for later download. Send notification to pertinent developers. Send notification to pertinent packagers.

downloading of released source code, to an S3 (http://docs.aws.amazon.com/ via HTTP or FTP. It then runs a series AmazonS3/latest/API/Welcome.html), of generic jobs that build, test and swift (http://docs.openstack.org/api/ deploy the resulting software. These openstack-object-storage/1.0/content) generic interfaces work well for or blob store-like interface. building and distributing RPMs to be Jenkins is built primarily for included by Cobbler. downloading code from one and only The use of Jenkins in a software one SCM. However, you can work development role is not all that different around this issue by adding another from building RPMs (see Table 1 for build step. This means that the SCM a comparison of the two processes). plugin is used to download the spec The first step in the two processes file and patches while the first step differs in that (hopefully) the software in the build process downloads the development code required for the build source code package. After these step is in one place. Package developers two steps are done, the source code, need to have, at a minimum, two patches or spec file can be patched locations to pull code from to continue with site-specific customization. with the build. The first location is for The next step is to build RPMs using patches and spec files, normally kept Mock. This involves several tasks that in an SCM. The second is for released can be broken up into various build source code packages. Source code is steps (see the Mock Build in Jenkins released in a single file and usually in sidebar). All these steps are done some container format (such as tar, using the Jenkins execute shell build rar or zip). These files do not normally steps. Some of the Jenkins jobs we belong in an SCM and are more suited use are multi-configuration jobs that

102 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 102 7/23/14 11:42 AM INDEPTH

Listing 1. basic-mock-jenkins.sh #!/bin/bash -xe

# keep in mind DIST is defined in multi-configuration axis MOCK="/usr/bin/mock -r $DIST" PKG=${JOB_NAME##*/} # keep in mind VER could also be a multi-configuration axis VER=${VER:-1.0} # if you are ripping apart an RPM might have this one too REL=${REL:-4.el6}

OUT=$PWD/output

wget -O $PKG-$VER.tar.gz ´http://www.example.com/sources/$PKG-$VER.tar.gz rm -f $OUT/*.src.rpm if ! $MOCK --resultdir=$OUT --buildsrpm --spec=$PKG.spec ´--sources=$PWD then more $OUT/*.log | cat exit -1 fi

if ! $MOCK --resultdir=$OUT --rebuild $OUT/*.src.rpm then more $OUT/*.log | cat exit -1 fi

rpmlint $OUT/*.rpm > rpmlint.log

contain one axis defining the Mock chroot configuration. That Mock Build in Jenkins chroot configuration should 1. Prepare the source and specs. be generated from the daily repositories defined in Cobbler. 2. Run Mock source rpm build. Following these tasks can get 3. Run Mock rpm build. you started on using Mock in 4. Run rpm validation. Jenkins (Listing 1).

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 103

LJ244-Aug2014.indd 103 7/23/14 11:42 AM INDEPTH

The number of warnings and errors should be tracked, counted and graphed over a series of builds. This gives a good indication whether bugs are being resolved or introduced over time.

Once the RPMs are built, it’s There also is an artifact deployer important to run rpmlint on the plugin that can copy the artifacts resulting RPMs. This output gives to directories that Cobbler can be useful advice for how to package configured to synchronize from for its RPMs properly for the targeted part of the process. platform. This output should be There is some room for handled like any other static code improvement in this process, and analysis tool. The number of warnings I outline that in the conclusion. and errors should be tracked, counted However, this is the basic framework and graphed over a series of builds. to start using Jenkins to build RPMs This gives a good indication whether using Mock and rpmlint. This part of bugs are being resolved or introduced the process needs constant care and over time. attention as new updates are pushed The generated RPMs and rpmlint by the distribution and package output need to be archived for future developers. Jenkins does have plugins use. The archive artifacts plugin to Trac and other issue-tracking works well for capturing these files. systems. However, they are not

Table 2. Software

ROLE SOFTWARE CHOICE Continuous Integration Jenkins Repository Management Cobbler Provisioning Cobbler Ticket Tracking Trac Wiki Trac Package Building Mock Package Guidelines Fedora Packaging Guidelines

104 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 104 7/23/14 11:42 AM INDEPTH

included in this process, as we find not seen traction in years. Package e-mail to be a sufficient means of development is another good example communication. The outlined process of the need to download and poll for for building RPMs using Jenkins updates on code from multiple places. helps us track the hacks we use to Here are links to information on the manipulate important packages for Jenkins Multiple SCMs Bugs: our systems. Q https://issues.jenkins-ci.org/ Conclusion browse/JENKINS-7192 I have discussed a method for setting up tools to develop RPMs against Q https://issues.jenkins-ci.org/ a custom distribution managed by browse/JENKINS-9720 Cobbler. Along with Trac, package developers can maintain updated Static code analysis tools are RPMs of critical applications while available as plugins for Jenkins managing communication. However, (https://wiki.jenkins-ci.org/display/ this process is not without gaps. JENKINS/Violations), although these First, I’ll go over the gaps present in plugins do not include rpmlint. These Jenkins, discussing core and plugin plugins create graphs to track the gaps that were not found. Then I’ll number of warnings and errors in code discuss the gaps in Cobbler regarding over time. To perform the same task repository management. These two for packaging would be very helpful. systems are lacking in integration, However, you can work around this although that can be worked around. gap by using the generic plot plugin MultiSCM is a functionality (https://wiki.jenkins-ci.org/display/ in Jenkins that would simplify JENKINS/Plot+Plugin) and another the package building process. build step for each job. There is a MultiSCM plugin Mock has a very well defined (https://wiki.jenkins-ci.org/display/ interface and workflow. A generic JENKINS/Multiple+SCMs+Plugin); plugin to use Mock in Jenkins would however, it is advertised as a proof- be very useful. The plugin should of-concept code. The hope is that include configuring the chroot the radio button selection for SCM configuration. Two kinds of build would turn into a set of check boxes. jobs also could be created, one using There are related bugs, but they have spec and source files, the other using

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 105

LJ244-Aug2014.indd 105 7/23/14 11:42 AM INDEPTH

source RPMs. A test also would need plugins to integrate better with Cobbler to be created to verify that Mock can or Jenkins. We have found some be run without prompting for a user usability issues with manipulating large password. This plugin would be very tables in the wiki format. Some plugin helpful for automating this process, to make editing large tables easier in as we currently have to copy scripts the wiki format would be useful for between jobs. us. Also, editing long pages becomes There are some additions to an issue if you cannot put comments Cobbler that would be useful for throughout the page. We validate this process as well. There are no our procedures by having members per-repo triggers. The ability to tell of the group who are unfamiliar Trac that packages went from repo with the system read through the test to repo prod would be useful. procedure. The reader should be able Furthermore, the ability to tell to comment on but not edit parts of Jenkins to build a package because the page. We have worked around or a dependent package updated also found plugins on the Trac Hacks would be useful. page (http://www.trac-hacks.org) The other useful addition to Cobbler to resolve these issues. would be the ability to remove older The final request is for some level RPMs in the destination tree while of certification from distribution synchronizing from the remote mirror. maintainers to certify third-party Cobbler repositories, if the “breed” packages. Many of the third- is yum, build up in an append-only party packages we have applied fashion. Processes for managing to this process to do not support the space may be run periodically all distribution configurations. by removing the RPMs and then A certification from distribution synchronizing the repository again. maintainers validating that software However, this leaves the repository distributed by third-party vendors in a broken state until the process have packaged their software is complete. This feature could be appropriately for the distribution useful in any Cobbler deployment, as would help customers determine it would make sure repositories do not the cost of support. continue to take up space when RPMs This is by no means a complete are not needed. solution for organizations to build Trac does not need any additional customized critical applications.

106 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 106 7/23/14 11:42 AM INDEPTH

There are still gaps in the system Northwest National Laboratory.Q that we have to work around using scripts or manual intervention. We David Brown is a high-performance computing system constantly are working on the process administrator with a B.S. in Computer Science from and tools to make them better, so Washington State University. He has worked at the Pacific any suggestions to improve it are Northwest National Laboratory (PNNL) in the Environmental welcome. However, these tools do fill and Molecular Sciences Laboratory (EMSL) since January the need to support customization of 2007. He also is a Fedora Package Maintainer and supports CRITICAL APPLICATIONS FOR (0# AT %-3, several scientific and administrative packages that are used in HPC environments. He has experience in high-performance Acknowledgement filesystems (Lustre) and cloud technology (OpenStack). The research was performed using %-3, A NATIONAL SCIENTIFIC USER FACILITY SPONSORED BY THE $EPARTMENT OF %NERGYS Send comments or feedback via /FFICE OF "IOLOGICAL AND %NVIRONMENTAL http://www.linuxjournal.com/contact Research and located at Pacific or to [email protected].

LINUX JOURNAL on your Android device Download the app now in the Android Marketplace

www.linuxjournal.com/android

For more information about advertising opportunities within Linux Journal iPhone, iPad and Android apps, contact John Grogan at +1-713-344-1956 x2 or [email protected].

LJ244-Aug2014.indd 107 7/23/14 11:42 AM EOF Can We Stop DOC SEARLS Playing Card Games with Business? Credit cards cause itches for all of us. Let’s scratch them.

friend who works in one of to name names, beyond saying that the big banks recently told much.) First, the retailer’s system A me that any new-fangled for sorting out billing and shipping approach to identity and payments addresses was broken. Then, after I is going to have a hard time getting got over that hurdle (which I suppose traction while credit cards continue to is still there), my credit card was work as well as they do. “Using credit declined. In the course of dealing cards is too easy, too normal, too with both failures, I have pounded entrenched in Business As Usual”, countless numbers and letters, over he said. They used to say the same and over again, into my laptop’s thing about Windows. keyboard and my phone’s screen. On As it happens, I am in the middle top of that, I have had to give the of a credit-card mess right now that last four digits of my social security is certainly normal and Business As number, plus a bunch of other Usual, but far from easy. information, over and over again, See, all I’m trying to do is buy to too many different people at the something on-line, from a retailer credit-card company’s call centers. that’s not Amazon. (I’m not going The credit-card company doesn’t

108 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 108 7/23/14 11:42 AM EOF

know (or seem to care) why my card ideal ratio of coffee and steamed milk. was declined. The attempted purchase It’s also known as a piccolo latte in was not unusual in any way. The some places, such as Australia error message from the retailer was (http://www.cafeculture.com/ also unhelpful. It said, “Something general-interest/what-is-a-piccolo- went wrong when trying to process latte). Try it out. Here is what your payment. Please review the error happens around identity and payment: message and try again: Braintree payment for Order #5283 (Transaction 1. I am anonymous—literally, ID gb3xx6m) was declined: Declined.” nameless. But... For the last several hours, the credit- card company also has been unable to 2. They can see I am a person, with turn off the fraud protection flag that an obvious ability to pay. caused it to decline the purchase in the first place, because its system for 3. They accept payment either via doing that is down. cash or credit card. Several more hours have passed between the last paragraph and this  )F ) USE CASH ITS ALSO ANONYMOUS one, which I’m writing after calling the even though there is a unique credit-card company for the Nth time number on every piece of paper and learning at last that the payment currency. The shop is not interested went through. The retailer’s system, in those numbers. however, still says “awaiting payment”. I don’t know if any of the new ideas 5. If I use a card, they do not care for solving this kind of mess are going about the name on the card or to succeed. Most of them probably the number. All they care about won’t. But I do believe the only is whether the payment goes answers that will finally work are ones through. In other words, they are that give us ways to be known in the not burdened with any details virtual world that resemble the ways about me. (I am purposely keeping we are known in the physical one. loyalty cards and other marketing For a base-level model of that, let’s gimmicks off the table here. I’ll say I go into coffee shop and order explain why below.) a cortado (http://en.wikipedia.org/ wiki/Cortado). A cortado has the 6. If they ask for a name, it’s only so

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 109

LJ244-Aug2014.indd 109 7/23/14 11:42 AM EOF

they can call it out when the drink On the whole, we have positive is ready. Not for any other reason. sum outcomes from the game played with credit cards. But there is a 7. That’s it. degree of entrapment to that game as well. We are not equals, and we Now, let’s say this is a coffee shop do not enjoy full agency. where I am already known to the This is not the fault of the people behind the counter. Here the credit-card system, but of mass only difference is that I might be marketing’s obsolete methods and extended some friendly courtesies. If assumptions, which date back to the people are honorable, I can expect the time when Industry won the that they won’t be out to screw Industrial Revolution. In order to me—for example, by giving or selling get scale—to market to masses— information about me to people or it was necessary for companies to systems I don’t know. treat many customers the same There are permissions and way, as populations rather than as agreements, casual and formal, on INDIVIDUAL HUMAN BEINGS %VEN IN THE both sides of this system, and they Internet Age, attempts by business to have been in the vernacular of every “personalize” and “mass customize” market since the dawn of commerce. relations with customers are made by When this system works well, there business—not by the customer. is also no power asymmetry—or And, because business mostly at least not one being exploited. talks only to itself about this The customer and the shop meet stuff, it is easy for business to as equals in the marketplace. They rationalize negative externalities trust each other. This trust has a (http://economics.fundamentalfinance. high degree of leverage toward com/negative-externality.php). Among future business between both those externalities are: parties. In terms of game theory (http://www.beyondintractability. 1. Wastes heaped by others—for org/essay/prisoners-dilemma), example, all the promotional crap that leverage is toward positive that fills communication channels sum (aka win-win) outcomes and brings no positive response (http://www.beyondintractability.org/ (in other words, 99.x% of all essay/sum). promotional messages).

110 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 110 7/23/14 11:42 AM 2. Inconveniences—such as the need by users and customers Advertiser Index to authenticate in separate and Thank you as always for supporting our arcane ways with every different advertisers by buying their products! company’s different system.

3. Resentments and other bad ADVERTISER URL PAGE #

feelings by users and customers Chef http://getchef.com 2, 37

toward both of the above, plus Drupalize.me HTTPWWWDRUPALIZEME  knowledge that they are being EmperorLinux HTTPWWWEMPERORLINUXCOM  spied upon and manipulated in ways they cannot escape without Fossetcon 2014 http://fossetcon.org 113 giving up relationships they can’t High Performance http://www.flaggmgmt.com/hpc/ 7 Computing Shows 2014 or won’t do without. Silicon Mechanics http://www.siliconmechanics.com 3

 #OMPANIES NEEDING TO MAINTAIN SPTechCon HTTPWWWSPTECHCONCOM  or hire the large and expensive server farms and “big data” crunching systems to process and make decisions on personal data ATTENTION ADVERTISERS gained by surveillance and fed The Linux Journal brand’s following has back to #1, above. grown to a monthly readership nearly one million strong. Encompassing the All those negative externalities magazine, Web site, newsletters and afflict the commercial Web today—and much more, Linux Journal offers the are spreading into brick-and-mortar ideal content environment to help you retailing as well. We see this with loyalty reach your marketing objectives. For programs (http://en.wikipedia.org/ more information, please visit wiki/Loyalty_program) that give http://www.linuxjournal.com/advertising. us additional cards and key tags to carry around. These externalities exist to a far lesser degree with credit cards than they do with marketing gimmicks (because credit cards’ purposes are

WWW.LINUXJOURNAL.COM / AUGUST 2014 / 111

LJ244-Aug2014.indd 111 7/23/14 11:42 AM EOF

mostly restricted to transactions), but new projects that start with are still present with credit cards, as the customer and move toward we see with my own story, above. business. I’m involved in many %INSTEIN IS SAID TO HAVE SAID h4HE of those, through ProjectVRM significant problems we face cannot (http://blogs.law.harvard.edu/vrm). be solved at the same level of thinking (Here is a partial list of developers: we were at when we created them” http://cyber.law.harvard.edu/ (http://en.wikiquote.org/wiki/ projectvrm/VRM_Development_Work.) Albert_Einstein). I can remember And, I consult some of those formally like it was yesterday the feeling of as well. But I won’t name any, because I futility I had when I was doing work want clean new Linux geek thinking and for Sun Microsystems, back in the code-writing applied to this problem. 1980s, enduring the torture of sitting Here’s the main challenge: not in meetings where the pointless topic using cards at all. Bitcoin was “fixing” UNIX, which had a (http://en.wikipedia.org/wiki/ zillion variants, most of which were Bitcoin) is the biggest breakthrough owned by somebody, including Sun. in that direction, so far—or at least There was no way UNIX’s problems the one with the most geek interest. could be solved at that level. We What else have we got—or could needed Gnu and Linux to solve it. we have? The answers will come, (And yes, the BSDs too.) That’s how I because there’s a huge itch here. feel today about trying to fix identity So tell me who’s scratching and payments inside the current what, and how. I’d rather salute mass-marketing system. those than complain more about The level at which we need to Business As Usual.Q solve identity and payments is the individual one. It needs to happen Doc Searls is Senior Editor of Linux Journal. He is also a on our side. We’re the ones who fellow with the Berkman Center for Internet and Society at need to manage our identities, how Harvard University and the Center for Information Technology we pay for stuff, what information and Society at UC Santa Barbara. we hand over when we pay for things, and how we control our side of relations with the retailers and Send comments or feedback via service providers of the world. http://www.linuxjournal.com/contact Today there are already many or to [email protected].

112 / AUGUST 2014 / WWW.LINUXJOURNAL.COM

LJ244-Aug2014.indd 112 7/23/14 11:42 AM FREE AND OPEN SOURCE SOFTWARE EXPO AND TECHNOLOGY CONFERENCE

2014

Come out and participate in the First Annual Fossetcon 2014 Florida's Only Free and Open Source Conference. With in 10 minutes of Disney Land, Universal Studios and Epcot Center.

Food, Training, Day 0 Workshops and Certifications

Food, Keynotes, Expo Hall, Day 1 BSD Speaker Tracks Friendly Food, Keynotes, Expo Hall, Day 2 Speaker Tracks

Free Food, Training, Certifications and Giveaways!!! SEPT 11 - SEPT 13 ROSEN PLAZA HOTEL ORLANDO, FL Fossetcon 2014: The Gateway To The Open Source Community powered by:

More info at www.fossetcon.org

LJ244-Aug2014.indd 113 7/23/14 11:42 AM Instant Access to Premium Online Drupal Training

Instant access to hundreds of hours of Drupal training with new videos added every week!

Learn from industry experts with real world H[SHULHQFHEXLOGLQJKLJKSURȴOHVLWHV

Learn on the go wherever you are with apps for iOS, Android & Roku

We also offer group accounts. Give your whole team access at a discounted rate!

Learn about our latest video releases and RIIHUVȴUVWE\IROORZLQJXVRQ)DFHERRNDQG 7ZLWWHU #GUXSDOL]HPH 

Go to http://drupalize.me and get Drupalized today!

LJ244-Aug2014.indd 114 7/23/14 11:42 AM