debian snippets

Changing the default terminal emulator the Debian way.

Tagged default terminal, debian, ubuntu, x11, linux  Languages bash

Use this to change the terminal emulator that comes with the default installation of Debian (and Ubuntu).

sudo update-alternatives --config x-terminal-emulator

Choose your emulator from the list and hit enter.

How to change the default editor in Debian

Tagged default editor, debian, ubuntu, standard editor, oletuseditori  Languages bash

This command changes the default editor system wide. It should work in all Debian derivatives.

sudo update-alternatives --config editor

Quick step by step on creating a xen environment in Debian Etch

Tagged xen, debian, etch, stable, virtualisointi, virtualisering  Languages bash

Jumpstart with Xen out-of-the-box in Debian Etch stable.

sudo apt-get install xen-tools xen-hypervisor linux-image-xen-amd64 bridge-utils iproute sysfsutils
# [reboot into xen kernel now]
sudo xen-create-image --hostname=db2.aktagon.com \
--size=10Gb --swap=256Mb --ip=10.0.0.51 \
--netmask=255.255.255.0 --gateway=10.0.0.2 \
--force --dir=/work/vserver --memory=512Mb \
--arch=i386 --kernel=/boot/vmlinuz-2.6.18-5-xen-amd64 \
--debootstrap --dist=etch \
--mirror=http://ftp.funet.fi/pub/linux/mirrors/debian/ \
--passwd
sudo xm create /etc/xen/db1.aktagon.com.cfg

Creating a local Debian mirror for your Xen servers

Tagged xen, debian, etch, local mirror, amd64, anonftpsync, nginx  Languages bash

Once you've bought a dual or quad Xeon and started to experiment with virtualization you will soon want to create your local mirror to make installs lightning fast. This is a step-by-step how i did it.

First create the Xen that will be our mirror server. The size requirements can be found here: Debian mirror sizes The combined size of amd64 architecture and architecture independent files was 39Gb on 1.9.2007. So I made the image 50Gb big. Remember to change this mirror to a location near you.

xen-create-image --hostname=mirrors.aktagon.com \
--size=50Gb --swap=256Mb --ip=10.0.0.44 \
--netmask=255.255.255.0 --gateway=10.0.0.2 \
--force --dir=/work/vserver --memory=256Mb \
--arch=amd64 \
--kernel=/boot/vmlinuz-2.6.18-5-xen-amd64 \
--debootstrap --dist=etch \
--mirror= http://ftp.fi.debian.org/debian/\
--passwd

Then ssh into your new Xen as root.

ssh -l root mirrors.aktagon.com

Make base configurations for a fresh Xen.

apt-get update && apt-get install locales console-data && dpkg-reconfigure locales

Then get the mirror synchronization script from Debian.

wget "http://www.debian.org/mirror/anonftpsync"
chmod a+x anonftpsync

Then install dependencies for anonftpsync script. Otherwise the script will fail with a -bash: lockfile: command not found error.

apt-get install procmail

Install nginx.

apt-get install nginx

Configure anonftpsync with your favorite editor and change the lines below. These settings will setup a mirror only for amd64 files. You could remove i386 from the excluded architectures, but then a 50Gb image won't fit all the files.

TO=/var/www/debian
RSYNC_HOST=ftp.fi.debian.org
RSYNC_DIR=debian
LOGDIR=/var/log/mirroring
ARCH_EXCLUDE="alpha arm hppa hurd-i386 i386 ia64 m68k mipsel mips powerpc s390 sh sparc source"

Make the log directory.

mkdir -p /var/log/mirroring

