Groesbeek, view of the 'National Liberation Museum 1944-1945' in Groesbeek. © Ton Kersten
Fork me on GitHub

Installing Pandoc

2013-01-26 (132) by Ton Kersten, tagged as linux, pandoc

John Macfarlane released a new version of Pandoc that has a lot of new enhancements. A lot of things have changed in the Markdown input types and it’s now compatible with PHP Markdown. This is very nice, because a lot of implementations use the extensions defined by PHP Markdown.

I downloaded the dmg file to install it on my MacBook Pro and it works like a charm.

So, I decided to install it on my new CentOS 6 server to build documents there. Well, I was in for a nice surprise.

After cloning the source from github I started as documented in the INSTALL file

make prep

and now I get

Resolving dependencies...
cabal: cannot configure directory-1.1.0.0. It requires old-time ==1.0.*
For the dependency on old-time ==1.0.* there are these packages:
old-time-1.0.0.0, old-time-1.0.0.2, old-time-1.0.0.3, old-time-1.0.0.4,
old-time-1.0.0.5, old-time-1.0.0.6 and old-time-1.0.0.7.
However none of them are available.
old-time-1.0.0.0 was excluded because pandoc-1.10.0.5 requires old-time ==1.1.*
old-time-1.0.0.7 was excluded because pandoc-1.10.0.5 requires old-time ==1.1.*

etc.

I kept tweaking the makefile and tried almost everything possible, but I was caught in a cyclic dependency loop. So, time to rethink and use Google.

I had already figured out it had to do with a cabal and ghc version that are to old, so it’s time to update.

I found newer Cabal versions at JustHub.

I started removing every RPM with haskel or ghc in the name and removed ~/.cabal and ~/.ghc directories to start of fresh. Then:

sudo rpm -Uhv
http://sherkin.justhub.org/el6/RPMS/x86_64/justhub-release-2.0-4.0.el6.x86_64.rpm
export PATH=/usr/hs/bin:~/.cabal/bin:$PATH
cabal install cabal-dev
cd ~/pandoc
make prep
.
.

Now it compiles but it breaks with:

make install
cabal-0.14.0: Error: some packages failed to install:
pandoc-1.10.0.5 failed during the tests phase. The exception was:
ExitFailure 1
cabal --config-file=/home/tonk/qq/pandoc/cabal-dev/cabal.config:
/usr/hs/tools/cabal-0.14.0 failure (return code=1)
make: *** [install] Error 1

Some tests fail, but I just removed --enable-tests from the Makefile and I got a working executable. Simply copy it to the ~/.cabal/bin directory, install the man-page and everything is fine.

I think it should be simpler, but for now I’m a happy camper.

rsync on a not standard port

2013-01-21 (131) by Ton Kersten, tagged as linux, sysadm

Today a colleague asked me to sync some files to a server that is not listening on SSH port 22.

I normally create a configuration entry in my ~/.ssh/config file, like

Host tosync
    Hostname syncer.example.com
    Port 1234
    User syncuser

and then command

rsync -va --progress --inplace . tosync:

But this time I didn't want to create the entry in my SSH configuration, because I need this trick in a script. So I started to read the rsync manpage and after some experimenting I found

rsync -va --progress --inplace --rsh='ssh -p1234' . syncuser@syncer.example.com:

This syncs the current directory to host syncer.example.com on port 1234 as user syncuser.

Ansible issue playbook

2012-11-23 (130) by Ton Kersten, tagged as ansible

Playing with Ansible I did get the idea to make a nice welcome message when you log in to a server. This message needs to be placed in a file, which is configured in /etc/ssh/sshd_config with the banner option. I call this file /etc/issue.

Of course I want to deploy this file with Ansible, so I first defined an entry in the hosts file. This looks like this:

# Settings for master
[master]
master

# Variables for master
[master:vars]
location=cow shed
room=ESX5i
issueremarks=This is the master Ansible server. Please be carefull!!

