September 2008 Archives
Lazy client, part II
I want to quiet, full blown PC, without fans nor a harddisk in my living room. See my other blog about this subject
Currently I'm thinking about the following setup:
- NFS4 root
- some sort of configuration management
I wanted to use puppet, but after seeing it use more than 30% of my main memory -- This is on a AMD64 Ubuntu server -- I was ready to ditch it.
I've also have experience with cfengine, so I'm going to use that. In
conjunction with svn. I'm going to store all my configs + cfengine
files in one repository. The modus operandi will become:
- edit a file
- check it into subversion
- periodically check out the subversion to a directory where cfengine will look for updates - this will probably happen every 5 minutes
- let cfegine distribute the changes to other machine
- let the
cfagenton the different machine figure out what to do.
So this blog is now becomming a post on how to configure cfengine :)
CFegine
The shortest none trivial snippet I could think of is
control:
actionsequence = ( shellcommands )
shellcommands:
!motd::
"/bin/echo Danger Robinson!" define=motd
motd::
"/bin/echo Ha ha after the first echo!"
Note: no spaces are allowed in define=motd. With this you can get
extra ordering.
From here we can do wilder stuff, like for instance getting
a copy from the motd file and running a post processing
which is needed in Debian:
uname -snrvm > /var/run/motd
[ -f /etc/motd.tail ] && cat /etc/motd.tail >> /var/run/motd
/etc/motd is a symlink pointing to /var/run/motd.
All commands in the shellcommands section should begin with a
/, hence the weird looking: /usr/bin/[.
Going about this, I'm getting to the following snippet:
control:
actionsequence = ( copy shellcommands )
copy:
/home/miekg/svn/etc/branches/elektron/motd.tail
dest=/etc/motd.tail
mode=644
owner=root
group=root
define=motd_copied
shellcommands:
motd_copied::
"/bin/uname -snrvm > /var/run/motd"
"/usr/bin/[ -f /etc/motd.tail ] && /bin/cat /etc/motd.tail >> /var/run/motd"
Which will update /etc/motd if there is a change.
Subversion
I've created a subversion repository where I'm going to put these files
in. A cronjob will periodically check this out into /etc/cfengine so
that cfengine will pick up any new changes automatically.
Testing
I've found that sudo cfagent -Hnvf cfagent.conf is a very neat way to
test out any given cfagent.conf, before deploying it for real.
Later on I will blog some more about the precise setup I'm going to use.
Bash loadable modules
Or how to create new builtins for use in bash. Short answer: you can,
but it is not enabled by default (at least on my distribution, Ubuntu)
This is also something that is done much better in zsh.
Why do want this? SPEED!
Shell scripting is a very easy way to program, but forking all these helper programs takes a lot of time. So one way to speed up your shell program is to load these programs into the shell and making them a builtin.
bash
I needed the bash source for this to work. So download it and
compile it. Then in the examples/loadables you have some
new builtins, like cat, cut, head and then some.
Making cat a builtin, you need the enable command
$ type cat
cat is /bin/cat
$ enable -f /tmp/bash-3.2/examples/loadables/cat cat
$ cat type
cat is a shell builtin
Same goes for other executables. When updating my site with
nanoblogger, using cat and others as builtins made the
update much quicker. I shaved off some 20 seconds on a total
of 250 seconds; so it may be worth the effort.
zsh
Here everything worked out of the box, but there is currently
no cat builtin for zsh (I created one). But there are
other interesting builtins.
What you need: man zshmodules and zmodload. With zmodload
you can create new builtins.
For example, I made a cat builtin. Next I copy the cat.so to
/usr/lib/zsh/4.3.4/zsh
% type cat
cat is /bin/cat
% zmodload zsh/cat
% type cat
cat is a shell builtin
Unload with zmodload -u. Works like a charm.
Idea: GPS alarm clock
Imagine: You are sitting in a train and you want to be awake when you arrive at your destination. Now I would set the time I would arrive and hope the train isn't late.
Wouldn't it be nice to have some kind of gadget the works on GPS coordinates? You set the coordinates of where you want to be awake and the alarm sounds when you get there.
So an alarm not on time, but on location. Something for OpenTom