Configure nginx by modifying /etc/nginx/nginx.conf with your favorite editor. Just add the autoindex line into server { location / { context

# abbreviated start of file for clarity...
    server {
        listen       80;
        server_name  localhost;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
            root   /var/www;
            # add the line below to allow directory listing
            autoindex  on;
            index  index.html index.htm;
        }
   # abbreviated end of file for clarity...

Do the synchronizing. And wait... for a long while. On a 8/1Mbit cable the first synchronize took roughly 20 hours.

./anonftpsync

Now modify your /etc/apt/sources.list on existing Xen images to use your local mirror. And remember to create new Xen images using your new mirror :) In the above case the URL is http://mirrors.aktagon.com/debian

NB: there is no public mirrors.aktagon.com available... sorry.

Fix for "Failed to find an unused loop device" when using xen

Tagged xen, debian, xen source, loop devices  Languages bash

If you use Xen and get an error "Failed to find an unused loop device" when you try to create a guest then you are probably using disk images and have run out of loop devices. Each guest uses at least two loop devices. Modify (or create) a file called /etc/modprobe.d/local-loop and add this line:

options loop max_loop=64

Use a number suitable for your needs. With 64 loop devices you can run up to 32 guests on your host, assuming you aren't using loop devices for any other purposes.

Custom kernel for Debian Etch

Tagged linux, debian, custom kernel, kustomoitu kerneli, kustomiserad kernel, deb  Languages bash

Sometimes you just need a kernel that is newer than the package manager has to offer. For me it was the bug fixes for the driver of the sound card in x61s. Here's how to do it "the debian way".

wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.23.1.tar.bz2
tar xjvf linux-2.6.23.1.tar.bz2 -C /usr/src
rm /usr/src/linux && ln -s /usr/src/linux-2.6.23.1 /usr/src/linux
cd /usr/src/linux
zcat /proc/config.gz > .config
make xconfig

Now turn on and configure the new features you are looking for in the new kernel, save the configuration and finally quit.

make-kpkg clean
fakeroot make-kpkg --initrd --append-to-version=-custom-13.10.2007 kernel_image kernel_headers
cd ..
sudo dpkg -i linux-image-2.6.23.1-custom-13.10.2007_2.6.23.1-custom-13.10.2007-10.00.Custom_amd64.deb
sudo dpkg -i linux-headers-2.6.23.1-custom-13.10.2007_2.6.23.1-custom-13.10.2007-10.00.Custom_amd64.deb

The --append-to-version parameter appends the given value into the kernel signature, so that it is easily recognized. If you compile a kernel with the exactly same name as a previous kernel you have then you must move away the directory /lib/modules/your-kernel-name-here.

Check if a file or directory exists with bash

Tagged nginx, daemon, bash, linux, debian  Languages bash

This script tests if nginx exists and is executable. The script prints a warning and exits, if nginx doesn't exists or isn't executable:

DAEMON=/usr/local/sbin/nbinx
if [ ! -x $DAEMON ]
then
   echo "Couldn't find $DAEMON. Please set path to DAEMON."
   exit 0
fi

See man test for more information on how to use the test command.

Installing nginx on Debian

Tagged nginx, install, debian  Languages bash

DRAFT...

Find latest version of nginx

http://sysoev.ru/en/ http://wiki.codemongers.com/NginxInstallOptions

Install a compiler otherwise: ./configure: error: C compiler gcc is not found

The command:

sudo apt-get install build-essential

Install pre-requisites otherwise you'll get:

Configuration summary + threads are not used + PCRE library is not found + OpenSSL library is not found + md5 library is not used + sha1 library is not used + zlib library is not found

The command:

sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev

Much better:

Configuration summary + threads are not used + using system PCRE library + using system OpenSSL library + md5 library is not used + sha1 library is not used + using system zlib library

Compile and install nginx

$ ./configure \
        --sbin-path=/usr/local/sbin \
        --conf-path=/etc/nginx/nginx.conf \
        --pid-path=/var/run/nginx.pid \
        --error-log-path=/var/log/nginx/error.log \
        --http-log-path=/var/log/nginx/access.log \
        --with-http_ssl_module \
        --http-client-body-temp-path=/tmp/nginx_client \
        --http-proxy-temp-path=/tmp/nginx_proxy \
        --http-fastcgi-temp-path=/tmp/nginx_fastcgi
$ make
$ sudo make install

Run the install script

cd /usr/local/src

wget http://sysoev.ru/nginx/nginx-0.5.35.tar.gz

tar zxvf nginx-0.5.35

cd nginx-0.5.35

Create an nginx user and group

$ useradd -g www-data -d /var/www nginx

Create the web server directory

mkdir /var/www
chown root.www-data /var/www
chmod ug=rwx,o= /var/www

Test configuration

nginx -t
2008/03/09 20:51:05 [info] 5034#0: the configuration file /etc/nginx/nginx.conf syntax is ok
2008/03/09 20:51:05 [info] 5034#0: the configuration file /etc/nginx/nginx.conf was tested successfully

Start nginx

nginx

Compiling Ruby with OpenSSL, Zlib and Readline support on Debian

Tagged ruby, readline, ssl, zlib, debian  Languages ruby

DRAFT... From http://blog.fiveruns.com/2008/3/3/compiling-ruby-rubygems-and-rails-on-ubuntu

Install pre-requisites

apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev

Download and install

cd /usr/local/src

wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz

tar zxvf ruby-1.8.6.tar.gz

cd ruby-1.8.6.tar.gz

./configure --prefix=/usr/local --with-openssl-dir=/usr --with-readline-dir=/usr --with-zlib-dir=/usr

make
make install

ruby -ropenssl -rzlib -rreadline -e "puts :success"

Installing Rails, mongrel and mongrel_cluster on Debian

Tagged rails, ruby, debian, install, sqlite3, mongrel, mongrel_cluster  Languages bash

DRAFT...

Install RubyGems

http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz

tar zxvf rubygems-1.0.1.tgz

cd rubygems-1.0.1

ruby setup.rb

Install Rails

gem install rails

Install sqlite3 (optional)

apt-get install sqlite3 libsqlite3-dev
gem install sqlite3-ruby

Install mongrel and mongrel_cluster

$ gem install mongrel mongrel_cluster

$ mongrel_rails cluster::configure -e production \
  -p 8000 \
  -a 127.0.0.1 \
  -N 3 \
  -c /var/www/xyz/current


$ mongrel_rails cluster::start


$ useradd -g www-data -d /var/www mongrel

Surviving reboots

sudo mkdir /etc/mongrel_cluster

sudo ln -s /var/www/xyz/config/mongrel_cluster.yml /etc/mongrel_cluster/xyz.yml

sudo cp /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d/

sudo chmod +x /etc/init.d/mongrel_cluster

sudo /usr/sbin/update-rc.d -f mongrel_cluster defaults

mongrel_cluster_ctl status

Stale pids

If your mongrels crash or if you kill them, mongrel_cluster won't start your mongrels because mongrel_cluster believes the processes are still running, instead mongrel_cluster complains and does nothing:

** !!! PID file tmp/pids/mongrel.8000.pid already exists.  Mongrel could be running already.  Check your log/mongrel.8000.log for errors.
** !!! Exiting with error.  You must stop mongrel and clear the .pid before I'll attempt a start.

To fix this simply add the --clean switch to the /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster startup script:

mongrel_cluster_ctl start -c $CONF_DIR --clean