Archive for December, 2011

If you’re going to write an init script, do it properly

“How do I make my Linux process auto-start?” is a fairly common question.  The answer is fairly simple, thank goodness.  Write a shell script, put it in /etc/init.d and run <code>update-rc.d myScriptName defaults</code>.  And you’re done.

Except you’re not, probably.  If you haven’t written your script correctly, you might well hang the boot process.

Init.d and all those rc.d folders are part of the Unix System V init process.  Unlike modern replacement Upstart, init starts processes in series, never in parallel.  If your startup script doesn’t exit, then init won’t either.  If you’re written a really lazy script that doesn’t detatch after starting a process, then you’re screwed 🙂

Another thing to watch our for is how your script is called.  Init will pass either “start” or “stop” to the script depending on what the process should be doing.  If you don’t handle the difference between these (in a case statement, say) and instead just execute the same code whenever the script is run, you’re going to have a really fun time when you try to shutdown or restart your server.  Especially if your script doesn’t detatch and hangs init.  Because then you’re not going to be able to shut down your server cleanly.

It’s been a fun week for my test VMs!

Here’s a little bonus for you.  If you want to start several processes in a specific sequence, you can do this by writing your startup scripts so they don’t exit until each process is ready.  Init allows you to determine the order in which you start processes within a runlevel (that’s what the numbers in the symlink filenames mean) and you know from the above that you can prevent init from processing the next script in it’s queue.  Use this knowledge wisely.


Running a program as administrator

Windows Vista and Windows 7 have a feature called UAC, which stands for User Account Control. It’s a good idea – programs can’t touch certain files or take certain actions unless you, the user, explicitly grant them administrative privileges. Sounds useful!

To get to the point of this article, as much as UAC is a good idea, it can be very annoying sometimes. Say you want to edit a config file in C:\Program Files\MyApp with Notepad++, your favourite text editor. Normally you’d right click on the file and click “Edit Notepad++” in the context menu. This won’t work in Program Files, though, as it’s a restricted folder. You need to launch Notepad++ with admin rights before you can open your file. (You might be able to read the file without admin rights, but you certainly won’t be able to save your changes!)

Or say you want to do something nifty from the command prompt. In Linux, you’d preface your command with sudo and enter your password when prompted. In Windows, you can’t do that. You need to launch your command prompt with elevated privileges, like so:

That’s: Start -> type “cmd” -> right click -> Run as administrator. Easy.

There’s an obvious downside to this, of course. In Linux you can elevate a single command and then return to being a limited user, all from the same shell. In Windows, though, your command prompt has to be elevated from start to finish. It’s the product of two different cultures. In the Linux world, the command line is king. Everything can be done from it, and it’s usually the best way of doing things. Windows expects you to work with the GUI, though, only dipping into command line mode when you absolutely have to. The GUI has almost everything you need, and you only use the command line for brief periods of time to do obscure things, generally. From that point of view, it makes sense to not have added the ability to elevate commands from within cmd, because you’re not expected to work like that. Completely understandable, but still a shame. Not to mention the source of a lot of nerdrage 😉


Why is Windows 7 bluescreening?

After upgrading from Windows XP to Windows 7, I never thought I’d see the old blue screen of death again. Wishful thinking in action 🙁

About a month ago my Windows 7 Ultimate computer started crashing with a blue screen of death whenever I connected a USB drive. The short-term solution was simple – find other ways to transfer files around. Long term, though, that was no good. I needed to find a real solution.

I noticed that whenever Windows crashed, it was outputting what it called a “minidump” in C:\Windows\Minidump. I didn’t have anything installed that could open the dump files, though, and the Microsoft Debugging Tools webpage seemed to suggest that you needed an MSDN subscription to get the tools for Windows 7. Luckily, it was just misleading/plain old wrong – the link for “Windows Vista or Previous Versions” is equally valid for Windows 7.

You can download WinDbg, the tool we’re going to use, here: Click the download button, run the program once it’s downloaded and then select the Debugging Tools option under Common Utilities.

Once you’ve got that installed, we want to make it easy to load. From an elevated command prompt (Start -> type “cmd” -> right click on the “cmd” entry and click “Run as administrator”):
cd C:\Program Files\Debugging Tools for Windows
windbg.exe -IA
WinDbg is now set to open when you double click on a .dmp file.

Now, we need to copy the crashdump out of C:\Windows\Minidump and into a folder where you don’t need admin right to read from it. Then double click on it and let’s see what WinDbg has to say.

Aha! It’s PDFsFilter.sys, a driver (surprise, surprise). A quick Google search later and I’ve found the perp – Raxco PerfectDisk, which I installed just before the crashed started, come to think of it. I uninstalled it and now I can mount USB drives again. Horray!


HP Touchpad – surprisingly nice to type on

I managed to get an HP Touchpad in the end-of-line firesale a few months ago. It’s subtly integrated itself into my life in many ways since then. What I want to talk about today, though, is the keyboard.

I hate touchscreen keyboards with a passion. My current phone is the Motorola Milestone 2, which has a full hardware qwerty keyboard. My previous phone was the Android G1, which also has a full hardware qwerty keyboard. I don’t enjoy typing on touchscreens, I find the buttons too small, I find it hard to type at a decent speed on them and they just annoy me.

The HP Touchpad keyboard is different, though. Taking up half of the tablet’s screen by default, it’s a nice size. My hands rest nicely on it and I can touch type at a decent speed without making too many mistakes. The virtual keys fall exactly where my fingers expect them to. It’s nice.

The only problem with it is that it lacks arrow keys. Moving to an exact place in the text is awkward without the ability to step one character to the left or right. Shame there’s not a vi mode for it 😉



Post queue test.  This should publish at 7am and be the only post that goes live today.


I’m starting to really like vim

Vi.  Vim.  You know the program I’m talking about.  You probably remember your first experience with it.  I do.  I couldn’t’t figure out how to get out of it.  Esc didn’t seem to work, control-c did nothing… I was trapped in a text editor from 1970!  Pure hell!

I’ve recently been working on headless Linux servers a lot.  Vi seemed like the best option for editing the endless scripts and config files.  It’s on every server, no matter the age (but the older ones don’t have the pretty colours) and you don’t need a mouse to use it, so it’s fine for working over ssh.

That’s a really big thing, actually.  Not needing a mouse.  It really speeds things up.  I can select text, cut, copy and paste, delete entire lines, find, replace and repeat what I just typed… All without moving my hands off the keyboard.

It’s kinda scary just how powerful it is, really.  The learning curve is painful, bit totally worth it.  I’m sure I’ll revisit this topic in a few months once I’ve got better at vi!


I am not good at blogging

This is fact, unfortunately.  It’s been, what, two years since I last updated?  Oops.

Comments (4)