Donnerstag, 26. Juni 2008

Problems setting up a NIS Slave Server

When I first trying to start a NIS slave server in my network, it complained:

Can't enumerate maps from server.example.com. Please check that it is running.


Appearantly, ypinit failed to enumerate maps using yphelper. The source of the problem turned out to be the DNS configuration. server.example.com had several DNS entries. I had to specify the name that the reverse lookup of its IP returned and then ypinit worked.

Mittwoch, 18. Juni 2008

Cleaning up animated swing controls

In its swing library, Java provides a timer class that can be used to animate controls. For example, one could create a blinking label as follows:

class BlinkLabel extends JLabel {
private static final int BLINK_INTERVAL = 500;

public BlinkLabel(String text) {
super(text);
ActionListener listener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(!isVisible());
}
};
Timer timer = new Timer(BLINK_INTERVAL, listener);
timer.start();
}
}


The problem with this approach is that the label will continue blinking even after its parent window has been disposed. Also, the label will never be garbage collected, since the timer still maintains a reference to it.

Here's the proper way to do it.

class BlinkLabel extends JLabel {
private static final int BLINK_INTERVAL = 500;

private Timer timer;
private ActionListener listener;

public BlinkLabel(String text) {
super(text);
listener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(!isVisible());
}
};

}

public void addNotify() {
super.addNotify();
timer = new Timer(BLINK_INTERVAL, listener);
timer.start();
}

public void removeNotify() {
super.removeNotify();
timer.stop();
timer.removeActionListener(listener);
timer = null;
}
}

Donnerstag, 22. Mai 2008

openvz VE slow to terminate

Sometimes openvz VEs take very long to terminate. The process can be shortened:

"ps ax | grep -w init" shows all the init processes. One of them belongs to the VE to be terminated. Use "vzpid " to find out which one. Then kill -9 that process.

get openvz to consent to checkpointing VEs with aufs, cifs and nfs file systems

openvz currently checks all file systems mounted under the VEs root against a static list of file system types. If one of the mounted file systems is not in that list, vzctl checkpoint complains about "unsupported fs type".

This can be fixed by extending the list of file systems and recompiling the vzcpt kernel module.

Here's how to do it under Ubuntu hardy:
cd /usr/local/src
apt-get -b source linux-image-2.6.24-17-openvz
cd linux-2.6.24
for a in debian/binary-custom.d/openvz/patchset/*.patch; do patch -p1 < $a; done
cd kernel/cpt
patch << EOF
--- cpt_files.h~ 2008-05-21 23:58:48.000000000 +0200
+++ cpt_files.h 2008-05-22 00:04:00.000000000 +0200
@@ -63,6 +63,9 @@
strcmp(mnt->mnt_sb->s_type->name, "ext2") != 0 && \
strcmp(mnt->mnt_sb->s_type->name, "simfs") != 0 && \
strcmp(mnt->mnt_sb->s_type->name, "unionfs") != 0 && \
+ strcmp(mnt->mnt_sb->s_type->name, "aufs") != 0 && \
+ strcmp(mnt->mnt_sb->s_type->name, "nfs") != 0 && \
+ strcmp(mnt->mnt_sb->s_type->name, "cifs") != 0 && \
strcmp(mnt->mnt_sb->s_type->name, "tmpfs") != 0 && \
strcmp(mnt->mnt_sb->s_type->name, "devpts") != 0 && \
strcmp(mnt->mnt_sb->s_type->name, "proc") != 0 && \
EOF
make -C /usr/src/linux M=/usr/local/src/linux-2.6.24/kernel/cpt modules modules_install
/lib/modules/2.6.24-17-openvz/extra
mv vz* ../kernel/kernel/cpt
depmod -a
/etc/init.d/vz stop
/etc/init.d/vz start

Montag, 19. Mai 2008

aufs with openvz and ubuntu

openvz on ubuntu currently only works with linux-image-2.6.24-17-openvz and linux-ubuntu-modules-2.6.24-17-openvz available through "deb http://ppa.launchpad.net/compbrain/ubuntu hardy main".

Thes packages don't contain the aufs module, so it has to be compiled seperately:
apt-get install aufs-source
cd /usr/src
tar xjf aufs.tar.bz2
cd modules/aufs

Apply the following patch:
*** vfsub.h~    2008-02-05 04:44:50.000000000 +0100
--- vfsub.h 2008-05-19 01:45:01.000000000 +0200
***************
*** 33,38 ****
--- 33,39 ----
#include
#endif

+ #define CONFIG_SECURITY_APPARMOR
/* ---------------------------------------------------------------------- */

struct aufs_hin_ignore;


Then compile:
/usr/bin/make -C /usr/src/linux M=/usr/src/modules/aufs modules modules_install

NX under Ubuntu Hardy

After upgrading to Ubuntu Hardy, NX reported the following error: "Cannot find KDE environment."

Here's how to fix it: http://chem-bla-ics.blogspot.com/2007/08/nxclient-on-ubuntu-gutsy.html