Redoing RabbitMQ’s tutorial – part 4

RabbitMQ's tutorial 4' scope is: subscribe only to a subset of the messages.

The following shows an implementation of that tutorial (sort of) in Perl with Net::RabbitMQ. As previously, the code is just sketched out and definitely not an example of style: it just aims to show how things work. Once I'll get all the tutorials sorted out in Perl, I'll build on these sketches to create something "real".

Enjoy! … Continue reading

Removing spurious ^M in Emacs when using tramp

I had this problem since I switched from XEmacs to Emacs: when using tramp, filenames or buffer information all got a spurious trailing ^M. I have always worked around this problem, but today I decided it was enough.

This snippet in my .emacs file fixed it:

  ;; trying to get rid of those annoying ^M's in buffer names
  ;; and file names when using tramp
  ;; http://stackoverflow.com/q/2567600
(setq default-buffer-file-coding-system 'utf-8-unix)
(prefer-coding-system 'utf-8)

Credits go to the people at StackOverflow

Redoing RabbitMQ’s tutorial – part 1

I am experimenting with RabbitMQ and Perl for a pet project of mine: gravity.

The Perl module Net::RabbitMQ seems to be usable, finally. I decided to give it a go, and reproduce with Perl the python scripts shown in the official RabbitMQ tutorial.

Tutorial 1 starts, unsurprisingly, with an "Hello world!" example:

let's send a message, receive it and print it on the screen. To do so we need two programs: one that sends a message and one that receives and prints it.

I am not going to redo the whole tutorial, just show the finished code. Please refer to the tutorial and to Net::RabbitMQ's documentation for the details. … Continue reading

cf-runagent is not obsolete

I sometimes see comments in the cfengine community, stating that cf-runagent is somehow useless. In its detractors' opinion, cf-agent runs by default every 5 minutes, so when you request cf-runagent to run the agent, chances are that it already did it by itself.

Well, fellow cfengineers, I strongly disagree. To me, cf-runagent is a powerful gun in my toolbox. Here's why.

The real big advantage of using cf-runagent is that you can choose which hosts you want to trigger a run on, and you can set classes in the remote agent (assuming you have cf-serverd properly configured). Combining these two features together, it's trivial to trigger one-off actions remotely (e.g.: deploying a new version of a software), and to do that in a one-two-many fashion: try on one node; if an action works on one test machine, try it on two; if it still works, install on a few more until you're confident it will work across the board; then, trigger the action everywhere.

I used that technique when replacing puppet with cfengine. Using cf-runagent, I was able to remotely enable and disable any of the two and, when the time came, to remove puppet from the nodes altogether (software packages and configurations). Isn't that reason good enough to keep using, developing and improving cf-runagent? ๐Ÿ˜‰

bundle agent SeasonGreetings
{
  reports:
    December.(Day24|Day25)::
      "Merry Christmas!" ;
}

An eye on the clock

Recently I was trying to make sane a system clock that, for some reason, suddenly slowed down to a crawl. I started to fiddle with adjtimex, and I needed a way to verify the reaction of the clock itself, and ntpd’s. On one window, I had a watch ntpq -c pe -c as running. On another, there was an ntpdate -q in a loop. In a third one, I wanted to monitor the changes in frequency (set by ntpd) and ticks (set by me). I found this one-liner pretty useful:

# while true ; do adjtimex -p | perl -alne '/frequency/ and $f=sprintf("%3.2f%%",100*$F[1]/32768000) ; /tick/ and $t=$F[1]-10000 ; END { print scalar(localtime),"\tf=$f\tt=$t" }' ; sleep 30 ; done

This snippet assumes that the frequency tolerance of the clock is 32768000, and that the normal value for ticks is 10000. Check the output of adjtimex -p and the man page to verify this fits your system, too.

The dirty dozen

I still remember very well the first (and only, for now) time I held a seminar for my colleagues in Opera: “NTP, a misunderstood protocol” in February 2011. Now fast forward to 2012. We had one leapocalypse between June and July, one bogus leap second one month later, and a bit of disaster about one week ago: nearly two years have passed since I held that seminar, and NTP is still a misunderstood protocol. … Continue reading

Location detection in cfengine

My employer provided me with a laptop that I usually use when working remotely (whether on a VPN or not); more rarely, that laptop could also be connected to the company network in Oslo. Usually, when working remotely I am either at home in Oslo, or in one of my relatives' house in Sardinia.

Depending on where I am, the laptop's configuration needs to be changed or augmented, in particular for these services:

  • ntpd
  • DNS resolver
  • software updates

Being an NTP junkie, I want my ntpd configured in the best possible way, and no: I am not going to point to some random servers in the pool that could be on the other side of the world. Whether I am in Italy or in Norway, I want to use servers from the pool that are either in the same country, or in a country nearby.

When I am in VPN, the client decides for me the search list for DNS domains: I want that list to be enriched with all the domains I actually need.

When I am on a low bandwidth network, I want the system to refrain from automatically checking for system updates: it's much better if I do it manually when, for example, I am not going to rot my mother's skype calls.

For all these reasons, I decided to implement a simple location detection process in cfengine that keeps my laptop correctly configured wherever I am. Besides, since the agent runs every 5 minutes, I can be sure that the configuration changes (e.g. when I enter the VPN) will take place quickly.

…and there could be more if you think about it! E.g.: what about having specific firewall rules depending on where you are? If you are in the office, you may not care if someone tries to access your laptop via SSH as that someone could be… you ๐Ÿ˜‰ But suppose you were not able to determine your current location: would you leave free access to your laptop? … Continue reading

My cfengine policies explained – part 4

The policy we are about to see this time ensures that the hosts file contains at least the small set of records that every hosts file should always include: a record for the IPv4 localhost, a record for the IPv6 localhost, and a record that associates one IP of the host with the FQDN and the hostname in that order. It should also contain a set of IPv6 standard addresses.

This policy is definitely not ready for prime time, and I discourage you from using it (unless you are willing to patch it and share your patch with the rest of the world). Nevertheless, it is a good example of how, with cfengine, you can take care of just a few details in a file, leaving the other parts untouched. … Continue reading