and this is parsed through a Jinja2 template which looks like

{{ figlethost.stdout }}

  ------------------------------------------------------------------------------
                               -- W A R N I N G --
                  UNAUTHORIZED ACCESS STRICTLY PROHIBITED!!
  ------------------------------------------------------------------------------
           System Name : {{ "%-25s"|format(ansible_hostname) }} Location : {{ location }}
           Managed by  : {{ "%-25s"|format(name)             }} Room     : {{ room }}
  ------------------------------------------------------------------------------
{% if issueremarks is defined %}
{{ issueremarks.center(80) }}
  ------------------------------------------------------------------------------
{% endif %}

When combining this all into a playbook this results in

---
- hosts: all
  tasks:
      - name: install figlet
        yum: pkg=figlet state=latest
      - name: figlet name
        command: /usr/bin/figlet -c -w 80 ${ansible_hostname}
        register: figlethost
      - name: deploy issue file
        template: src=issue.in dest=/etc/issue owner=root mode=0444

As you can see there is a registered variable, called figlethost which contains the hostname parsed through figlet. And putting it all together this gives

                                            _
                        _ __ ___   __ _ ___| |_ ___ _ __
                       | '_ ` _ \ / _` / __| __/ _ \ '__|
                       | | | | | | (_| \__ \ ||  __/ |
                       |_| |_| |_|\__,_|___/\__\___|_|

  ------------------------------------------------------------------------------
                               -- W A R N I N G --
                  UNAUTHORIZED ACCESS STRICTLY PROHIBITED!!
  ------------------------------------------------------------------------------
           System Name : master                    Location : cow shed
           Managed by  : Ton Kersten               Room     : ESX5i
  ------------------------------------------------------------------------------
            This is the master Ansible server. Please be carefull!!
  ------------------------------------------------------------------------------

Ode to the Haggis

2012-10-26 (129) by Ton Kersten, tagged as humor

Hendrik Jan Thomassen not only sent me the tail of Haggis hunting but also a nice ancient poem as an ode to Haggis.

Here it is:

The haggis season has begun
and all over Scotland every gun
Is taken down with loving care
Though some prefer the haggis snare
The haggis are a wiley lot
That's why they are so seldom shot

Then hidden in the highland heather
Great hairy Clansmen crouch together
And having laid the haggis bait,
a life-like haggis on a plate,
One cries out loudly: ''There's the noo''
Which means the haggis are in view

It's flying upside down and low
The guns all fore but they're too slow
For thought it's rather old and fat
They're awful hard to hit like that

And as it flies off into the mist
Great hairy clansmen shake their fists
Scream their curseds to the crags
Stamp on empty haggis bags
And so the haggis get away
to live until next Christmas day
''Come back haggis''

And that's the reason it is so rare
This strange traditional Scottish fare

We're that haggis hi hooray
It's hog'manay not Christmas day

How to hunt the Haggis

2012-10-22 (128) by Ton Kersten, tagged as humor

Most people are familiar with my love of Scotland, single malt and (of course) haggis. But most people do not have a clue what haggis is and when you tell them, they walk out in disgust.

But a colleague of mine found out that haggis is just an animal that can be hunted in the Scottish Highlands.

This is how it's done:

.....asked me how the haggis were hunted so I explained that there were two types of haggis, who, because they lived on the steep slopes of the Scottish Highlands, developed legs of different lengths on their left and right sides depending upon which way they travelled round the mountain to graze. With the knowledge of which type of haggis one was hunting, the procedure was quite simple.

A large 'catch fence' was erected around the base of the mountain and a piper was sent up the mountain to play his bagpipes while walking contrary to the normal direction of rotation of the haggis. This put the fear of G*d in to the wee creatures who tried to run away, but of course their short legs were now down-hill so they soon overbalanced and rolled down the mountain into the catch fence at the base where they were then easily caught and euthanized.

Thanks to Hendrik Jan Thomassen.

Resize a partition

2012-10-19 (127) by Ton Kersten, tagged as sysadm

I often have to increase the size of a virtual disk on a virtual machine. But I always seem to forget how to do it. I guess I have done it over a 100 times and I cannot remember exactly how I did it. So this blog entry is to help people on how to do this and as a reminder to myself.

This example is done on a virtual machine with CentOS 6, but it can be done on every Linux. And in the fdisk examples I have left out some of the not to interesting lines.

Oke, here we go:

First, shut down your virtual machine and increase the disk size. Then start your virtual machine and go to the console. Now you have a virtual machine with a new disk size, but the current partition table needs to be adjusted to the new disk size. I know it’s possible with parted, but I always seem to end up on systems where it’s not available. So I just use fdisk.

# fdisk /dev/sda

Now give the p command, which prints the partition table and make a note of the start cylinder of the Linux LVM partition. This is the partition we are going to increase.

Please be very careful This trick only works if the partition you want to resize is at the end of the disk and contains a logical volume type system.

Command (m for help): p

Disk /dev/sda: 17.2 GB, 17179869184 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
/dev/sda2              65        2089    16264192   8e  Linux LVM

Delete the LVM partition (we will recreate this later)

Command (m for help): d
Partition number (1-5): 2

and create a new partition with the original starting point. The starting point should be the same, because all the partitions meta data is at the start of the partition.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2

And fill in the start cylinder of the LVM partition we deleted above

First cylinder (1-25600, default 1): 65
Last cylinder, +cylinders or +size{K,M,G} (65-25600, default 25600):
Using default value 25600

and change the type to Linux LVM

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sda: 26.8 GB, 26843545600 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2          64      262144   83  Linux
/dev/sda2              65        2089    24567892   8e  Linux LVM

If you agree with the new layout, write it to disk with the w command and quit with q. If it’s not the disk disk with the root volume on it, it could be possible that you can skip the next reboot. Just a partprobe could do the trick.

# reboot

First it’s needed to resize physical volume.

# pvresize /dev/sda2

Make sure you know how much free space you now have

# vgdisplay

Make a note of the “LV Name” of the logical volume you want to resize

# lvdisplay

Resize the logical volume. I use gigabytes as an example here.

# lvresize -L +[Size]GB [LV Name]

Resize the file system on the logical volume.

# resize2fs [LV Name]

MySQL backup error

2012-08-09 (126) by Ton Kersten, tagged as linux, mysql

After upgrading my MySQL database server from version 5.0.95 to 5.1.61 I suddenly got these errors in the backup logging.

mysqldump: Couldn't execute 'SELECT /*!40001 SQL_NO_CACHE */ * FROM `EVENTS`': Cannot
proceed because system tables used by Event Scheduler were found damaged at server start
(1577)
dbdump gave errorcode 2 for database 'information_schema'
2012-08-09 09:07:53 -> Finished MySQL backup on host 'xxx.tonkersten.com'

Hmm, no idea what has happened. I hope I didn't do something stupid.

Asking Google I found out that the information_schema tables where changed during the upgrade and that I could recreate the error with:

mysql> use information_schema
Database changed

mysql> SELECT /*!40001 SQL_NO_CACHE */ * FROM EVENTS;
ERROR 1577 (HY000): Cannot proceed because system tables used by Event Scheduler were found damaged at server start
mysql> Bye

So I tried to repair the error with:

mysql_upgrade -u root -h localhost -p --verbose

but still the same error.

Turns out that the MySQL server needs to be restarted for this to work.

Now I get

mysql> use information_schema
Database changed

mysql> SELECT /*!40001 SQL_NO_CACHE */ * FROM EVENTS;
Empty set (0.00 sec)
mysql> Bye

CDE is Open Source

2012-08-06 (125) by Ton Kersten, tagged as code, linux, news

Today the classic, and old, Common Desktop Environment (a.k.a. CDE) was released into the Open Source world.

You can get the very alpha version at SourceForge.

I haven't been able to get a running version by now, but I keep trying.

Good job, guys.

git status in the prompt

2012-07-23 (124) by Ton Kersten, tagged as code, git, linux, sysadm

Working with git a lot I decided I needed some git status in my prompt.

I searched the web and some solutions where almost what I wanted and this one by Sebastian Celis came very close.

But it didn't work with my version of zsh, because that didn't seem to understand the =~ operator.

I also think Sebastian makes things over complicated and so I changed some things aroud.

This is what I came up with:

First make sure this code is included in your ~/.zshenv file

prompt_git_info()
{
    unset __GIT_BRANCH
    unset __GIT_BRANCH_STATUS
    unset __GIT_BRANCH_DIRTY

    local st="$(git status 2>/dev/null)"
    if [[ -n "$st" ]]; then
        local -a arr
        arr=(${(f)st})

        if [[ $arr[1] = *Not\ currently\ on\ any\ branch.* ]]
        then
            __GIT_BRANCH='no-branch'
        else
            __GIT_BRANCH="${arr[1][(w)4]}"
        fi

        if [[ $arr[2] = *Your\ branch\ is* ]]
        then
            if [[ $arr[2] = *ahead* ]]
            then
                __GIT_BRANCH_STATUS='ahead'
            elif [[ $arr[2] = *diverged* ]]
            then
                __GIT_BRANCH_STATUS='diverged'
            else
                __GIT_BRANCH_STATUS='behind'
            fi
        fi

        if [[ $st = *nothing\ to\ commit* ]]
        then
            __GIT_BRANCH_DIRTY='0'
        else
            __GIT_BRANCH_DIRTY='1'
        fi
    fi

    if [[ -n "$__GIT_BRANCH" ]]
    then
        local s="("
        s+="$__GIT_BRANCH"
        case "$__GIT_BRANCH_STATUS"
        in
            ahead)      s+="↑"  ;;
            diverged)   s+="↕"  ;;
            behind)     s+="↓"  ;;
        esac
        if [[ "$__GIT_BRANCH_DIRTY" = "1" ]]
        then
            s+="⚡"
        fi
        s+=")"

        printf " %s%s" "%{${fg[yellow]}%}" $s
    fi
}

