Revisioning /etc with Git

First and foremost I’m a coder, a coder who strongly believes in revision control. Second I am also a sysadmin; but only by accident. I have some servers and someone has to take care of them. I’m not a good sysadmin because I don’t have any interest on it so I learn as little as possible and also because I don’t want to be good at it and get stuck doing that all the time. What I love is to code.

I’m always scare of touching a file in /etc. What if I break something? I decided to treat /etc the same way I treat my software (where I am generally not afraid of touching anything). I decided to use revision control. So far I’ve never had to roll back a change in /etc, but it gives me a big peace of mind knowing that I can.

In the days of CVS and Subversion I thought about it, but I’ve never done it. It was just too cumbersome. But DVCS changed that, it made it trivial. That’s why I believe DVCS is a breakthru. Essentially what you need to revision-control your /etc with Git is to go to /etc and turn it into a repository:

cd /etc
git init

Done. It’s now a repo. Then, submit everything in there.

git add .
git commit -am "Initial commit. Before today it's prehistory, after today it's fun!"

From now on every time you modify a file you can do

git add <filename>
git commit -m "Description of the change to <filename>"

where <filename> is one or many files. Or if you are lazy you can also do:

git commit -am "Description to all the changes."

which will commit all pending changes. To see your pending changes do:

git status

and

git diff

When there are new files, you add them all with

git add .

and if some files were remove, you have to run

git add -u .

to be sure that they are remove in the repo as well (otherwise they’ll stay as pending changes forever).

That’s essentially all the commands I use when using git and doing sysadmin. If you ever have to do a rollback, merge, branch, etc, you’ll need to learn git for real.

One last thing. I often forget to commit my changes in /etc, so I created this script:

#!/usr/bin/env sh

cd /etc
git status | grep -v "On branch master" | grep -v "nothing to commit"
true # Don't return 1, which is what git status does when there's nothing to do.

on /etc/cron.daily/git-status which reminds me, daily, of my pending changes.

Hope it helps!

Advertisements

What Joel Spolsky doesn't understand about Linux

Once again I hear Joel Spolsky saying the same thing about Linux that I consider wrong. I’m sure I’m not the only one thinking that and I’m sure I’m not the only one writing about it, but I’m going to do it anyway. Joel’s position is that administrating Linux must be harder because something like 70% of the support calls they handle for FogBugz come from Linux while it is less than 30% of its market.

I’d agree that for someone that doesn’t know anything about administrating, getting a Windows server running is easier than getting a Linux server running. I think that being an expert in both environments is equally hard. The sysadmin problems are hard and there are no shortcuts.

But Joel Spolsky point is wrong in one regard: Linux is not an operating system. I’ve said it before and I’ve got many negative comments, mails, messages about it but very few actually got my point. This is an instance where Linux being taken for an operating system is causing someone pain and thus causing that someone to say something that is not completely right.

Joel makes FogBugz for Windows and Linux. Does that mean that I can run it on my Windows CE phone? It is a Windows, isn’t it? It says Windows in the name! It has a start button! Well, of course I can’t run FogBugz on it. They ship it for Windows the PC operating system. Does it work on ReactOS then? In a sense it is a Windows PC operating system; an alternative implementation of one with all the same interfaces and libraries. Well, of course not. It work only in the Windows PC operating system produced by Microsoft. For example, Windows 7 Starter Edition, yes, that one that allows you to run only three apps at the time. Well, no!

All those things I mentioned are in a sense Windowses as well, yet they are not supported and probably FogBugz doesn’t work on them. Yet, he says he supports Linux. Saying you support Linux is like saying that you supports computers that have RAM. It’s too broad. Trying to ship something that should run on almost everything won’t work. Be it Linux or anything else.

Linux is only a kernel. It’s a kernel used by many different operating systems. Some of them radically different (like Android or Chrome OS). If you are a company and make a product supporting it on Linux is crazy. What should Joel do then?

He should support operating systems, not kernels. What operating systems should Joel support? I don’t know, whatever is popular. I’d guess Red Hat’s RHEL, Ubuntu, Debian are probably popular operating systems. Once you start supporting operating systems instead of kernels the world looks differently. You don’t have to deliver a tar.gz (a compressed archive) that should compile and run everywhere. It’s insane to ship that and it’s insane to expect users to be able to install them. I administer various Debian and Ubuntu servers and workstations. Do you know how often I compile source code that I haven’t written myself? Never!

When you support an operating system like Ubuntu or Debian you can ship binaries. You build binaries in the form of debs or rpms. And you don’t build only one of them, you probably need one deb for Ubuntu, one deb for Debian and maybe even one deb for each version of Ubuntu if they vary enough. If you think this is a lot of work, then look at how much work is building a Windows installer that can work in any Windows from XP pre-SP1 without .Net to Windows 7. If it was trivial there wouldn’t be companies like InstallShield making money.

I’ve heard FogBugz comes with its own copy of MySQL and Apache. How Windowish! That’s crazy and meant to break. You don’t copy code, programs or libraries in the world of Linux-based operating systems. You set dependencies. You make a fogbugz.deb that depends on Apache and depends on MySQL and when fogbugz.deb is installed it will automatically install Apache and MySQL. It will install an Apache built, optimized and customized for that version of Apache that follows the Ubuntu guidelines for storing caches, config files, etc.

There’s more, since there are some pretty straighfoward guidelines where everything is installed, fogbugz.deb could work out of the box. In an Ubuntu box I can run

aptitude install phpmyadmin

and it works out of the box. And phpMyAdmin depends on Apache and MySQL. Of course I could break those services so that nothing works, but most people don’t. What the phpmyadmin package does is drop files in certain locations where Apache is going to pick them up. Apache as many other programs don’t have just one configuration files but directories of them, so you can drop another configuration file and it’s picked up.

I am very certain that if FogBugz was packaged in this fashion, then it would not generate as many phone calls as it does now. It is packaged and distributed like software in 1995 for Linux-based operating systems, when almost everything was a mess and chaotic and there were very few people putting it in production.

To close this post let me tell you something else to convince you that Linux is not an operating system. You can write a program for Linux, but then it runs just fine in OpenBSD. And then you find out that it also runs just fine in Solaris. Well, but you wrote it on a Debian box, which is Linux. Did you know that there’s a Debian kFreeBSD (or something like that)? which is Debian running the FreeBSD kernel. Debian kFreeBSD is more similar to Debian than to FreeBSD. Nexenta is Ubuntu with the Solaris kernel, and it’s more similar to Ubuntu than to Solaris. Android is Linux, yet almost none of the software that runs on Debian, FreeBSD, Nexenta, Solaris runs on Android.

You see, Linux is just one component, and not even the biggest component, of an operating system. It is not the component users interact with when using a computer and it is not even the component programmers interact most of the time, when writing a program. It makes almost no sense to say “I make this program for Linux”.

Linux is not an operating system

For the purpose of writing this article I’m going to use the following definition of “operating system”. There are other definitions and I’m not claiming this is the right one. An operating system is a unit of software that you can install in a computer and will let you use the computer, thought a set of utilities or program in one way or another. Continue reading