keepalive.sh: restarting flaky applications

February 5th, 2007

Sometimes you just want an application to run in the background for whatever reason. One that tends to crash. Well, if you're not there when it crashes, you can't start it up again. So what to do? The obvious answer is "fix the damn application already!" But maybe you don't have the source code. Or you don't know how. Or you can't be bothered. Or whatever. And you just want a way to automatically restart the application whenever it crashes.

I didn't know how to do that before, so I never had a solution for those rare cases when this was needed. But it's very easy to do.

#!/bin/sh

if [ "x$1" = "x" ]; then echo "usage: $0 <application>"; exit 1; fi


app=$1
echo "Running $app"


$app &
pid=$!
while ((1)); do
	if ! ps $pid; then 
		echo "Restarting $app"
		$app &
		pid=$!
	fi
	echo "pid: $pid"
	wait $pid
	sleep 30
done

Here's how keepalive.sh works.

  1. It starts the application.
  2. It captures the pid.
  3. Now it starts an infinite loop.
    1. Check the pid to see if the app is running.
    2. If the app is not running, start it and capture the pid.
    3. Otherwise just wait for it to finish.
    4. Goto 3.1.

It doesn't matter if you stop the application in a standard way, if you kill it, or if it dies on its own. Within 30 seconds it will be restarted. The short delay is included so that an application that dies instantly won't keep restarting and dieing all the time, bringing your system to its knees. Until you stop keepalive.sh, it will keep looping forever.

impossible to find: socks

February 4th, 2007

Sometimes it's the simplest problems that are the most difficult. Like buying socks. In the last month or so I've looked all over the place, spanning three different countries, and come up with zip. How hard is it to find socks? Hard. The socks I own were rare finds in the first place, and it's times like these that make me wish I had bought 4 times as many of them. It's not that socks wear out, which they do. But they also have a way of going missing. A couple years down the line you suddenly have fewer pairs than you used to, for unexplained reasons.

This is what I'm looking for. Cotton socks. Cotton, okay? Not polyester, polyamide or any other plastic-like sweaty fabrics. When you pick up a pair you can tell right away if the fabric is good, or if it feels more like it's plastic mixed in that will make your feet sweat. Even 20% polyester will do that. I don't mind elastics, though, that's fine. But the rest has to be cotton, or the deal is off. And while I've bought cotton socks lots of times, they're always rare. So rare for the moment that I can't find them anywhere. Maybe I should look on ebay.

where is your company again?

February 3rd, 2007

Location, location, location! Remember when that used to be important for business? Well, it's not important for e-business. Take GNi (mentioned in the last gentoo newsletter). Nowhere on the front page does it mention where their offices are. It doesn't say "we're a San Jose-based company ... ". How many clicks does it take you to find their location? I first went to "About Us", but that had no mention of it. Apparently, location is not relevant to a page about the company. Then I went to "Contact Us", which is usually a safe last resort. And sure enough, there it is. But GNi has a small website, on some company sites it takes me a bit of effort to even locate the "Contact Us" page, it's buried somewhere deep in the hierarchy, or the link is in 6pt font, so you're not meant to see it.

So I can only conclude from this that location doesn't matter. And in our globally interconnected world that may seem obvious. On the other hand, it may not. If you're looking for a web host, wouldn't you rather pick one in your timezone? So that when the server crashes, they have office hours at the same time as you? Or wouldn't you prefer a partner in your timezone for just about any kind of business? Or in fact in your vicinity, so that you don't have to fly to Cape Town for meetings?

powerpoint productivity

February 2nd, 2007

I find it interesting that office suites are often dubbed "productivity suites" by vendors. Of course, they are "productive" software compared to say.. Solitaire, but are they really "productive" in the absolute meaning of the word?

Claim
By making office software easy to use, the user doesn't have to waste time on learning how to use the software, because it's so intuitive that any idiot can use it. And thus you're more productive.

Counterclaim
If it's easy enough for idiots to use, won't idiots use it? Or rather, to be a little more accurate, won't users use it at the intellectual level of an idiot? How, and why, would they rise above that level if it's all they need to get by?