and set your prompt to something like this

PS1=$'$C_CYAN%n@%m$(prompt_git_info) $C_WHITE%2~$ $C_OFF'

When I now switch to a directory that is under control of git I get gt status messages in my prompt, like

tonk@mach (master) ~/dir$ git commit -a
[master fca5ac3] Nice, new stuff.
 6 files changed, 88 insertions(+), 12 deletions(-)
tonk@mach (master) ~/.dir$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
tonk@mach (master) ~/.dir$

No network on CentOS 6

2012-07-17 (123) by Ton Kersten, tagged as linux, sysadm

When installing a minimal CentOS 6 system, minimal really, really means minimal. After a reboot the network interfaces do not start, so network connectivity is non existing.

Looking into that I noticed that the file /etc/sysconfig/network-scripts/ifcfg-eth0 contained

DEVICE=eth0
HWADDR=11:22:33:44:55:66
NM_CONTROLLED=yes
ONBOOT=no
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no

The lines that mess things up are NM_CONTROLLED=yes meaning the interfaces are managed with NetworkManager, which isn’t actually installed as part of a minimal install. You want a minimal install, you get a minimal install. And ONBOOT=no, meaning "do not start the interface on boot". How stupid is that!

The trick is to run something like system-config-network-tui to set the IP addresses manually, but as you might imagine, that's not installed either.

So you best edit /etc/sysconfig/network-scripts/ifcfg-eth0 by hand and set it to:

DEVICE=eth0
HWADDR=11:22:33:44:55:66
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no
IPADDR=192.168.0.1
NETMASK=255.255.255.0
GATEWAY=192.168.0.254
DNS1=192.168.0.254

The USERCTL=... line is optional: If set to yes it lets non-root users control the interface.

After setting this a service network restart will do the trick.