LXJ 245
LXJ 245
AN IN-DEPTH
LOOK AT
ZFS vs.
BTRFS
Since 1994: The Original Magazine of the Linux Community SEPTEMBER 2014 | ISSUE 245 | www.linuxjournal.com
+
Check Your Exchange InBox
from the Command Line
12-Factor,
Scalable,
Maintainable
WEB APPS
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:
HOW-TOs
FEATURES
62 Provisioning X.509 74 Synchronize Your Life
Certificates Using RFC 7030 with ownCloud
Enrollment over Secure Transport, Access your data from anywhere
easing the pain of provisioning with ownCloud.
X.509 certificates. Mike Diehl
John Foley
ON THE COVER
(U 0U+LW[O 3VVR H[ A-: HUK );9-: W
,HZL [OL 7HPU VM 7YV]PZPVUPUN ? *LY[PMPJH[LZ W
:`UJOYVUPaL @V\Y 3PML ^P[O V^U*SV\K W
*OLJR @V\Y ,_JOHUNL 0UIV_ MYVT [OL *VTTHUK 3PUL W
WP^LIHNLU[! H +LZR[VW ,U]PYVUTLU[ MVY [OL 9HZWILYY` 7P W
+5:4HZX! H /LYV MVY :LY]LYZ W
6WLU(_PVT! H *VTW\[LY :`Z[LT MVY (SNLIYH W
COLUMNS
30 Reuven M. Lerner’s At the Forge
12-Factor Apps
50 Shawn Powers’
The Open-Source Classroom
DNSMasq, the Pint-Sized
Super Dæmon!
IN EVERY ISSUE
8 Current_Issue.tar.gz
10 Letters
16 UPFRONT
28 Editors’ Choice
58 New Products
109 Advertisers Index 94
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.
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
Advertising
E-MAIL: [email protected]
URL: www.linuxjournal.com/advertising
PHONE: +1 713-344-1956 ext. 2
Subscriptions
E-MAIL: [email protected]
URL: www.linuxjournal.com/subscribe
MAIL: PO Box 980985, Houston, TX 77098 USA
T
IEX Group, formerly with Speaker on the
his 11th Annual HPC networking opportunity will assemble 600 Wall Street IT the SEC Regulatory Divi- Code Writing Panel
professionals, code writers and programmers at one time and one place in New York. sion of Trading & Markets
Visit: www.flaggmgmt.com/hpc
Modeling, Bloomberg Officer, CodeFutures,
Speaker on the
Code Writing Panel
Current_Issue.tar.gz
Do That?
O
pen-source advocates tend to follows with some smarter code for
make for rotten magicians. solving the “how many days have
Whereas most illusionists passed” script he’s been working
insist on taking their secrets to the with for the past few months.
grave, we tend to give away the secret All too often, our perfectly crafted
sauce to anyone who’ll listen. Heck, solutions get ruined by someone
sometimes we create things just so changing something outside our
we can explain to others how they control. Kyle Rankin recently had
work! And, that is how this issue was an issue with his fetchmail setup,
born. We love the How-To concept. and he walks through the process of
Heck, our entire magazine is based troubleshooting and problem solving
on the idea of spreading knowledge, when someone changes the rules.
and this month, we specifically go If, like me, you’re a fan of Kyle’s
out of our way to show not only the passion for the command line, you’ll
result, but the “How” as well. appreciate his efforts to maintain his
Reuven M. Lerner starts us off ASCII lifestyle.
with a discussion of 12-Factor Apps. I made true on my promise to get
He basically describes a process for a little more serious this month and
developing scalable, maintainable wrote about DNSMasq. It’s not a new
Web applications. As someone program, but it’s so powerful and
who recently started creating Web so simple, it’s often overlooked as
apps, I can attest that they get a viable option for serving DNS and
unmanageable quickly! Dave Taylor DHCP. Although most people are fine
with running DNS and DHCP from
VIDEO: their off-the-shelf routers, there are
V
Vim Macros
Regarding Kyle Rankin’s “The Only
Mac I Use” article in the July 2014
issue: I knew all about macros. What
I didn’t know was what <ctrl>-a did.
That is going to save me so much
time in the future.
—Rick
2014 issue, I think he has a big test. Got a much better one in the next
problem with the valid_date.sh way column. Thanks for writing in, Harrie!
of checking for leap year:
Harrie Wijnans replies: Yeah, my
harrie@v1:~> /lj243_valid_date sh 2 29 1776 solution, of course, fails for the year 29.
checking for feb 29 : was 1776 a leap year? Adding tail solves that (and the -w flag
Yes 1776 was a leapyear so February 29 1776 is a valid date for grep has no real meaning anymore):
harrie@v1:~> /lj243_valid_date sh 2 29 1929
checking for feb 29 : was 1929 a leap year? leapyear=$(cal 2 $year | tail +3 | grep -w 29)
if [ ! -z "$leapyear" ] then With this test, you can see that 1932
echo "Yes $year was a leapyear so February 29 $year \ was a leap year, but 1929 wasn’t.
is a valid date "
Dave Taylor replies: Yup, someone else That is, for the date on my Linux
also pointed out the flaw in my leap year (openSUSE 12.1), and it also fails
struct tm
the cleanest version of all of this: int tm_sec; /* Seconds. [0-60] (1 leap second) */
# If you have GNU date on your Linux system this is superior: int tm_mon; /* Month. [0-11] */
# If you don't have GNU date (Mac OS X doesn't for example) int tm_yday; /* Days in year.[0-365] */
then, because I also have date 8.4, long int _ _tm_gmtoff; /* Seconds east of UTC. */
#endif
366
$ date -d 12/31/1810 +%j Apparently, openSUSE library does not
365 accept the year field to be <= 0. Sorry,
I’m lost here. I’m not that experienced
in Linux C programming, and LJ, I followed the link to the new Letters
lib/parse-datetime.y even uses bison, “page” to find just two letters there.
which I hardly ever used. There always were more when they were
included in the magazine (print and of
Beware of the cal -j you gave as an course digital). Only two! I cannot believe
example. Try it for 2000, which is missed that LJ readers have been that quiet.
as a leap year. (Are we lucky it was a leap —Roy Read
year? Otherwise, the “millennium-bug”
would have been much more severe.) The past couple months, we’ve been
experimenting with moving Letters
This is because there, 366 is at the to the Editor to the Web, or at least
start of the line, so there are no char- partially to the Web. We received a
acters in front of it, hence it does not lot of feedback, and so we have put
match [^12]366 . An extra -e ^366 things back the way they used to
would solve that and still not see
1366 or 2366 as leap years; 366 still
would be considered a leap year.
Library
LANG=nl_NL.UTF8 cal 2 2012 or
fr_FR.UTF8 —no February in there.)
on
I’d say, the person who claims creating LinuxJournal.com
scripts for everyone and every environ-
ment is simple, never tried it.
Letters?
It is 19.48 GMT on 9 July 2014. I only say
this in case at this point in time there is
a problem with your system. Reading my www.linuxjournal.com/whitepapers
Dave Taylor replies: Thanks for the leapyear=$(date -d 12/31/$1 +%j | grep 366)
update. It’s been a while since I had
access to a Solaris system! A different approach, for sure! Thanks
for writing.
Bug in Dave Taylor’s Days
Between Dates Script Digital Encryption and a Random
Dave’s leap year test in the July 2014 Bit Generator
issue contains a little bug. He uses: A printable poster of an unbreakable
Solaris 8 was actually released in 2000, not 2004. Your monthly download notifications
will have links to the various formats
—Peter Schow and to the digital archive. To access the
digital archive at any time, log in at
http://www.linuxjournal.com/digital.
Dave Taylor replies: Bah, and I looked it up LETTERS TO THE EDITOR: We welcome your
letters and encourage you to submit them
on-line too. Thanks for the update. Now for the at http://www.linuxjournal.com/contact or
real question: are you still running it, Peter? mail them to Linux Journal, PO Box 980985,
Houston, TX 77098 USA. Letters may be
edited for space and clarity.
Peter Schow replies: No, I run the latest-and- WRITING FOR US: We always are looking
for contributed articles, tutorials and
greatest Solaris, but there are stories about real-world stories for the magazine.
An author’s guide, a list of topics and
Solaris 7 (~1998) still in production out there. due dates can be found on-line:
http://www.linuxjournal.com/author.
send us your comments and feedback via ADVERTISING: Linux Journal is a great
resource for readers and advertisers alike.
http://www.linuxjournal.com/contact. Request a media kit, view our current
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.
diff -u
WHAT’S NEW IN KERNEL DEVELOPMENT
Sometimes a new piece of code was tolerable for each data packet.
turns out to be more useful than its David Lang also liked Cryogenic
author suspected. Alejandra Morales and agreed that it should go into
recently came out with the Cryogenic the core input/output system. He
Project as part of his Master’s thesis, added that a lot of other folks had
supervised by Christian Grothoff. attempted to accomplish similar
The idea was to reduce energy things. It was a highly desired feature
consumption by scheduling input/ in the kernel. David also pointed out
output operations in batches. that in order to get into the core
This idea turned out to be so good input/output system, the Cryogenic
that H. Peter Anvin didn’t want code would have to demonstrate that
Cryogenic to be a regular driver, it had no performance impact on code
he wanted it to be part of the core that did not use its features, or that
Linux input/output system. On the the impact would be minimal.
other hand, he also felt that the Luis R. Rodriguez recently
programmer interface needed to be pointed out that a lot of drivers were
cleaned up and made a bit sleeker. routinely backported to a large array
Pavel Machek also was highly of older kernels, all the way down
impressed and remarked that this to version 2.6.24. And although he
could save power on devices like acknowledged that this was currently
phones and tablets that were manageable, he expected the number
always running low. And, Christian of drivers and other backportable
confirmed that this was one of the features to continue to increase,
main goals of the code. making the situation progressively
Christian added that power more difficult to sustain.
savings seemed to be on the order of Luis said the kernel folks should
10%, though that number could be do more to educate users about
tweaked up or down by increasing or the need to upgrade. But, he also
decreasing the amount of delay that wrote up a recommendation that
the kernel folks use Coccinelle to limit the number of target kernels.
automate the backporting process It turns out Windows does certain
(http://www.do-not-panic.com/2014/04/ things better than Linux—for example,
automatic-linux-kernel-backporting- in the area of rebooting. Apparently,
with-coccinelle.html). there are several techniques that
Coccinelle is a tool used to transform can be done in software to cause
source code programmatically. It can a system to reboot. But in some
be used to generate changes to earlier cases, the Linux system will go down
kernel code to match the functionality successfully, and then not come up
provided by newer patches. That’s so again. This is a problem, for example,
crazy, it just might work! in server farms with minimal human
But to get started, Luis wanted staff. If 20 systems are acting up and
to draw a line between kernels that you want to reboot them all, it’s easier
would receive backports and kernels to give a single command from a
that would not. Hopefully, that line remote terminal than to send a human
would only move forward. So he out into the noise and the cold to
asked the linux-kernel mailing list press each reset button by hand.
members in general to tell him which One rebooting technique involves
were the earliest kernels they really sending certain values to the 0xCF9
needed to keep using. port on the system. Another is to use
As it turned out, Arend van Spriel the EFI (Extensible Firmware Interface)
knew of Broadcom WLAN testers BIOS replacement from Intel.
that still relied on Fedora 15, running Depending on the circumstances, one
the 2.6.38 kernel. He said he was or the other rebooting technique is
working with them to upgrade to preferred, but the logic behind that
Fedora 19 and the 3.13 kernel, but selection can be tricky. In particular,
that this hadn’t happened yet. changing the state of various pieces of
So it appears that a certain hardware can change the appropriate
amount of backporting will become reboot technique. So, if you run
automated, but of course, the through a series of reboot attempts,
Coccinelle transformations still would and somehow change hardware state
need to be written and maintained by along the way, you can find that none
someone, which is why Luis wanted to of the attempts can succeed.
The cool thing about this fixes some machines. We know that
particular bug is the straightforward it breaks some machines. We don’t
way Linus Torvalds said that know how many machines it fixes or
Windows must be doing something how many machines it breaks. We
right, and that the Linux people don’t know how many machines are
needed to figure out what that was flipped from a working state to a
so Linux could do it right too. broken state whenever we fiddle with
Steven Rostedt pointed out the the order or introduce new heuristics.
boot failure in one of his systems, We don’t know how many go from
and this triggered the bug hunt. broken to working. The only way
Part of the problem is that it’s very we can be reasonably certain that
difficult to understand exactly what’s hardware will work is to duplicate
going on with a system when it precisely what Windows does,
boots up. Strange magical forces are because that’s all that most vendors
apparently invoked. will ever have tested.”
During the course of a somewhat But, Linus Torvalds felt that
heated debate, Matthew Garrett ditching CF9 was equivalent to
summed up what he felt was the flailing at the problem. In the course
underlying issue, and why the problem of discussion he said, “It would
was so difficult to solve. In response to be interesting if somebody can
any of the various bootups attempted, figure out exactly what Windows
he said, “for all we know the firmware does, because the fact that a lot of
is running huge quantities of code Dell machines need quirks almost
in response to any of those register certainly means that it’s us doing
accesses. We don’t know what other something wrong. Dell doesn’t
hardware that code touches. We don’t generally do lots of fancy odd
know what expectations it has. We things. I pretty much guarantee it’s
don’t know whether it was written because we’ve done something odd
by humans or written by some sort of that Windows doesn’t do.”
simulated annealing mechanism that The discussion had no resolution—
finally collapsed into a state where probably because it’s a really tough
Windows rebooted.” problem that hits only a relatively
Matthew was in favor of ditching small number of systems. Apparently
the 0xCF9 bootup technique entirely. the bug hunt—and the debate—will
He argued, “We know that CF9 continue. —ZACK BROWN
Lucidchart
OpenAxiom
Several computer algebra systems OpenAxiom with:
are available to Linux users. I
even have looked at a few of sudo apt-get install openaxiom
them in this column, but for this
issue, I discuss OpenAxiom If you want to build OpenAxiom
(http://www.open-axiom.org). from source, you need to have a
OpenAxiom actually is a fork Lisp engine installed. There are
of Axiom. Axiom originally was several to choose from on Linux,
developed at IBM under the name such as CLisp or GNU Common Lisp.
ScratchPad. Development started Building is a straightforward:
in 1971, so Axiom is as old as I
am, and almost as smart. In the ./configure; make; make install
1990s, it was sold off to the
Numerical Algorithms Group (NAG). To use OpenAxiom, simply execute
In 2001, NAG removed it from open-axiom on the command line.
commercial sale and released it as This will give you an interactive
free software. Since then, it has OpenAxiom session. If you have
forked into OpenAxiom and FriCAS. a script of commands you want to
Axiom still is available. The system run as a complete unit, you can do
is specified in the book AXIOM: the so with:
Scientific Computation System by
Richard Jenks and Robert Sutor. open-axiom --script myfile.input
This book is available on-line at
http://wiki.axiom-developer.org/ where the file “myfile.input”
axiom-website/hyperdoc/axbook/ contains the OpenAxiom commands
book-contents.xhtml, and it to be executed.
makes up the core documentation So, what can you actually do
for OpenAxiom. with OpenAxiom? OpenAxiom has
Most Linux distributions should many different data types. There
have a package for OpenAxiom. are algebraic ones (like polynomials,
For example, with Debian-based matrices and power series) and data
distributions, you can install structures (like lists and dictionaries).
You can combine them into any new type, Fraction Integer . If you
reasonable combinations, like have used a commercial system like
polynomials of matrices or matrices Maple before, this should be familiar.
of polynomials. These data types are OpenAxiom has data types to try
defined by programs in OpenAxiom. to keep results as exact values. If you
These data type programs also have a reason to use a particular type,
include the operations that can be you can do a conversion with the
applied to the particular data type. :: operator. So, you could redo the
The entire system is polymorphic above division and get the answer as
by design. You also can extend the a float with:
entire data type system by writing
your own data type programs. There (4/6)::Float
are a large number of different
numeric types to handle almost any It even can go backward and
type of operation as well. calculate the closest fraction
The simplest use of OpenAxiom is that matches a given float with
as a calculator. For example, you can the command:
find the cosine of 1.2 with:
%::Fraction Integer
cos(1.2)
The % character refers to the most
This will give you the result with recent result that you calculated. The
20 digits, by default. You can change answer you get from this command
the number of digits being used with may not match the original fraction,
the digits() function. OpenAxiom due to various rounding errors.
also will give you the type of this There are functions that allow
answer. This is useful when you are you to work with various parts
doing more experimental calculations of numbers. You can round() or
in order to check your work. In the truncate() floating-point numbers.
above example, the type would be You even can get just the fractional
Float . If you try this: part with fractionPart() .
One slightly unique thing in
4/6 OpenAxiom is a set of test functions.
You can check for oddness and
the result is 2/3 , and you will see a evenness with the functions odd?()
and even?() . You even can check The last feature I want to look at
whether a number is prime with in this article is how OpenAxiom
prime?() . And, of course, you still handles data structures. The most
have all of the standard functions, basic data structure is a list. Lists
like the trigonometric ones, and the in OpenAxiom are homogeneous,
standard operators, like addition so all of the elements need to
and multiplication. be the same data type. You
OpenAxiom handles general define a list directly by putting a
expressions too. In order to use them, comma-separated group in square
you need to assign them to a variable brackets—for example:
name. The assignment operator is
:= . One thing to keep in mind is that [1,2,3,4]
this operator will execute whatever
is on the right-hand side and assign This can be done equivalently with
the result to the name on the left- the list function:
hand side. This may not be what you
want to have happen. If so, you can list(1,2,3,4)
use the delayed assignment operator
== . Let’s say you want to calculate You can put two lists together with
the square of some numbers. You can the append function:
create an expression with:
append([1,2],[3,4])
xSquared := x**2
If you want to add a single element
In order to use this expression, you to the front of a list, you can use the
need to use the eval function: cons function:
mylist.3 oneDimensionalArray([2,3,4,5])
Non-Linux FOSS:
AutoHotkey
“I really enjoyed it. I can hardly wait to get back to work and
September 16-19, 2014
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 going to tell others to go.” SharePoint MVPs and Certified SharePoint Professionals
—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
LINUX JOURNAL
t o understand what Password B o x
allows you to do. When you
i nitially launch it, you’ll be
prompted for how you want t h e
on your
application to handle when i t Android device
l ocks your data and requires y o u Download the
t o retype the master passwo rd . app now in
I deally, this would be “imme d i a t e l y the Android
after you quit the app”, but Marketplace
PasswordBox allows you to
s acrifice security for conveni e n c e
and will stay unlocked anywh e re
f rom 30 seconds to several h o u r s .
I t even will let you rely on yo u r
Android lock screen for secu r i t y
and never prompt you for yo u r
m ast er passw ord!
Even with its potential for
insecurity, PasswordBox is a www.linuxjournal.com/android
12-Factor REUVEN M.
LERNER
Apps
Reuven describes an interesting perspective on scalable,
maintainable Web apps.
will make your app more maintainable production server. Obviously, things
and more likely to succeed. have improved a great deal since then,
In this article, I take a look at and many (most?) developers now
each of the factors of a 12-factor understand the importance of keeping
app, describing what they mean their code inside a Git repository.
and how you can learn from them. So, why would it be important to
I should note that not every aspect state this as part of a 12-factor app?
of a 12-factor app is unique to It would seem that the reason is
this set of recommendations; two-fold: keep everything you need
some of these practices have been for the application inside a single
advisable for some time. Moreover, repository, and don’t use the same
it’s important to see these as repository for more than one app. In
recommendations and food for other words, there should be a one-
thought, not religious doctrine. to-one correspondence between your
After all, these recommendations app and the repository in which it sits.
come from examining a large Following this advice means, among
number of applications, but that other things, that you can distribute
doesn’t mean they’re a perfect your app multiple times. I recently
match for your specific needs. finished a project for a client that
originally had developed the software
1. Codebase in Lotus Notes. Now, I don’t know
A 12-factor app has “one codebase much about Notes, but the fact is
tracked in revision control, with many that you cannot easily distribute an
deploys”. I remember the days before application written in Notes to new
version control, in which we would servers, let alone to your laptop. A
modify Web applications on the 12-factor app puts everything inside
I’d generally agree that it’s a bad hear that we could add as many Web
idea to modify production code. servers as we wanted, because of the
However, I’ve certainly been in “share nothing” architecture.
situations when it was necessary Now, you do sometimes want to
to do so, with particularly hard- have cached memory or state for
to-track-down bugs that even a users or other resources. In such
seemingly identical staging system cases, it’s best to use something
could not change. Yes, that might like Memcached or Redis—or even
point to problems with the testing a full-fledged relational database—
environment, but when there is a to keep the state. This has the
crisis, my clients generally don’t want advantage of not only keeping it
to hear clever suggestions about separate from your application, but
the development and build process. also of sharing the data across all
Rather, they first want to fix the the Web servers you deploy.
problem and then worry about how
they can avoid the same problem in 7. Port Binding
the future. This factor suggests that the
Nevertheless, if you aren’t using application should be a self-contained
a deployment tool to put your sites system and, thus, export itself and its
out on their servers, you might want services via HTTP on a particular port.
to consider that. The idea here seems to be that every
application should include an HTTP
6. Processes server of some sort and then start that
The next factor says that the server on a port. In this way, every
application should be one or more Web application becomes a resource
stateless processes. The main on the Internet, available via a URL
implication is that the application and a port.
should be stateless, something I truly I must admit that this strikes me as
would hope has been the case for a bit odd. Do I really want to see my
most Web apps for some time. And HTTP server as part of my Web app?
yet, when I was speaking with folks at Probably not, so I don’t see a good
a Fortune 500 company several days reason to include them together.
ago, asking about the scalability of an At the same time, I do see a strong
application that I’m building for them, advantage of considering each Web
they seemed genuinely surprised to application as a small SOA-style
starting up—thus, I’d downplay the on the staging server and a fourth
importance of this particular factor. way on the production machine. Such
a situation is asking for trouble. It
10. Dev/Prod Parity means that even if you have excellent
The idea behind this factor is test coverage of your application,
extremely simple but also important: you’re likely to experience hard-to-
keep your development, staging and debug problems that have to do with
production environments as similar the configuration or the inherent
as possible. differences between operating-
It’s hard to exaggerate the number system versions.
of times I have experienced problems Once again, an increasingly popular
because of this. The system worked solution to this problem is to use a
one way on my own development virtual machine and/or a container.
machine, another way on another With a Vagrant VM, for example,
programmer’s machine, a third way you can share the same machine, not
COLUMNS
AT THE FORGE
to manual tinkering with the database in a way that all can agree on.
that always can lead to problems. However, as with design patterns,
However, I’m not sure if this warrants it’s important to see this as a tool,
inclusion as a crucial component of a not a religion. Consider your needs,
maintainable Web application. take the 12-factor app prescriptions
into account, and apply as necessary.
Conclusion If all goes well, your app will end
I see the 12-factor app as a great up being more scalable, reliable and
way to think about Web applications maintainable. Q
and often to increase their stability
and maintainability. In some ways, I Reuven M. Lerner is a Web developer, consultant and trainer.
see it as similar to design patterns, He recently completed his PhD in Learning Sciences from
in that we have gained a language Northwestern University. You can read his blog, Twitter feed
that allows us to communicate with and newsletter at http://lerner.co.il. Reuven lives with his wife
others about our technical design and three children in Modi’in, Israel.
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].
COLUMNS
WORK THE SHELL
Between Dates:
a Smarter Way
How many days have elapsed? Our intrepid shell script
programmer Dave Taylor looks at how to solve date-related
calculations and demonstrates a script that calculates
elapsed days between any specified day in the past and
the current date.
key phrases, like “back door” and Mon Jul 7 09:14:37 PDT 2014
working on a shell script that The date you specified -- 7-4-2012 -- is valid Continuing
calculates the number of days 0 days transpired between end of 2012 and beginning of this year
between a specified date in the past calculated 153 days left in the specified year
and the current date. Calculated that 7/4/2012 was 341 days ago
starting year subsequent to the date This is free software: you are free to change and redistribute it.
specified (July 4, 2012, in the above There is NO WARRANTY, to the extent permitted by law.
# build date string format for the specified starting date daysbetweenyears=0
tempyear=$(( $tempyear + 1 ))
debugging echo statement offers useful echo "Intervening days in years between $startyear and
The date you specified -- 2-4-2013 -- is valid Continuing The date you specified -- 2-4-2010 -- is valid Continuing
There were 336 days left in the starting year Calculated that there were 336 days left in the starting year
337 days left in the year, but when intervening days in years between 2010 and 2014 = 1096
The problem is, the older date command That’s it. Now, stripping out the
also works differently, because 1969 is debug echo statements, here’s what
the beginning of Epoch time. Look: we can ascertain:
$ date -j 0204120060 # last two digits are year, so '60 $ sh daysago.sh 2 4 1949
Wed Feb 4 12:00:00 PST 2060 23900 days have elapsed between 2/4/1949 and today,
2060, not 1960. Boo! 6003 days have elapsed between 2/4/1998 and today,
problem for dates prior to 1969, and 524 days have elapsed between 2/4/2013 and today,
I’m just going to say “get GNU date, ´day 188 of 2014.
the number of days in intervening years, 524 days have elapsed between 2/4/2014 and today,
daysInMonth $startmon # sets global var dim ### DAYS IN CURRENT YEAR
if [ $startday -lt 0 -o $startday -gt $dim ] ; then dayofyear=$(date +%j) # that's easy!
echo "Invalid date: Month #$startmon has $dim days,
´so day $startday is impossible." ### NOW LET'S ADD IT ALL UP
exit 1
fi totaldays=$(( $daysleftinyear + $daysbetweenyears + $dayofyear ))
if [ $startmon -eq 2 -a $startday -eq 29 ] ; then echo "$totaldays days have elapsed between
isleap $startyear ´$startmon/$startday/$startyear and today,
if [ -z "$leapyear" ] ; then ´day $dayofyear of $thisyear."
echo "$startyear wasn't a leapyear, so February
´only had 28 days." exit 0
Dave Taylor has been hacking shell scripts for more than 30 years.
Really. He’s the author of the popular Wicked Cool Shell Scripts Send comments or feedback via
and can be found on Twitter as @DaveTaylor and more generally http://www.linuxjournal.com/contact
at his tech site http://www.AskDaveTaylor.com. or to [email protected].
Android is everywhere! Come to AnDevCon and learn how to develop apps for the
next generation of connected devices and how to create a seamless user experience.
Learn about Android Wear, Android L, Android TV and more!
A BZ Media Event
AnDevCon™ is a trademark of BZ Media LLC. Android™ is a trademark of Google Inc. Google’s Android Robot is used under terms of the Creative Commons 3.0 Attribution License.
COLUMNS
HACK AND /
Exchange
from the
Command Line
When fetchmail can’t fetch mail, it’s time to fall back to raw
command-line commands.
fetchmail to treat it like any other IMAP then check for unread messages.
host—but in this case, the Exchange
server was configured with security in OpenSSL s_client
mind. So in addition to using IMAPS, The first step was to set up an OpenSSL
each client was given a client certificate s_client connection. Most people
to present to the server during probably interact with OpenSSL on the
authentication. Mutt was able to handle command line only when they need to
this just fine with a few configuration generate new self-signed certificates
tweaks, but fetchmail didn’t fare so or read data from inside a certificate,
well. It turns out that fetchmail has but the tool also provides an s_client
what some would call a configuration mode that you can use to troubleshoot
quirk and others would call a bug. SSL-enabled services like HTTPS. With
When you configure fetchmail to use a s_client, you initiate an SSL
client certificate, it overrides whatever connection and after it outputs relevant
user name you have configured in favor information about that SSL connection,
of the user specified inside the client you are presented with a prompt just
certificate. In my case, the two didn’t as though you used Telnet or Netcat to
match, so fetchmail wasn’t able to log connect to a remote port. From there,
in to the Exchange server, and I no you can type in raw HTTP, SMTP or IMAP
longer got new mail notifications inside commands depending on your service.
my screen session. The syntax for s_client is
I put up with this for a week or so, relatively straightforward, and here
until I realized I really missed knowing is how I connected to my Exchange
when I had new e-mail while I was server over IMAPS:
working. I decided there must be some
other way to get a count of unread $ openssl s_client -cert /home/kyle/.mutt/imaps_cert.pem
some touchy IMAPS servers. Finally by the mailbox and then (UNSEEN)
the -connect argument lets me to tell it to return the number of
specify the hostname and port to unseen messages:
which to connect.
Once you connect, you will see a lot tag STATUS INBOX (UNSEEN)
of SSL output, including the certificate * STATUS INBOX (UNSEEN 1)
the server presents, and finally, you tag OK STATUS completed.
will see a prompt like the following:
In this example, I have one unread
* OK The Microsoft Exchange IMAP4 service is ready. message in my INBOX. Now that I
have that information, I can type tag
From here, you use the tag login LOGOUT to log out.
IMAP command followed by your
user name and password to log in, expect
and you should get back some sort of Now this is great, except I’m not
confirmation if login succeeded: going to go through all of those steps
every time I want to check for new
tag login kyle.rankin supersecretpassword mail. What I need to do is automate
tag OK LOGIN completed. this. Unfortunately, my attempts just
to pass the commands I wanted as
Now that you’re logged in, you can input didn’t work so well, because I
send whatever other IMAP commands needed to pause between commands
you want, including some that would for the remote server to accept the
show you a list of mailboxes, e-mail previous command. When you are in a
headers or even the full contents of situation like this, a tool like expect
messages. In my case though, I just is one of the common ways to handle
want to see the number of unseen it. expect allows you to construct
messages in my INBOX, so I use the incredibly complicated programs that
tag STATUS command followed look for certain output and then send
your input. In my case, I just needed For my screen session, I just want
a few simple commands: 1) confirm the name of the mailbox and the
Exchange was ready; 2) send my login; number of read messages (and
3) once I was authenticated, send the no output if there are no unread
tag STATUS command; 4) then finally messages), so I modify my egrep
log out. The expect script turned into slightly and pipe the whole thing
the following: to a quick Perl one-liner to strip
output I don’t want. The final script
set timeout 10 looks like this:
spawn openssl s_client -cert /home/kyle/ mutt/imaps_cert pem
send "tag login kyle rankin supersecretpassword\n" MAILCOUNT=`expect ~/ imapsexpectscript | egrep '\(UNSEEN [1-9]'
expect "tag OK LOGIN completed " ´| perl -pe 's/ *STATUS \w+ *?(\d+)\) *?$/$1/'`
the Pint-Sized
Super Dæmon!
What’s better than a DNS server, a DHCP server and a TFTP
server? A single dæmon that does it all!
Or, on a Red Hat/CentOS system: This will find the PID (process ID)
and send the signal to reload its
yum install dnsmasq (as root) configuration files. Either way should
work, but the init script will give you
The configuration file (there’s more feedback if there are errors.
just one!) is usually stored at
/etc/dnsmasq.conf, and as I First Up: DNS
mentioned earlier, it is very well Of all the features DNSMasq offers, I
commented. Figuring out even the find its DNS services to be the most
most advanced features is usually as useful and awesome. You get the full
easy as reading the configuration file functionality of your upstream DNS
and un-commenting those directives server (usually provided by your ISP),
you want to enable. There are even while seamlessly integrating DNS
examples for those directives that records for you own network.
require you to enter information To accomplish that “split DNS”-type
specific to your environment. setup with BIND, you need to create
After the dnsmasq package is a fake DNS master file, and even
installed, it most likely will get started then you run into problems if you
automatically. From that point on, are missing a DNS name in your local
any time you make changes to the master file, because BIND won’t
configuration (or make changes to the query another server by default
/etc/hosts file), you’ll need to restart for records it thinks it’s in charge
the service or send an HUP signal to of serving. DNSMasq, on the other
the dæmon. I recommend using the hand, follows a very simple procedure
Figure 2. DNSMasq makes DNS queries simple, flexible and highly configurable.
when it receives a request. Figure 2 it will query the upstream DNS server
shows that process. and return the live IP for my Web host.
For my purposes, this means I can DNSMasq makes a split-DNS scenario
put a single entry into my server’s extremely easy to maintain, and
/etc/hosts file for something like because it uses the server’s /etc/hosts
“server.brainofshawn.com”, and file, it’s simple to modify entries.
DNSMasq will return the IP address My personal favorite feature of
in the /etc/hosts file. If a host DNSMasq’s DNS service, however,
queries DNSMasq for an entry not is that it supports round-robin load
in the server’s /etc/hosts file, balancing. This isn’t something that
www.brainofshawn.com for instance, normally works with an /etc/hosts file
Figure 3 shows the modified method server. (The extra step is shown
used when the DNS server receives as the orange-colored diamond in
a query if it’s also serving as a DHCP the flowchart.)
Figure 3. If you use DHCP, it automatically integrates into your DNS system—awesome
for finding dynamically assigned IPs!
Figure 4. There are no DNS entries anywhere for my Hackintosh, but thanks to
DNSMasq, it’s pingable via its hostname.
Basically, if your friend brings a laptop Even though it isn’t listed in any of
to your house and connects to your the server’s configuration files, since it
network, when it requests a DHCP handles DHCP, it creates a DNS entry
address, it tells the DNSMasq server its on the fly.
hostname. From that point on, until Static DHCP entries can be entered
the lease expires, any DNS queries the in the single configuration file using
server receives for that hostname will be this format:
returned as the IP it assigned via DHCP.
This is very convenient if you have a dhcp-host=90:fb:a6:86:0d:60 xbmc-livingroom 192 168 1 20
whose hostname you know, but it gets dhcp-host=b8:27:eb:16:d9:08 xbmc-masterbedroom 192 168 1 22
adds it to the DNS server’s list of secure, there’s no need to install BIND.
known addresses, even if the client DNSMasq supports DNSSEC, and once
itself doesn’t tell the DHCP server again provides configuration examples
its hostname. You also could just in the configuration file.
add the hostname to your DNSMasq Truly, DNSMasq is the unsung
server’s /etc/hosts file, but I prefer hero for consumer-grade Internet
to make my static DHCP entries with routers. It allows those tiny devices
hostnames, so I can tell at a glance to provide DNS and DHCP for your
what computer the reservation is for. entire network. If you install the
program on a regular server (or teeny
And If That’s Not Enough... tiny Raspberry Pi or Cubox), however,
The above scenarios are all I use it can become an extremely robust
DNSMasq for on my local network. It’s platform for all your network needs. If
more incredible than any DHCP/DNS it weren’t for my need to get a more
combination I’ve ever used before, powerful and reliable router, I never
including the Windows and OS X server- would have learned about just how
based services I’ve used in large networks. amazing DNSMasq is. If you’ve ever
It does provide even more services, been frustrated by BIND, or if you’d
however, for those folks needing them. just like to have more control over
The TFTP server can be activated via the DNS and DHCP services on your
configuration file to serve boot files, network, I urge you to give DNSMasq
configuration files or any other TFTP files a closer look. It’s for more than just
you might need served on your network. your DD-WRT router! Q
The service integrates flawlessly with the
DHCP server to provide boot filenames, Shawn Powers is the Associate Editor for Linux Journal.
PXE/BOOTP information, and custom He’s also the Gadget Guy for LinuxJournal.com, and he has an
DHCP options needed for booting even interesting collection of vintage Garfield coffee mugs. Don’t let
the most finicky devices. Even if you his silly hairdo fool you, he’s a pretty ordinary guy and can be
need TFTP services for a non-boot- reached via e-mail at [email protected]. Or, swing by
related reason, DNSMasq’s server is just the #linuxjournal IRC channel on Freenode.net.
a standard TFTP service that will work for
any computer or device requiring it.
If you’ve read Kyle Rankin’s recent Send comments or feedback via
articles on DNSSEC and want to http://www.linuxjournal.com/contact
make sure your DNS information is or to [email protected].
Open-E JupiterDSS
The latest release of the Open-E JupiterDSS—
or Defined Data Storage Software—is a
result of three years of development, testing,
working closely with partners and integrating
customer feedback, reported maker Open-E.
The firm added that Open-E JupiterDSS
provides enterprise users the highest level
of performance with unlimited capacity and
volume size. Delivered through Open-E certified partners as a software-defined storage
system, Open-E JupiterDSS comes complete with advanced features, including thin
provisioning, compression and de-duplication. This milestone release of the company’s
flagship application comes in response to customers demanding ever larger storage
environments while maintaining high benchmarks for quality, reliability, performance and
price. Open-E JupiterDSS features a ZFS- and Linux-based storage operating system.
http://www.open-e.com
Zentyal Server
What’s special about the upgraded Zentyal
Server 3.5 is that it integrates both
the complex Samba and OpenChange
technologies, making it easy to integrate
Zentyal into an existing Windows environment and carry out phased, transparent migration
to Linux. In other words, the Zentyal Linux Small Business Server offers a native drop-in
replacement for Windows Small Business Server and Microsoft Exchange Server that can
be set up in less than 30 minutes and is both easy to use and affordable. Because Zentyal
Server’s 3.5 release focuses on providing a stable server edition with simplified architecture,
it comes with a single LDAP implementation based on Samba4, helping solve a number of
synchronization issues caused by having two LDAP implementations in the earlier editions.
In addition, a number of modules have been removed in order to advance the core goal of
offering the aforementioned drop-in Windows server replacement capabilities.
http://www.zentyal.com
Nevercenter’s
Silo 3D Modeler
In response to its number-one request,
Nevercenter has ported version 2.3 of its Silo 3D
Modeler application to Linux, complementing
the existing Mac OS and Windows editions. Silo,
popular with designers of video games, movies
and 3-D architectural applications, can be used
either as a standalone tool or as a versatile element of a multi-application 3-D graphics
workflow. Nevercenter is finding ever more studios and individuals in this space moving to
Linux. Silo’s internals also have received significant updates, including an updated windowing
system and bug fixes across all platforms, as well as added support for .stl import.
http://www.nevercenter.com/silo
Provisioning
X.509 Certificates
Using
RFC 7030 Learn how to use libest
to deploy X.509 certificates
across your enterprise.
JOHN FOLEY
openssl base64 -d -in cacerts.p7 | \ openssl req -new -sha256 -newkey rsa:2048 \
openssl pkcs7 -inform DER -outform PEM \ -keyout privatekey.pem -keyform PEM -out csr.p10
two entities. However, first you need writing new private key to 'privatekey.pem'
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ACME, Inc. -H "Content-Type: application/pkcs10"
Common Name (e.g. server FQDN or YOUR name) []:mfgserver1.acme.org Step 6: If successful, the curl
Email Address []:[email protected] command should place the new
certificate in the cert.p7 file. The
Please enter the following 'extra' attributes EST specification requires the
to be sent with your certificate request certificate to be base64-encoded
A challenge password []: PKCS7. Because PEM is a more
An optional company name []: commonly used format, you’ll
use OpenSSL to convert the new
Now that you have the CSR and key certificate to PEM format:
pair, you need to send the CSR to the
CA to have it signed and returned to openssl base64 -d -in cert p7 | openssl pkcs7 -inform DER \
you as an X.509 certificate. The EST -outform PEM -print_certs -out cert pem
Certificate: CA:FALSE
Validity keyid:EE:DE:AA:C0:5B:AC:38:7D:F3:08:26:33:73:00:3F:F3:2B:63:41:F8
Modulus:
61:94:8d:63:cd:54:2c:a9:86:7a:3b:35:62:e9:c6: libest
76:58:fb:27:c1:bf:db:c2:03:66:e5:dd:cb:75:bc: Curl provides a primitive method to
72:6c:ca:27:76:2a:f7:48:d5:3b:42:de:85:8e:3b: issue the RESTful operations of the
15:f1:7a:e4:37:3c:96:b2:91:70:6f:97:22:15:c6: EST enrollment process. However,
82:ea:74:8b:f2:80:39:c1:c2:10:78:6e:70:11:78: the curl command-line options
31:2f:4a:c3:c4:2b:ab:2f:4d:f2:87:15:59:88:b3: required to enroll a new certificate
17:12:1d:92:b2:6d:a6:8a:94:3f:b3:76:18:53:f9: securely are cumbersome and error-
59:29:e1:9b:8c:81:41:7e:8c:a2:a7:34:c9:b4:07: prone. Additionally, curl is unable
32:77:57:37:59:dd:fb:36:02:59:74:bb:96:6e:e7: to perform the TLS channel binding
Go to http://drupalize.me and
get Drupalized today!
FEATURE Synchronize Your Life with ownCloud
Synchronize
Your Life with
ownCloud
Once everything is configured, there file from the filesystem directly or via a
are some operational issues. The obvious Samba share. In those cases, you either
issue stems from making concurrent have to change the user name that
changes to an asset. This results in a the Web server runs as or the name
conflict, and the various clients handle that the Samba server uses to access
conflicts differently. To avoid problems, the files. Either way, you still won’t be
simply synchronize the asset before able to access the files directly. I’ve not
you modify it, and then re-synchronize yet decided on if or how I intend to fix
when your changes are complete. This this. I’ll probably just access the files
will ensure that everyone has the same via a Samba share or NFS mount.
version of each asset on their client. The ownCloud system supports
I also discovered that it is very server-side encryption that can be
difficult to move assets from one turned on and off on a per-user basis.
calendar or address book to another. This leads to more problems than it’s
The various clients don’t seem to do worth, in my opinion. For example,
a very good job of this. So far, my what happens when a user encrypts his
attempts at organizing my contacts or her files and then shares a directory
have resulted in duplicate contacts in with a user who does not? I happen
different address books. I think the to know that you get a warning from
solution is going to involve adding ownCloud, but I didn’t spend the time
the assets in question to a category, to find out what actually happens,
exporting the assets in that category, because I stumbled upon another
deleting the assets in that category problem. Server-side encryption pretty
and the re-importing the assets into much breaks any possible means of file
the appropriate calendar or address access besides webDAV. I guess that’s
book. This seems like the long way the point of server-side encryption,
around the block, so I’m going to hold but it doesn’t work for the way I
on doing it this way until I know for want/need to access my files. I
sure there isn’t an easier way to do it. ended up turning off encryption and
The rest of the difficulties involve decrypting my existing files, which was
file security. The first problem is that done seamlessly for me by ownCloud.
when a user uploads a file into his or The better solution might be to use
her cloud space, that file will be owned an encrypted filesystem like Encfs to
by the Web server user. This is okay as protect your files. With this solution,
long as you don’t want to access the you still will be able to use Samba and
LINUX JOURNAL
on your
e-Reader
Customized e-Reader
editions
Kindle and Nook
editions FREE
for Subscribers
now available
LEARN MORE
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
> http://lnxjr.nl/modsap
WHITE PAPERS
White Paper: JBoss Enterprise Application
Platform for OpenShift Enterprise
Sponsor: DLT Solutions
Red Hat’s® JBoss Enterprise Application Platform for OpenShift Enterprise offering provides IT organizations with a simple and
straightforward way to deploy and manage Java applications. This optional OpenShift Enterprise component further extends
the developer and manageability benefits inherent in JBoss Enterprise Application Platform for on-premise cloud environments.
Unlike other multi-product offerings, this is not a bundling of two separate products. JBoss Enterprise Middleware has been
hosted on the OpenShift public offering for more than 18 months. And many capabilities and features of JBoss Enterprise
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, JBoss Enterprise Application Platform for OpenShift Enterprise, for enterprises looking for cloud
benefits within their own datacenters.
> http://lnxjr.nl/jbossapp
WHITE PAPERS
Linux Management with Red Hat 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
Benefits of an SOE:
SOE is a specification for a tested, standard selection of computer hardware, software, and their configuration for use
on computers within an organization. The modular nature of the Red Hat SOE lets you select the most appropriate
solutions to address your business' IT needs.
s 4HERE ARE MANY BENEFITS TO HAVING AN 3/% WITHIN LARGER ENVIRONMENTS SUCH AS
s 3TANDARDIZATION
> http://lnxjr.nl/RH-SOE
For a long time, the software Currently, there are two filesystems
RAID implementation in the Linux available on Linux that support
kernel has worked well to protect internal RAID with checksums on all
data against drive failure. It provides data to prevent silent corruption:
great protection against a drive ZFS and BTRFS. ZFS is from Sun and
totally failing and against the has some license issues, so it isn’t
situation where a drive returns read included in most Linux distributions.
errors. But what it doesn’t offer It is available from the ZFS On Linux
is protection against silent data Web site (http://zfsonlinux.org).
corruption (where a disk returns BTRFS has no license problems and is
corrupt data and claims it to be included in most recent distributions,
good). It also doesn’t have good but it is at an earlier stage of
support for the possibility of drive development. When discussing BTRFS
failure during RAID reconstruction. in this article, I concentrate on the
Drives have been increasing in size theoretical issues of data integrity
significantly, without comparable and not the practical issues of kernel
increases in speed. Modern drives panics (which happen regularly to me
have contiguous read speeds 300 but don’t lose any data).
times faster than drives from 1988
but are 40,000 times larger (I’m Do Drives Totally Fail?
comparing a recent 4TB SATA disk For a drive totally to fail (that is, be
with a 100M ST-506 disk that can unable to read any data successfully
sustain 500K/s reads). So the RAID at all), the most common problem
rebuild time is steadily increasing, used to be “stiction”. That is when
while the larger storage probably the heads stick to the platters, and
increases the risk of data corruption. the drive motor is unable to spin the
disk. This seems to be very uncommon regarded that the best research on the
in recent times. I presume that drive incidence of hard drive “failure” is the
manufacturers fixed most of the Google Research paper “Failure Trends
problems that caused it. in a Large Disk Drive Population”
In my experience, the most (http://research.google.com/pubs/
common reason for a drive to pub32774.html), which although
become totally unavailable is due to very informative, gives no information
motherboard problems, cabling or on the causes of “failure”. Google
connectors—that is, problems outside defines “failure” as anything other
the drive. Such problems usually than an upgrade that causes a drive
can be fixed but may cause some to be replaced. Not only do they
downtime, and the RAID array needs not tell us the number of drives that
to keep working with a disk missing. totally died vs. the number that had
Serious physical damage (for some bad sectors, but they also don’t
example, falling on concrete) can tell us how many bad sectors would
cause a drive to become totally be cause for drive replacement.
unreadable. But, that isn’t a Lakshmi N. Bairavasundaram, Garth
problem that generally happens to R. Goodson, Bianca Schroeder, Andrea
a running RAID array. Even when C. Arpaci-Dusseau and Remzi H.
I’ve seen drives fail due to being in Arpaci-Dusseau from the University
an uncooled room in an Australian of Wisconsin-Madison wrote a
summer, the result has been many paper titled “An Analysis of Data
bad sectors, not a drive that’s totally Corruption in the Storage Stack”
unreadable. It seems that most drive (http://research.cs.wisc.edu/adsl/
“failures” are really a matter of an Publications/corruption-fast08.
increasing number of bad sectors. html). That paper gives a lot of
There aren’t a lot of people who information about when drives have
can do research on drive failure. An corrupt data, but it doesn’t provide
individual can’t just buy a statistically much information about the case of
significant number of disks and run major failure (tens of thousands of
them in servers for a few years. I errors), as distinct from cases where
couldn’t find any research on the there are dozens or hundreds of
incidence of excessive bad sectors errors. One thing it does say is that
vs. total drive failure. It’s widely the 80th percentile of latent sector
errors per disk with errors is “about (something less than 48M of data)
50”, and the 80th percentile of was a small fraction of a 3TB disk. If
checksum mismatches for disks with an older filesystem was used in that
errors is “about 100”. So most disks situation, a metadata error could
with errors have only a very small corrupt a directory and send all its
number of errors. It’s worth noting entries to lost+found.
that this research was performed ZFS supports even greater
with data that NetApp obtained redundancy via the copies= option. If
by analyzing the operation of its you specify copies=2 for a filesystem,
hardware in the field. NetApp has then every data block will be written
a long history of supporting a large to two different parts of the disk. The
number of disks in many sites with number of copies of metadata will
checksums on all stored data. be one greater than the number of
I think this research indicates copies of data, so copies=2 means
that the main risks of data loss are that there will be three copies of
corruption on disk or a small number every metadata block. The maximum
of read errors, and that total drive number of copies for data blocks
failure is an unusual case. in ZFS is three, which means that
the maximum number of copies of
Redundancy on a Single Disk metadata is four.
By default, a BTRFS filesystem that The paper “An Analysis of Data
is created for a single device that’s Corruption in the Storage Stack”
not an SSD will use “dup” mode shows that for “nearline” disks (that
for metadata. This means that every is, anything that will be in a typical
metadata block will be written to two PC or laptop), you can expect a 9.5%
parts of the disk. In practice, this can probability of read errors (latent sector
allow for recovering data from drives errors) and a 0.466% probability
with many errors. I recently had a 3TB of silent data corruption (checksum
disk develop about 14,000 errors. mismatches). Typical Linux Journal
In spite of such a large number of readers probably can expect to see data
errors, the duplication of metadata loss from hard drive read errors on
meant that there was little data loss. an annual basis from the PCs owned
About 2,000 errors in metadata blocks by their friends and relatives. The
were corrected with the duplicates, probability of silent data corruption
and the 12,000 errors in data blocks is low enough that all users have a
less than 50% chance of seeing it on with BTRFS, the default configuration
their own PCs during their lives—unless is to use “dup” for metadata. This
they purchased one of the disks with a means that a small number of disk
firmware bug that corrupts data. errors will be unlikely to lose any
If you run BTRFS on a system with metadata, and a scrub will tell you
a single disk (for example, a laptop), which file data has been lost due
you can expect that if the disk to errors. Duplicate metadata alone
develops any errors, they will result can make the difference between a
in no metadata loss due to duplicate server failing and continuing to run.
metadata, and any file data that is It is possible to run with “dup” for
lost will be reported to the application data as well, but this isn’t a well
by a file read error. If you run ZFS on supported configuration (it requires
a single disk, you can set copies=2 mixed data and metadata chunks that
or copies=3 for the filesystem that require you to create a very small
contains your most important data filesystem and grow it).
(such as /home on a workstation) to It is possible to run RAID-1 on two
decrease significantly the probability partitions on a single disk if you are
that anything less than total disk willing to accept the performance
failure will lose data. This option of loss. I have a 2TB disk running as a
providing extra protection for data 1TB BTRFS RAID-1, which has about
is a significant benefit for ZFS when 200 bad sectors and no data loss.
compared to BTRFS. Finally, it’s worth noting that a
If given a choice between a RAID-1 “single disk” from the filesystem
array with Linux software RAID (or perspective can mean a RAID array.
any other RAID implementation that There’s nothing wrong with running
doesn’t support checksums) and a BTRFS or ZFS over a RAID-5 array.
single disk using BTRFS, I’d choose The metadata duplication that both
the single disk with BTRFS in most those filesystems offer will reduce
cases. That is because on a single disk the damage if a RAID-5 array suffers
a read error while replacing a failed array from the contents of the old
disk. A hardware RAID array can disk and from the other disks in a
offer features that ZFS doesn’t offer redundant set. BTRFS supports the
(such as converting from RAID-1 to same thing with the btrfs replace
RAID-5 and then RAID-6 by adding command. In the most common error
more disks), and hardware RAID situations (where a disk has about 50
arrays often include a write-back disk bad sectors), this will give you the
cache that can improve performance effect of having an extra redundant
for RAID-5/6 significantly. There’s disk in the array. So a RAID-5 array
also nothing stopping you from using in BTRFS or in ZFS (which they call
BTRFS or ZFS RAID-1 over a pair of a RAID-Z) should give as much
hardware RAID-5/6 arrays. protection as a RAID-6 array in a
RAID implementation that requires
Drive Replacement removing the old disk before adding
When you replace a disk in Linux a new disk. At this time, RAID-5
software RAID, the old disk will be and RAID-6 support in BTRFS is
marked as faulty first, and all the still fairly new, and I don’t expect
data will be reconstructed from other it to be ready to use seriously by
disks. This is fine if the other disks the time this article is published.
are all good, but if the other disks But the design of RAID-5 in BTRFS
have read errors or corrupt data, is comparable to RAID-Z in ZFS,
you will lose data. What you really and they should work equally well
need is to have the new disk directly when BTRFS RAID-5 code has been
replace the old disk, so the data for adequately tested and debugged.
the new disk can be read from the Hot-spare disks are commonly used
old disk or from redundancy in the to allow replacing a disk more quickly
array, whichever works. than someone can get to the server.
ZFS has a zpool replace The idea is that the RAID array might
command that will rebuild the be reconstructed before anyone even
disks, you might lose some data but working or not?”, they are part of
won’t lose metadata. For metadata the same issue.
to be lost on a RAID-Z array, you
need to have one disk die entirely Comparing BTRFS and ZFS
and then have matching read errors For a single disk in a default
on two other disks. If disk failures configuration, both BTRFS and
are independent, it’s a very unlikely ZFS will store two copies of each
scenario. If, however, the disk failures metadata block. They also use
are not independent, you could have checksums to detect when data is
a problem with all disks (and lose no corrupted, which is much better
matter what type of RAID you use). than just providing corrupt data to
an application and allowing errors
Snapshots to propagate. ZFS supports storing
One nice feature of BTRFS and ZFS as many as three copies of data
is the ability to make snapshots blocks on a single disk, which is a
of BTRFS subvolumes and ZFS significant benefit.
filesystems. It’s not difficult to write For a basic RAID-1 installation,
a cron job that makes a snapshot of BTRFS and ZFS offer similar features
your important data every hour or by default (storing data on both
even every few minutes. Then when devices with checksums to cover
you accidentally delete an important silent corruption). ZFS offers duplicate
file, you easily can get it back. Both metadata as a mandatory feature and
BTRFS and ZFS can be configured the option of duplicate data on top of
such that files can be restored from the RAID configuration.
snapshots without root access so BTRFS supports RAID-0, which is a
users can recover their own files good option to have when you are
without involving the sysadmin. working with data that is backed
Snapshots aren’t strictly related up well. The combination of the
to the the topic of data integrity, use of BTRFS checksums to avoid
but they solve the case of accidental data corruption and RAID-0 for
deletion, which is the main reason performance would be good for a
for using backups. From a sysadmin build server or any other system
perspective, snapshots and RAID that needs large amounts of
are entirely separate issues. From temporary file storage for repeatable
the CEO perspective, “is the system jobs but for which avoiding data
Introducing
pi-web-agent,
a Raspberry Pi
Web App
A Web application allowing everyday users to control
the Raspberry Pi.
VASILIS NICOLAOU, ANGELOS GEORGIADIS,
GEORGIOS CHAIREPETIS and ANDREAS GALAZIS
desktop with the Glavsoft TightVNC expert). You can set rules for various
client Java applet. chains, block certain IP addresses or
The firewall management, despite allow connections through different
its early stage, enables you to avoid protocols (Figure 2).
the fuss of many complicated options Clicking the “Other” tab will reveal
that iptables provides from the more extensions. The camera controller
command line (until you become an enables you to take snapshots and
even begin your own live stream! your files, and download or choose to
We also provide a media player play audio files with the pi-web-agent’s
(tagged as radio, since it started as media player extension. (Note: this
such), where you can provide a URI functionality is available only from the
of an audio file or a streaming radio development branch on GitHub, but it
channel. Your Raspberry Pi will start will be available in version 0.3.)
playing the audio, so get ready to The media player extension is
attach your HD speakers! an Mplayer port that also enables
You also can play an audio file you to control the sound with an
straight from your Pi, but don’t bother equalizer (Figure 3).
typing the URI in the text box. Find it If you want to be more hard-
through the file browser we provide. core and play with some wires and
Although it’s simple in functionality for LEDs, we provide an extension for
now, it enables you to browse through controlling the GPIO pins on your Pi
Figure 4. The GPIO module gives you control over the Raspberry Pi GPIO pins.
just arrived and you have installed following and then pressing Enter:
Raspbian on your SD card. Even if
you don’t have much experience with pistore
Linux and the command line, worry
no more. You can connect to your Pi When pistore opens, just register
with SSH and install the pi-web-agent, and search for pi-web-agent.
which will help you in your first steps. Everything else is straightforward.
While you become more experienced
with the Pi and Linux, the pi-web-agent Installing via the Command Line
will grow with you, giving you If you are not on a Linux machine,
more powerful capabilities and or if your distribution is headless,
making your interaction with your you still can install pi-web-agent
Pi more enjoyable. easily. The following commands will
The most difficult task you’ll face fetch and install pi-web-agent:
is the installation process, especially
if you run a headless Debian wget https://github.com/vaslabs/\
distribution on your Raspberry Pi. pi-web-agent/archive/0.2-rc-1.zip
You won’t be able to avoid executing unzip 0.2-rc-1.zip
commands (until we release a cd pi-web-agent-0.2-rc-1
Raspbian mod with the pi-web-agent ./install.sh
included). You need to connect with ./run.sh
your Pi via SSH. There are two ways
to install the pi-web-agent, which Troubleshooting
are described below. We’ve started a discussion on Reddit
that covers a lot of troubleshooting,
Installing through pistore thanks to users’ questions
If you are using a Linux machine, it’s (http://www.reddit.com/r/raspberry_pi/
easy. Just do: comments/249j4r/piwebagent_control_
your_pi_from_the_ease_of_your). You
ssh -X pi@raspberrypi can find guidelines on how to install
under various circumstances and
The -X will enable you to execute how to resolve problems that others
graphical applications. Provide your already have faced. All the issues
password to the prompt, and then identified in this discussion have been
launch the pistore by typing the resolved, but if you face a new one,
Figure 5. Sneak peek of the pi-web-agent version 1.0, simple window with content
inside and dock as navigation menu.
with some free time and a passion chance of keeping pi-web-agent alive if Vasilis is hit by a bus
for open source, don’t hesitate to tomorrow. He is the number-one suspect when something
contact us and join our team. breaks in pi-web-agent and is probably responsible, since he
has blown the repository quite a few times (17-ish).
Acknowledgements
We want to give credit and a kind Georgios Chairepetis is a young programming enthusiast,
thank you to all the people that currently studying for an MSc in Software Engineering at the
helped shape the pi-web-agent: University of Manchester. He got involved with the rest of the
pi-web-agent team initially by taking part in a hackathon
Q Kyriacos Georgiou contest and was lucky enough to win an award in the first
competition he ever attended. He enjoys staying inside on
Q Maria Charalambous Saturdays doing some programming with friends, but he also
likes to go outside and enjoy the sunshine, maybe with some
Q Argyris Zardylis beer, when he has the chance.
Q Iliada Eleftheriou Andreas Galazis has been a junior Web developer for six
months. The fact that his favourite Linux application is
Q Theodoros Pertsas Mplayer is somewhat misleading, as he spends most of
his time coding rather than watching movies or listening
to music, but when he does, he wants to do it the proper
Send comments or feedback via way. When he heard about pi-web-agent, he decided to join
http://www.linuxjournal.com/contact forces to develop an extension to demonstrate the power of
or to [email protected]. his favourite media player.
Matters
Are we going to get real about privacy for everybody—or just
hunker in our own bunkers?
I
’m writing this in a hotel room friends and once in a bunker entered
entered through two doors. The hall through a men’s room at the beach.
door is the normal kind: you stick a After gathering behind a heavy door,
card in a slot, a light turns green, and everyone in the shelter tensely but
the door unlocks. The inner one is three cheerfully waits to hear a “boom” or
inches thick, has no lock and serves two, then pauses another few minutes
a single purpose: protection from an to give shrapnel enough time to finish
explosion. This grace is typical of many falling to the ground. Then they go
war-zone prophylaxes here in Tel Aviv, outside and return to whatever they
Israel’s second-largest city. The attacks were doing before the interruption.
come in cycles, and the one going on But not everybody bothers with the
now (in mid-July 2014) is at a peak. Sirens shelters. Some go outside and look at
go off several times a day, warning of the sky. I was one of those when I shot
incoming rockets from Gaza. When that the photo shown in Figure 1 from the
happens, people stop what they’re doing front porch of my hotel, a few moments
and head for shelters. If they’re driving, after hearing a pair of booms.
they get out of their cars and lie on the The photo tells a story in smoke of
ground with their heads covered. two incoming Hamas rockets from
Since I got here, I have joined Gaza, intercepted by four Israeli
those throngs three times in small, missiles. The round puffs of smoke
claustrophobia-inducing shelters— mark the exploded rockets. The
once in my hotel, once in an parallel trails mark the paths of the
apartment house where I was visiting interceptors. These are examples of the
Figure 1. Two incoming Hamas rockets from Gaza, intercepted by four Israeli missiles.
wiki/Iron_Dome) at work. */
Alert. The one on my phone tells me ´and word('linux'or ' USB ' or ' CD ' or 'secure
there were 27 rocket attacks fired from ´desktop' or ' IRC ' or 'truecrypt' or ' tor')
xkeyscorerules100.txt), of sorts, by (The Amnesic Incognito Live System) software program viewing
the NSA. Here are the crosshairs at documents relating to TAILs or viewing websites that
fingerprint('ct_mo/TAILS')=
// START_DEFINITION fingerprint('documents/comsec/tails_doc') or
/* ´web_search($TAILS_terms) or
These variables define terms and websites relating to the ´url($TAILS_websites) or html_title($TAILS_websites)
Doc Searls is Senior Editor of Linux Journal . He is also a much more, Linux Journal offers the
fellow with the Berkman Center for Internet and Society at ideal content environment to help you
reach your marketing objectives. For
Harvard University and the Center for Information Technology
more information, please visit
and Society at UC Santa Barbara.
http://www.linuxjournal.com/advertising.