Personal Web Page

Wednesday, December 17, 2008

 

Pull A String, A Puppet Moves

each man must realize
that it can all disappear very
quickly:
the cat, the woman, the job,
the front tire,
the bed, the walls, the
room; all our necessities
including love,
rest on foundations of sand -
and any given cause,
no matter how unrelated:
the death of a boy in Hong Kong
or a blizzard in Omaha …
can serve as your undoing.
all your chinaware crashing to the
kitchen floor, your girl will enter
and you’ll be standing, drunk,
in the center of it and she’ll ask:
my god, what’s the matter?
and you’ll answer: I don’t know,
I don’t know …

-Charles Bukowski

from Burning in Water Drowning in Flame. Not to be confused with:
Pulling Strings With Puppet: Configuration Management Made Easy

Labels: ,


Tuesday, December 9, 2008

 

This superblock wants to tell you something

The problem is, when you reboot a Linux server, it will probably be back up quickly, but it may want to check all the filesystems, which takes substantially longer. How do you know what to expect? The conditions that can trigger a fsck (the time and number of mounts since the last one) are stored in the superblock, which is annoying to inspect before planning an outage.

It doesn't seem worth doing the checks myself every time, but it would be nice to know. I didn't follow up on this until someone else complained about it, convincing me there was enough demand to justify a better user interface. Now I install the following script as a daily cron job with standard output redirected to the message of the day file. I decided to use a few older idioms to support Python 1.5.2 installed on Red Hat 7.3 (Valhalla). I would have just used awk if it had a decent date parsing library.


#!/usr/bin/env python
# Author: Jared Brothers
#
# Which ext2/3 filesystems will require a fsck, delaying the next reboot?
#
# Inspect the superblock of mounted filesystems with debugfs(8)
# to check whether the max mount count or time interval have been
# exceeded. List the overdue filesystems' mount points.
#

import os, sys, re, time, popen2, string
fsck = []
debug = 0
name = os.path.basename(sys.argv[0])

if os.geteuid() != 0:
sys.exit(name + ": not run as root")

fd1, fd0, fd2 = popen2.popen3("/bin/mount")
for line in fd1.readlines():

if re.search("type (ext2|ext3)", line):
fields = string.split(line)
dev = fields[0]
if debug: print("dev: " + dev)

fs = fields[2]
if debug: print("fs: " + fs)

fd1, fd0, fd2 = popen2.popen3("/sbin/debugfs -R show_super_stats " + dev)
for line in fd1.readlines():
fields = string.split(line)

if re.search("^Mount count:", line):
count = int(fields[2])

if re.search("^Maximum mount count:", line):
max = int(fields[3])

if re.search("^Last checked:", line):
last = string.strip(string.join(fields[2:], " "))

if re.search("^Check interval:", line):
check = int(fields[2])

if max != -1:
left = max - count
if debug: print("left: " + str(left))

if check != 0:
next = time.mktime(time.strptime(last)) + check
if debug: print("next: " + time.asctime(time.localtime(next)))

if max != -1 and left <= 0 or check != 0 and next <= time.time():
fsck.append(fs)

if len(fsck):
print("These ext2/3 filesystems are due for a fsck: "
+ string.join(fsck, ", "))

My Photo
Name: Jared Brothers
Location: New York, NY, United States

Links

Archives

November 2008   December 2008   January 2009   May 2009   June 2009   July 2009  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]