As someone who thinks about software, writes software, uses software, and comments on software, it pains me to see how some people use software. It really makes me sad.

The whole office suite concept was never my cup of tea. I used it because it seemed to be "the way" to write documents, but deep down it always bugged me. Then I got into using latex for document creation and it's like a whole new world opened up. Structured documents, what an amazing thing. It took me a while to get used to the latex way, but that's because I had to de-program myself of those bad habits. Now I wouldn't use an office suite for anything ever.

Here's how Ms Office works. You sit down at the desk, your friend points to the keyboard, you press a key, the character comes up on the screen. This is pretty much the intellectual level at which most people use Ms Word. Of course, the software has other features, it has functions to get things done faster/better/nicer. But most people, and that's probably 90% or more, don't know/don't care/wouldn't care about them. As long as they can just plug along.

I gave a presentation about two weeks ago, I had 20 slides, and it took me a couple of hours to write the presentation in latex. I didn't have to re-learn anything, because latex is the same whatever document you're writing. The process was entirely smooth, as it wasn't my first time, so I knew what I was doing. I've done maybe three presentations in latex, and by the third one I felt completely comfortable.

Last week my group was obliged to give another presentation, and this time another guy did the honors. But we all wrote it together, so he manned the computer while we discussed the content. A computer screen tends to draw your eyes in, but I was fighting the urge, I really couldn't stand it. First the guy designed a little logo in Ms Paint, which he included into the slides. When I said the logo could use a slight modification, he had to change the image on every slide one by one. Then he thought it would be nice to have a little index of the presentation on the side of the slides, which was a nice touch. So everytime he added a slide or renamed another, he would update the index on every single slide manually. Then it was the layout.. when he combined images with text, or even just when adding lists of points, often the layout wouldn't fit, there would be a forced linebreak, or something would clash, so he had to reposition the text fields. He spent more time doing these updates than actually adding content, in the form of keywords mostly. I felt like chewing my arm off watching this.

Yes, Ms Powerpoint might just have templates. And it might just have indexing. But what's the difference when noone uses this? It was certainly not the first time the guy made a presentation, I'm sure he'd done plenty of them before. But this was his level of usage. Because Powerpoint encourages you to act an idiot, that's what people become.

Needless to say, this has very little to do with productivity. Busy work, that's what this is. It's the computer equivalent of digging holes and then filling them. The general level of document creation is just appalling to me. That Ms Office be the standard for exchanging documents, and seeing how bad they look and how incredibly messy the whole process is, it's astounding.

upgrading ubuntu - the horror

February 1st, 2007

I can't believe how long it's been since we started using distributions, picking the one we like and staying with, because we perceive certain advantages the others don't have. And when a new version comes, we install it, replacing the old. How much longer will it be before it is possible to *upgrade* a distro without friggin breaking it in half??

I installed Ubuntu Dapper on the "family" pc back in Norway in.. July...ish. I'm back in town now for a few days and as I logged in, it still worked beautifully. Nothing broken, no problems, nothing. But Edgy has been out for some time, and keeping up with updates is generally recommended to stay more or less in the loop long term. So I decided to update. I looked up how in the documentation and followed the instructions. It started off so well that I was impressed. It first removed all my "custom" sources in sources.list and then it set off. I had used Automatix to install multimedia stuff, but I think that was the extent of my "modifications". There was one entry for the latest amarok in sources.list, but the rest I think were standard.

But it did not carry on so. At one point I got a big fat warning about some package not being able to install/configure/whatever. Then I got a dozen more of them. Once the process was done, not throwing a fatal error my way, the little icon indicated that "a reboot is required", so I did, thinking I could probably fix the bugs when I do. It was not to be. Upon boot, X wouldn't start. I was getting strange errors about a permission problem with /dev/null or something. The system was completely broken and I really didn't feel like resuscitating. I use Ubuntu because it's no hassle and "just works". :rolleyes:

And there ends the tale of the upgrade. Once again, after so many years, an upgrade between versions leaves the system completely broken. How much longer do we have to wait until this ceases to be a problem? I can appreciate that it's complicated, but how many other complicated problems have been solved?