Remove items from Ubuntu’s indicator applet

Ubuntu 10.04 (Lucid Lynx) features new panel applets called “indicator applets”. If you want to get rid of some of them, they can be removed by removing the corresponding package(s) using your favourite tool (Synaptic, aptitude, apt-get, …):

  • indicator-me provides the menu with your avatar and your availability status
  • indicator-messages provides the menu for email/Evolution, social networks/Gwibber etc.
  • indicator-session provides the menu with the shutdown/logout button (if uninstalled, this functionality will be provided by the “System” menu)
  • indicator-sound provides the sound/audio settings menu

For more information, have a look at the Launchpad page and the Ubuntu Wiki page for the indicator applets.

Automated MySQL backup for shared webhosting

What to do if you want to use mysqldump in a shared hosting environment without being able to access the shell (SSH…)? Use a Perl CGI script:

#!/usr/bin/perl -w

use strict;
use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/plain\nContent-disposition: attachment; filename=\"db_backup.sql\"\n\n";
print qx(mysqldump -uUSERNAME -pPASSWORD DATABASE 2>&1);

Replace USERNAME, PASSWORD and DATABASE with the configuration data for your database and drop the script into your cgi-bin directory. Don’t forget to make it executable (chmod +x) and apply some form of access restrictions! Here’s an Apache .htaccess file which serves well for this purpose: Continue reading “Automated MySQL backup for shared webhosting”

Dell Preboot Authentication: Deleting smartcard associations

Laptops from the new Dell Latitude E series come with an OEM version of Wave Embassy Trust Suite. This software can be used (amongst others) for configuring BIOS and hard disk “passwords” based on smartcard authentication.

This is a nice feature, but what if you try to turn this off again after trying it out? There is just no such option; once configured, the smartcard login can no longer be turned off properly. The FAQ tells us to unset some passwords which just does not work as described, at least when using a hard drive password: The laptop still requires the smartcard before booting.

I wrote to the Wave Systems support and got a valuable hint, which finally worked:

  1. Open a command line window (right click on the command prompt application and select “run as administrator” when you are running Windows Vista or 7)
  2. Change to the following directory (cd): C:\Program Files\Wave Systems Corp\Dell Preboot Manager
  3. Type the following line: PrebootEnrollmentUtil.exe x <SystemPassword>

In step 3, <SystemPassword> needs to be replaced by your system password.

This will delete all credentials in the Credential Vault. Who would have thought of a Windows application providing a command line mode mightier than the graphical counterpart? 😉

ionice: Controlling the Linux I/O scheduler

Linux is quite good at scheduling the CPU time of running programs: Even when a process is running which constantly uses up all processor power, it is still possible to use another (interactive) program nearly as fast as on an idle system. But if a process is doing heavy I/O operations (i.e. backup software), the response times of interactive programs can be heavily increased.

A possible solution for this problem is the command line tool ionice which can be used to control the I/O scheduler. For example, if a backup tool is to be run, running

ionice -c3 COMMAND

will execute COMMAND with the scheduling class “idle” (will only run when no other process needs I/O).

Have a look at the man page for more information.

Clean MySQL backup using mysqldump

If you need to configure a backup of a MySQL database server, you shouldn’t simply copy it’s database files from /var/lib/mysql since they might be inconsistent (due to simultaneous changes). mysqldump is a safe choice for this task. I wrote a simple script for Debian that uses the pre-configured “debian-sys-maint” account and compresses the output:


mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --all-databases --lock-all-tables --result-file=$BACKUP_FILENAME

Please take care that you need to create the output directory (/var/backups/mysql in the above example) first!

If you need more than one revision of the backup, you might want to use “date” to format the filename. Since I run a normal (rdiff-)backup of a big part of the server afterwards, I don’t need this.

java -jar ignores classpath — Workaround

When you want to run a Java class wich needs additional libraries, you usually run java -cp mylib.jar MyClass or you specify the environment variable $CLASSPATH before running the class.

When you have a JAR file you want to run, you usually do this by issuing java -jar myjarfile.jar

Maybe you’ll think: Hey, I want to run a JAR file with some additional library so I issue java -cp mylib.jar -jar myjarfile.jar ! Forget about it, it won’t work. Believe me. Look into the java man page (section “-jar”) if you don’t believe me. I wasted hours on sorting that out. Even setting the $CLASSPATH variable won’t work. Here’s the solution:

  1. Open the jar file with some ZIP program (JAR = renamed ZIP).
  2. Open META-INF/MANIFEST.MF in a text editor.
  3. Copy the path and name of the main class: If you see a line like “Main-Class: some.package.ClassName”, it’s the part after the colon.
  4. Run this on your command line instead of the command that doesn’t work: java -cp mylib.jar:myjarfile.jar some.package.ClassName

Now you shouldn’t get any more NoClassDefFoundErrors…

Concrete example: If you want to run Lecturnity Player under Linux, just download the .jar, install the Java Media Framework (I used the “Cross-platform Java” version) and run the following command:

java -cp /opt/JMF/lib/jmf.jar:player_30.jar imc.epresenter.player.Manager

This assumes that you put the Java Media Framework to /opt/JMF and you are in the directory where player_30.jar resides.

Strato V-Server/Virtuozzo: Memory usage

This blog runs on a virtual server offered by Strato. They use Virtuozzo for virtualization which has a drawback: If you use top, free or other tools to show the current memory usage, not only your “slice” of the machine but more (all?) of the memory is measured. This doesn’t help much if you try to find out how much of it your own processes use, which is important as you can use only a certain part of the machine’s memory.

I could not find a better way to circumvent this but to sum up the numbers of every single process, listed by ps. Here’s a little shell script that does the job:

echo -ne "Allocated virtual memory: "
ps auxh | sed 's/ \+/ /g' | cut -d' ' -f 5 | \
php -r '$c=0; while($line=fgets(STDIN)) $c+=intval($line); echo "$c";'
echo " kB"

echo -ne "Used physical memory: "
ps auxh | sed 's/ \+/ /g' | cut -d' ' -f 6 | \
php -r '$c=0; while($line=fgets(STDIN)) $c+=intval($line); echo "$c";'
echo " kB"

You need to have the command line version of PHP 5 installed to run this script. The corresponding Debian package is called php5-cli.

Caching using weak references

Some time ago I wrote a Java class that caches generated images so I don’t need to re-render them all the time (rendering SVG graphics takes some time…). There’s only one problem: As more and more different images are getting cached, the maximum heap space of the JVM will eventually get exhausted. Increasing this limit is not an option. This can be “fixed” by using a queue for the images: If it is full, the first image cached will get discarded so the memory usage will be limited. This can be improved by implementing a least recently used (LRU) caching strategy, which is exactly what I did.

This has the drawback that even if there is plenty of memory remaining, cached images are deleted if the queue is full and a new image is about to be added. Today, I learned about the java.lang.ref package and especially about it’s SoftReference class. Objects referenced by SoftReferences will be deleted by the garbage collector if the JVM runs out of memory, which should be the ideal way to implement a cache…

You can learn more about it at Wikipedia and IBM Developer Works.