Charlie for Mayor
April 14th, 2008Start wearing purple
April 13th, 2008(OK, the Gogol Bordello guy is from Ukraine not Poland but I am lacking in inspiration at this time)
At mbm/Mel/Tom’s triple (yeah, really) leaving drinks Friday night, I was talking to Kvik about his forthcoming wedding. It went a bit like this:
Me: When is it you’re getting married?
Kvik: August
Me: Wow, not long to go…
Kvik: Yeah! I asked everyone if they wanted to come but only mbm replied…
Me: What!? I never heard about this. Where did you say this?
Kvik: In [obscure IRC channel]
Me: People go days without looking in there!
Kvik: Meh.. you want to come?
Me: Yeah! Of course!
Kvik: Excellent!
Me: Great..! Well, as long as it’s in London..
Kvik: No, it’s in Poland!
Me: [pause] Ah.
Today I’ve examined this to be sure it wasn’t just the effects of alcohol but, well, why not? So I guess I am going to Poland in August.
Aye, and what have the Romans ever done for us!?
April 12th, 2008Seen on the Intarweb:
“ScotLUG owes nothing to the UK and I didn’t (and don’t) see why we should recognise such a redundant concept.”
Married To The Sea
April 12th, 2008I’ve been looking for that site for ages! Ever since I saw:
and then later forgot it.
Links for 2008-04-11
April 11th, 2008- Belly button as animal arsehole — the look for 2008?
- Representative tries to put the fear of God in atheist — Chicago Tribune
Links for 2008-04-07
April 7th, 2008- Wanted Poster! A call for the UK Prime Minister’s fingerprints — Privacy International
Links for 2008-04-06
April 6th, 2008- Baby’s First Waxing — there is something terribly wrong with the world
- How risky are nuclear weapons?
- The “Blog” of “Unnecessary” Quotation Marks
Sleeping deterministically in a shell script
April 1st, 2008Occasionally on a Unix machine you might want a task to happen at the same time every iteration, but not have to specify the exact time. An example of this could be when getting multiple machines to mirror something from a master — you would like this to happen say every half an hour, but not for every machine to do it at the exact same time.
If you are distributing out your configs from a central place then you can’t hard code a time since then every machine will hit at once. Also if you are suggesting to others a config to use, you do not want to specify a time otherwise they will hard code it too.
A technique I’ve used for a few years is to use the “hostid” command to get a sort of serial number for each host:
ruminant$ hostid 0dd44bc6 specialbrew$ hostid a8c00800
I use this inside sleep commands to pause some tasks for a “random” but deterministic amount of time. For example, in /etc/cron.daily/000-sleep-deterministically I have:
#!/bin/bash sleep $(($(printf \%d 0x$(hostid)) \% 24))h
The printf command changes the hex string into a decimal number and then the outer $(()) construct does a modulus 24, so the whole thing will return a “random” number between 0 and 23. The script then sleeps for that many hours.
As it is named 000-sleep-deterministically it is the first script to run out of /etc/cron.daily/ and thus holds up the entire daily cron routine by this “random” number of hours — but because it is deterministic, the next run will still be exactly 24 hours later, so we still get a single daily cron run at the same time every day.
The point is that when all the virtual machines on one server do their daily cron it won’t be at the exact same moment for all of them, which can be a real issue when you have 30+ machines on one piece of hardware.
I use the same thing for other cron jobs, often calling them like:
*/30 * * * * sleep $(($(printf \%d 0x$(hostid)) \% 30))m && some_heavy_task
This fires every half an hour but then sleeps for between 0 and 29 minutes. I can use the same cron job on every machine but not have to worry about multiple clients running some_heavy_task and all hitting the server at :00 and :30.
“hostid” doesn’t really produce a random number of course — it’s based on the IP address of the host. dg pointed out that “hostid” is still broken in Ubuntu if you have 127.0.1.1 in /etc/hosts. If you can’t use the workaround suggested then maybe you could use the MAC address of an interface or similar.
This technique was also discussed on Debian Administration a while back, but the site seems to be down right now so I can’t find the exact article.
Links for 2008-03-30
March 30th, 2008- Penetrating Wagner’s “Ring”
- Hackers Assault Epilepsy Patients via Computer — Wired
- Business Owners, Customers, Unicorns Upset Over Controversial Billboard
- Sidewalk Psychiatry
- Man Caught Having Sex with a Picnic Table — First Coast News
- Lower Back Tattoo Stickers FINALLY Available For Kids At Toys ‘R Us
