Configuring PulseAudio with Jack Audio Connection Kit (DBus)

Configuring PulseAudio with Jack Audio Connection Kit running via DBus is pretty easy nowadays. Following procedure was tested on Gentoo Linux but it should probably apply to other Linux distributions too. Used versions of packages were media-sound/pulseaudio-2.1-r1 and media-sound/jack-audio-connection-kit-2.9999 (from pro-audio overlay).

First you should check the name of the sound card you want Jack to play sound via. Use command aplay -l to get the name of the sound card. Then run following command to set the card for Jack:

jack_control dps device hw:DX

Replace DX with the name of your sound card.

Second, we’ll make sure Jack will use Alsa for output. Following command will set Jack output to Alsa:

jack_control ds alsa

If this command fails, make sure you have Python 2.7 selected as the active Python version. jack_control does not work with Python 3.2 because new Python changed print from statement to function and Jack Python scripts are not updated yet.

Last step is to start Jack and optionally configure PulseAudio. Issue the following command:

pulseaudio -k && jack_control start && pacmd set-default-sink jack_out && pacmd set-default-source jack_in

This command line first kills PulseAudio, then it starts Jack and tells PulseAudio to use Jack by default both for input and output.

If you do not get sound from sound applications that play sound via PulseAudio, use pavucontrol to check that the sound output for given application is directed to Jack sink.

PostgreSQL Unix Socket vs TCP/IP Performance

I just finish a test that compares PostgreSQL speed using Unix socket and TCP/IP connection to localhost with SSL enabled. The test was performed on import on OpenStreetMap PBF file (around 17GB of binary data). The result is that loading the data via TCP/IP connection with SSL enabled was about 17% slower than loading data via Unix socket.

Unix socket:
Processing: Node(1542670k 261.2k/s) Way(146203k 26.07k/s) Relation(1518310 44.75/s)  parse time: 45446s

TCP/IP:
Processing: Node(1542670k 257.1k/s) Way(146203k 18.02k/s) Relation(1518310 38.92/s)  parse time: 53122s

Tags: ,

Configuring GNU Screen Status Bar

With default GNU Screen configuration in Gentoo (I have no experience with other Linux distributions) you get no visible user interface for the tool. To get a status bar that displays host name, list of screen windows with some usability information, system load and current date and time, you can put following line in file ~/.screenrc:

hardstatus alwayslastline '%{= G}[ %{G}%H %{g}][%= %{= w}%?%-Lw%?%{= R}%n*%f %t%?%{= R}(%u)%?%{= w}%+Lw%?%= %{= g}][ %{y}Load: %l %{g}][%{B}%Y-%m-%d %{W}%c:%s %{g}]'

You can find more information about status configuration in GNU Screen Manual.

Tags:

SSL in Apache with Intermediate Certificate

For configuration you need these files: domain.tld.key (your private key), domain.tld.crt (your public certificate) and intermediate.crt (intermediate certificate of your certificate authority).

The configuration is pretty easy. Just put these lines in your virtual server configuration:

...
SSLEngine On
SSLProtocol All
SSLCipherSuite HIGH:MEDIUM
SSLCertificateFile /path/to/domain.tld.crt
SSLCertificateKeyFile /path/to/domain.tld.key
SSLCertificateChainFile /path/to/intermediate.crt
<Files ~ "\.(phtml|php?)$">
        SSLOptions +StdEnvVars
</Files>
<IfModule mod_setenvif.c>
        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
</IfModule>
...

Now just restart apache daemon and you’re done 🙂

Tags:

SSL in Postfix with Intermediate Certificate

This article describes just how to install certificates with intermediate certificate in Postfix, it does not describe how to configure Postfix for SSL as that is pretty complex topic.

For configuration you need these files: domain.tld.key (your private key), domain.tld.crt (your public certificate) and intermediate.crt (intermediate certificate of your certificate authority).

The configuration is pretty easy (once you know the steps). First you need to create combined PEM file:

cat domain.tld.key domain.tld.crt intermediate.crt > domain.tld.pem

Next you need to change two variables in Postfix main.cf configuration file:

...
smtpd_tls_cert_file = /path/to/domain.tld.pem
smtpd_tls_key_file = /path/to/domain.tld.pem
...

Now just restart postfix daemon and you’re done 🙂

Tags:

SSL in Courier IMAP with Intermediate Certificate

For configuration you need these files: domain.tld.key (your private key), domain.tld.crt (your public certificate) and intermediate.crt (intermediate certificate of your certificate authority).

The configuration is pretty easy (once you know the steps). First you need to create combined PEM file:

cat domain.tld.key domain.tld.crt intermediate.crt > domain.tld.pem

Next you need to change TLS_CERTFILE variable in Courier IMAP pop3d-ssl and imapd-ssl configuration files:

...
TLS_CERTFILE=/path/to/domain.tld.pem
...

Now just restart courier-imapd-ssl and courier-pop3d-ssl daemons and you’re done 🙂

Tags:

Checking Free Disk Space on Linux

Long time ago, there was a utility on Gentoo that was able to check and report free disk space left in case the free disk space reached some treshold. Recently I tried to find the tool again but failed. Maybe it was diskfree which is hosted at sourceforge.net, but that application is not maintained anymore. In the end, I decided to write my own script that will report to me information about filesystems that have reached some usage treshold and need my attention. Here is the script:

#!/bin/bash

# Copyright 2010 Miroslav Å ulc
#
# You can always find the latest version at http://www.fordfrog.name/posts/checking-free-disk-space-on-linux/
#
# This script is licensed under GPLv3 or newer.

# Percentage of disk usage from which to issue alerts
ALERT_USAGE=90
# You can pass extra switches to 'df' command if you want. Here are those that might be useful:
# -h     = outputs the information about filesystem usage in human readable form
# -l     = performs check only on local filesystems (so ignores filesystems connected via network)
# --sync = performs sync operation which makes the output more up to date, mainly on SunOS systems
#          (for more information see 'df' man page)
DF_EXTRA_SWITCHES="-h -l"

LC_ALL="C" df -P $DF_EXTRA_SWITCHES | grep -vE "(^Filesystem|cdrom)" \
                | awk '{ print $1 " " $5 " " $2 " " $4 }' | while read output
do
        usage=`echo $output | awk '{ print $2 }' | cut -d'%' -f1`

        if [ $usage -ge $ALERT_USAGE ]; then
                part=`echo $output | awk '{ print $1 }'`
                total=`echo $output | awk '{ print $3 }'`
                left=`echo $output | awk '{ print $4 }'`
                echo "$part usage $usage% (left $left out of $total)"
        fi
done

The scripts needs df, grep, awk and cut utilities present on your system, but these are already installed on most of the Linux systems so you should not have to install them manually.

The script has two configuration variables. ALERT_USAGE specifies usage percentage that if reached on single filesystem, it will trigger output of alert about the filesystem usage. The other configuration variable is DF_EXTRA_SWITCHES which you can use to finetune the output, like to ignore mounted network filesystems, output information about disk usage in more readable form, sync disk information before getting information from disk etc. You can see man page of df for all the possible switches.

So, with the default configuration, if you run the script and none of your filesystems has 90%+ usage, no output will be displayed. But if some of your filesystems will use 90% or more of its space, it will appear in the output. Then the output will look like this:

/dev/mapper/vg-var usage 96% (left 1.1G out of 25G)

The output says that device /dev/mapper/vg-var (which is LVM filesystem in this case) has 96% disk usage and there is 1.1GB of data left out of total 25GB which is the filesystem size.

You sure do not want to run the script manually, so put it in your cron configuration so it will be triggered automatically:

0 * * * * root bash /path/to/the/script.sh

This line will trigger the script each hour. Set it up so that it meets your needs. Also, make sure you have correctly set up your email address for cron and that your mailing system works on the box. As the script produces output only if there are any filesystems with usage over the treshold, you will receive emails only in these cases.

Here you can download the script: diskcheck-0.1.zip.

Xfce, Keychain And Two ssh-agents

While trying to find out how to make NetBeans work with keychain, I noticed that after I start Xfce and then keychain is run from my .bashrc, I end up with two ssh-agents running instead of one. I did not find out why it works this way, only thing I found out is that SSH_AGENT_PID is empty when running .bashrc, and I was not willing to dig deeper to find the cause. Anyway, I made a small patch that makes Xfce work with keychain:

--- /etc/xdg/xfce4/xinitrc.orig	2010-07-17 18:43:00.025468585 +0200
+++ /etc/xdg/xfce4/xinitrc	2010-07-17 18:54:10.045657796 +0200
@@ -113,7 +113,11 @@
 sshagent=`which ssh-agent`
 kill_sshagent=0
 if test -z "$SSH_AGENT_PID" -a "$sshagent" -a "x$sshagent" != "xno"; then
-	eval `$sshagent -s`
+	if test ! -e $HOME/.keychain; then
+		mkdir $HOME/.keychain
+	fi
+	$sshagent -s | grep -v "echo Agent pid" > $HOME/.keychain/$HOSTNAME-sh
+	. $HOME/.keychain/$HOSTNAME-sh
 	kill_sshagent=1
 fi
 

The patch saves output of ssh-agent into file that keychain uses so keychain then reuses the current data and does not have to spawn new ssh-agent. just to make the info complete, this is what i have in my .bashrc:

keychain -q
. ~/.keychain/$HOSTNAME-sh
. ~/.keychain/$HOSTNAME-sh-gpg

bug report at xfce: bug 6558

Tags: , ,

Speeding Up emerge

When working on NetBeans ebuilds, it’s often about doing some modifications, then emerging the ebuild … and then finding another problem (it’s most often caused by “playing” with dependencies). What speads the emerge up significantly is using tmpfs for /var/tmp/portage, which is the directory where portage compiles application. Using part of your RAM for emerge is also generally useful for any emerge tasks as it makes it work faster. Here is how to use tmpfs for /var/tmp/portage:

mount -t tmpfs -o size=6G,mode=775,uid=portage,gid=portage tmpfs /var/tmp/portage/

Specify size that you want or can afford to share max from your RAM. After this, your emerge commands will be faster because instead of writing files to disk and reading from disk, most of the operations are performed in memory.

If you want to mount it permanently, you can put something like this below to your /etc/fstab file:

...
tmpfs /var/tmp/portage tmpfs size=6G,mode=775,uid=portage,gid=portage 1 2
...

This will automatically mount it on each system boot.

Tags: