<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tech notes &#187; linux</title>
	<atom:link href="http://bsd.dischaos.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://bsd.dischaos.com</link>
	<description>just some random notes on BSDs, linux and web development</description>
	<lastBuildDate>Fri, 07 May 2010 10:18:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>how to create a new kvm image for eucalyptus UEC</title>
		<link>http://bsd.dischaos.com/2009/11/15/how-to-create-a-new-kvm-image-for-eucalyptus-uec/</link>
		<comments>http://bsd.dischaos.com/2009/11/15/how-to-create-a-new-kvm-image-for-eucalyptus-uec/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 13:29:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[eucalyptus]]></category>
		<category><![CDATA[kvm]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=150</guid>
		<description><![CDATA[Eucalyptus is a new cloud management software available with the latest version of ubuntu (karmic koala). It&#8217;s compatible with Amazon&#8217;s EC2 (in terms of images and CLI tools) and it&#8217;s opensource so anyone can build a EC2 like service. That is&#8230; when it becomes a little bit more stable&#8230;  
Eucalyptus comes with 2 images [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.eucalpytus.com/products/ubuntu_enterprise_cloud">Eucalyptus</a> is a new cloud management software available with the latest version of ubuntu (karmic koala). It&#8217;s compatible with Amazon&#8217;s EC2 (in terms of images and CLI tools) and it&#8217;s opensource so anyone can build a EC2 like service. That is&#8230; when it becomes a little bit more stable&#8230; <img src='http://bsd.dischaos.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Eucalyptus comes with 2 images you can use to create vm instances on it &#8211; a 64 bit and 32 bit versions of ubuntu. These images are very well prepared and well integrated with EC2/Eucalyptus. But what if you want to run a different linux distro in your Eucalyptus based lab? Here&#8217;s a quick howto on creating a simple CentOS image on a ubuntu box with kvm installed:</p>
<p><strong>Creating a new disk Image</strong></p>
<p>This will be the main hdd in your virtual image, so make sure to give it as much space as you think you&#8217;ll need. Since we&#8217;re building a kvm image, we can use a qcow2 format for disk images. Qcow2 is an expandable image format, so it&#8217;ll only take as much storage space as it&#8217;s actually used withing the image.  </p>
<div class="codesnip-container" >kvm-img create -f qcow2 image.img 20G</div>
<p><strong>OS Installation</strong></p>
<p>Fetch an .iso of the distribution you want installed in the image.</p>
<div class="codesnip-container" >wget http://www.mirrorservice.org/sites/mirror.centos.org/5.4/isos/x86_64/CentOS-5.4-x86_64-netinstall.iso</div>
<p>and start the installation process:</p>
<div class="codesnip-container" >sudo kvm -m 256 -cdrom Centos-5.4-x86_64-netinstall.iso -drive file=image.img,if=scsi,index=0 -boot d -curses -net<br />
nic,vlan=0,model=e1000,macaddr=00:16:3e:de:ad:01 -net tap</div>
<p>if your installation process requires more than 256MB of RAM change the -m option, and if you need more processors available, you can use the &#8216;-c&#8217; option. </p>
<p>The command above will boot a new kvm instance, with the disk image you&#8217;ve created as the primary hdd and the iso as the first bootable device. Also the &#8216;-curses&#8217; option will make the kvm display all console output to your ssh session. (I&#8217;m assuming here, you&#8217;re creating this image over a remote connection, if you&#8217;re not you can probably skip the -curses option and kvm should use sdl drivers instead)</p>
<p>After finishing the installation you can test the new virtual machine by running:</p>
<div class="codesnip-container" >sudo kvm -m 256 -drive file=image.img,if=scsi,index=0,boot=on -boot c -curses -net nic,vlan=0,model=e1000,macaddr=00:16:e3:de:ad:01 -net tap</div>
<p>At this point you can add all the packages you want to have installed, all users, any settings that need to be present in your new UEC instances.</p>
<p>Now it&#8217;s also a good time to copy the kernel and the initrd image from your new vm image some place outside. They will be used later on to create and upload an complete virtual image to your UEC.</p>
<p>Before you shut your new shiny image down there&#8217;s one more step to be done:</p>
<p><b>Integration with UEC</b></p>
<p>Your new image needs to know what IP it has when started in UEC and also, it needs to know the public bit of the ssh key allowed to access it. The way it&#8217;s done in UEC (and EC2?) is via a restful interface provided by the cloud. The interface is available under this URL: http://169.254.169.254/latest/meta-data. You can use wget to see what information is provided:</p>
<div class="codesnip-container" >wget -q -O &#8211; http://169.254.169.254/latest/meta-data/</div>
<p>What&#8217;s interesting for us here is the public key data which is available here:</p>
<p>http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key</p>
<p>As we need to automate the whole process a bit, let&#8217;s put it all into an init.d script:</p>
<div class="codesnip-container" >#!/bin/bash<br />
#<br />
. /etc/rc.d/init.d/functions</p>
<p>RETVAL=0</p>
<p>start()<br />
{<br />
        fetch_ssh_key<br />
        regenerate_ssh_keys<br />
}</p>
<p>stop()<br />
{<br />
        echo &#8220;nothing to stop&#8230;&#8221;<br />
}</p>
<p>regenerate_ssh_keys()<br />
{<br />
        rm -f /etc/ssh/ssh_host_key /etc/ssh/ssh_host_rsa_key /etc/ssh_ssh_host_dsa_key<br />
        [ -f /etc/ssh/ssh_host_key ] || (ssh-keygen -f /etc/ssh/ssh_host_key -t rsa1 -C &#8216;host&#8217; -N &#8221; | logger -s -t &#8220;ec2&#8243;)<br />
        [ -f /etc/ssh/ssh_host_rsa_key ] || (ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa  -C &#8216;host&#8217; -N &#8221; | logger -s -t &#8220;ec2&#8243;)<br />
        [ -f /etc/ssh/ssh_host_dsa_key ] || (ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa  -C &#8216;host&#8217; -N &#8221; | logger -s -t &#8220;ec2&#8243;)</p>
<p>        echo &#8220;&#8212;&#8211;BEGIN SSH HOST KEY FINGERPRINTS&#8212;&#8211;&#8221; |logger -s -t &#8220;ec2&#8243;<br />
        ssh-keygen -l -f /etc/ssh/ssh_host_key.pub |logger -s -t &#8220;ec2&#8243;<br />
        ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub |logger -s -t &#8220;ec2&#8243;<br />
        ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub |logger -s -t &#8220;ec2&#8243;<br />
        echo &#8220;&#8212;&#8211;END SSH HOST KEY FINGERPRINTS&#8212;&#8211;&#8221;   |logger -s -t &#8220;ec2&#8243;<br />
}</p>
<p>fetch_ssh_key()<br />
{<br />
        if [ ! -d /root/.ssh ] ; then<br />
                mkdir -p /root/.ssh<br />
                chmod 700 /root/.ssh<br />
        fi</p>
<p>        curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/ssh-key<br />
        if [ $? -eq 0 ] ; then<br />
                cat /tmp/ssh-key >> /root/.ssh/authorized_keys<br />
                chmod 600 /root/.ssh/authorized_keys<br />
                rm /tmp/ssh-key<br />
                # disable password logging<br />
                sed -i.bkp &#8217;s/^PasswordAuthentication yes/PasswordAuthentication no/&#8217; /etc/ssh/sshd_config<br />
        fi<br />
}</p>
<p>case &#8220;$1&#8243; in<br />
        start)<br />
                start<br />
                ;;<br />
        stop)<br />
                stop<br />
                ;;<br />
        restart)<br />
                stop<br />
                start<br />
                ;;<br />
        condrestart)<br />
                echo &#8220;not implemented&#8221;<br />
                ;;<br />
        status)<br />
                echo &#8220;not implemented&#8221;<br />
                ;;</p>
<p>        *)<br />
                echo $&#8221;Usage: $0 {start|stop|restart|reload|condrestart|status}&#8221;<br />
                RETVAL=1<br />
esac</p>
<p>exit $RETVAL</p></div>
<p>Enable this script in your boot process. The script will not only download and install this key on root account. It also regenerates your instance&#8217; keys and displays their fingerprints on the console (so you can see them by doing euca-get-console-output i-instance_number)</p>
<p>This script is just a simple example, you can also take the python uec backend available in ubuntu and use it to do the same thing i a slightly better and cleaner way.</p>
<p><b>Uploading to UEC</b></p>
<p>The last step is uploading your image to UEC:</p>
<p>bundle and upload the previously copied kernel first:</p>
<div class="codesnip-container" >euca-bundle-image -i kvm-kernel/vmlinuz-2.6.28-11-generic &#8211;kernel true<br />
euca-upload-bundle -k mybucket -m /tmp/vmlinuz-2.6.28-11-generic.manifest.xml<br />
euca-register mybucket/vmlinuz-2.6.28-11-generic.manifest.xml</div>
<p>save the k-* output produced by the last command above and proceed with initrd:</p>
<div class="codesnip-container" >euca-bundle-image -i kvm-kernel/initrd.img-2.6.28-11-generic<br />
euca-upload-bundle -b mybucket  /tmp/initrd.img-2.6.28-11-generic.manifest.xml<br />
euca-register mybucket/initrd.img-2.6.28-11-generic.manifest.xml</div>
<p>as above, save the i-* output and upload the image now:</p>
<div class="codesnip-container" >euca-bundle-image -i image.img &#8211;kernel $PREVIOUSLY_SAVED_KERNELID &#8211;ramdisk $PREVIOUSLY_SAVED_IMAGERD<br />
euca-upload-bundle -b mybucket -m /tmp/image.img.manifest.xml<br />
euca-register mybucket/image.img.manifest.xml</div>
<p>All done, your new image should be visible after euca-describe-images -a.</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/11/15/how-to-create-a-new-kvm-image-for-eucalyptus-uec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RPM build environment on CentOS</title>
		<link>http://bsd.dischaos.com/2009/09/02/rpm-build-environment-on-centos/</link>
		<comments>http://bsd.dischaos.com/2009/09/02/rpm-build-environment-on-centos/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 21:42:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[redhat]]></category>
		<category><![CDATA[rpm]]></category>
		<category><![CDATA[rpmbuild]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=106</guid>
		<description><![CDATA[Just a quick note on how to build RPMs
 setting up build environment 
RPMs should be built from a &#8221;&#8217;standard user&#8221;&#8217; account, &#8221;&#8217;not root&#8221;&#8217;. This saves a lot of trouble when something goes wrong during package preparation/installation and keeps the build environment clean.
Here&#8217;s how to setup build environment in your home directory:
mkdir -p ~/build/{BUILD,RPMS,S{OURCES,PECS,RPMS}}
These directories [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note on how to build RPMs</p>
<h3> setting up build environment </h3>
<p>RPMs should be built from a &#8221;&#8217;standard user&#8221;&#8217; account, &#8221;&#8217;not root&#8221;&#8217;. This saves a lot of trouble when something goes wrong during package preparation/installation and keeps the build environment clean.</p>
<p>Here&#8217;s how to setup build environment in your home directory:</p>
<div class="codesnip-container" >mkdir -p ~/build/{BUILD,RPMS,S{OURCES,PECS,RPMS}}</div>
<p>These directories are for:</p>
<p>BUILD &#8211; that&#8217;s the place where your source package will get untargzipped, patched and compiled<br />
RPMS &#8211; will contain your RPMS when done<br />
SOURCES &#8211; upload all source .tar.gz&#8217;s and your patches here<br />
SPECS &#8211; .spec files with instructions on how to build your packages<br />
SRPMS &#8211; source RPMS, a bit more about them below</p>
<p>Now you need to tell rpm-build where to look for these directories:</p>
<div class="codesnip-container" >echo &#8220;%_topdir $HOME/build&#8221; &gt; ~/.rpmmacros</div>
<p>and finally you need to install some software:</p>
<div class="codesnip-container" >sudo yum install rpm-build redhat-rpm-config mock</div>
<p>(Keep in mind, that the list above is not complete as it doesn&#8217;t contain any compilers, libtools, automakes etc, that might be required to actually build your source package.)</p>
<p>and create a &#8217;special&#8217; user for the mock package (this is to allow fakeroot builds):</p>
<div class="codesnip-container" >sudo useradd -M -d / -s /sbin/nologin mockbuild</div>
<h3> building from SRPMs (easy!)  </h3>
<p>SRPMS (source RPMS) contain the .spec file and all necessary source files and patches needed to build a binary package. This can be usefull if there&#8217;s no binary package available for your platform but there&#8217;s a source one available for a similar one (redhat.srpms to build packages for centos).</p>
<p>One way to build a binary package from a source one is to:</p>
<div class="codesnip-container" >rpmbuild &#8211;rebuild package-1.0.src.rpm</div>
<p>This will do all the magic and (hopefully) put a binary package in build/RPMS/$arch/</p>
<p>Other way is to install (as user, it will put all sources and patches to build/SOURCES and the spec file to build/SPECS) the source package first and then use rpmbuild:</p>
<div class="codesnip-container" >rpm -i package-1.0.src.rpm<br />
rpmbuild -ba ~/build/SPECS/package-1.0.spec</div>
<p>According to the documentation you can build RPMs from .tar.gzs if they contain a .spec file. You would do it by using -ta option for rpmbuild instead of -ba.</p>
<h3>building from source</h3>
<p>This means creating your own package from scratch. There&#8217;s how to do it:</p>
<p>First see if the package builds from source without any tweaking. Check if it (or the resulting package you want built) requires any special options to be passed to either ./configure or make. Also at this point think of any modifications to the original source code you&#8217;d like to have (changes in default config files, additional modules compiled in or removed from the package etc etc).</p>
<p>If you do need some changes done, this is a good time to make all the patches.<br />
Make a clean and untouched copy of the untargzipped package:</p>
<div class="codesnip-container" >tar xvfz moosoft-1.0.tar.gz<br />
cp -Rvp moosoft-1.0 moosoft-1.0.orig</div>
<p>now make all the required changes in the moosoft-1.0 directory and generate patch or a set of patches:</p>
<div class="codesnip-container" >diff -uNr moosoft-1.0.orig moosoft-1.0 &gt; moosoft-1.0.bigpatch.patch<br />
# or:<br />
diff -uNr moosoft-1.0.orig/etc/moo.conf moosoft-1.0/etc/moo.conf &gt;<br />
moosoft-1.0.config.patch<br />
diff -uNr moosoft-1.0.orig/doc/ moosoft-1.0/doc &gt;<br />
moosoft-1.0.documentation.patch<br />
# etc&#8230; to generate multiple patches</div>
<p>Copy these patches and the original moosoft-1.0.tar.gz file to ~/build/SOURCES.</p>
<p>The last thing to do is to prepare a recipe for rpmbuild how to build your package. Create moosoft-1.0.spec file in ~/build/SPECS:</p>
<pre>#                  _____________________________
#         (__)    /                             \
#         (oo)   ( This is an example .spec file )
#  /-------\/  --'\_____________________________/
# / |     ||
#*  ||----||
#   ^^    ^^
####
# package preamble
# one line description of the package
Summary: Very important Unix tool
Name: moo
Version: 1.0
# this marks the internal release version: moo-1.0-1.666.x86_64.rpm
Release: 1.666
License: BSD
# group you want your package in, mostly for GUI package browsers
# some example groups used by vendors:
# http://www.rpmfind.net/linux/RPM/Groups.html
Group: Networking/Daemons
# your name for example
Packager:
#
Source: http://full.url.to.the/package/%{name}-%{version}.tar.gz
Source1: moo.init
# list all your patches here:
Patch0: moo-1.0.etc.patch
Patch1: moo-1.0.documentation.patch
# list all packages required to build this package
BuildRequires: openssl-devel
Provides:
# list all packages that conflict with this one:
Conflicts: bse
BuildRoot: %{_tmppath}/%{name}-%{version}-build

####
# full length description
%description

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eros elit,
pretium eu vestibulum vel, blandit vel nisl. Fusce mattis volutpat
pellentesque. Etiam sit amet magna eget dui faucibus rutrum. Aliquam a ligula
erat. Proin metus tortor, sollicitudin et accumsan quis, hendrerit non leo.
Curabitur egestas neque sed nulla vulputate vel bibendum sapien tristique.
Vivamus malesuada, magna et semper iaculis, magna lorem adipiscing erat, vel
euismod enim nulla vel tortor. Vestibulum accumsan placerat sagittis. Sed
commodo pretium lectus et dignissim. Ut nec orci tellus.

#####
# this prepares a fresh build directory in ~/build/BUILD, useful macros here
# are:
# %setup - cleans any previous builds and untargzips the source
# %patch - applies patches
# any other commands here are executed as standard sh commands
%prep

%setup
%patch
%patch1

./configure --enable-something --with-something-else

#####
# this tells rpmbuild how to build your package, rpmbuild runs it as a sh
# script
%build
make

#####
# all the steps necessary to install your package into $RPM_BUILD_ROOT
# first step is to clear $RPM_BUILD_ROOT
%install
[ "$RPM_BUILD_ROOT" != "/" ] &amp;&amp; rm -rf $RPM_BUILD_ROOT
#install all files under RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

# now you can remove uneeded stuff
rm -f $RPM_BUILD_ROOT{_prefix}/sbin/rc.moo

#####
# NOTE: this section is optional
# commands run just before the package is installed
%pre
/usr/sbin/useradd -c "moo user" -r -s /bin/false -u 666 -d / moo 2&gt; /dev/null
|| :

#####
# NOTE: this section is optional
# commands run before uninstalling the software
%preun
/sbin/service moo stop &gt; /dev/null 2&gt;&amp;1
/sbin/chkconfig --del moo

#####
# NOTE: this section is optional
# commands run after installing the package
%post
/sbin/chkconfig -add moo
touch /var/log/moo

#####
# NOTE: this section is optional
# commands run after unistalling the package
%postun
/sbin/service moo stop
/usr/sbin/userdel moo

#####
# list all the files that are part of the package. If a file is not in the
# list rpmbuild won't put it in the package
# see below on how to automate the process of creating this list.
# some useful macros here:
# %doc filename - installs filename into /usr/share/doc/moo-1.0/
# %doc /path/to/filename - installs filename into /path/to/filename and marks
# it as being documentation
# %config /etc/config_file - similar for configuration files
# %attr(mode, user, group) file - lets you specify file attributes applied
# during installation, use - if you want to use defaults
%files
/usr/bin/moo
/usr/sbin/moomoo
# this will package the dir and all directories inside it
/example/of/a/dir
# this will package only the 'dir' directory
%dir /example/of/a/dir

#####
# document changes between package releases
%changelog
* Wed Jul 8 2009 Your Name Here
- another version of the package

* Mon Jul 6 2009 Your Name Here
- initial version of the package</pre>
<p>To get the list of all installed files do</p>
<div class="codesnip-container" >rpmbuild -bi ~/build/SPECS/moo-1.0.spec</div>
<p>this will go through prep, build and install steps of the spec file and install all files under $RPM_BUILD_ROOT, which in this case should be /var/tmp/moo-1.0-build.</p>
<div class="codesnip-container" >ls -R1 /var/tmp/moo-1.0-build</div>
<p>and use the output to populate the %files section</p>
<p>Now the package can be build by running:</p>
<div class="codesnip-container" >rpmbuild -ba ~/build/SPECS/moo-1.0.spec</div>
<h3> building with modules </h3>
<p>Sometimes it&#8217;s helpful to split one package into multiple modules. Here&#8217;s an example .spec file for a library, it will produce two packages: libmoo (with the shared objects provided by the library) and libmoo-devel (with all headers and static libraries)</p>
<pre>#                  _____________________________
#         (__)    /                             \
#         (oo)   ( This is an example .spec file )
#  /-------\/  --'\_____________________________/
# / |     ||
#*  ||----||
#   ^^    ^^
####
# package preamble
# one line description of the package
Summary: An Example library
Name: libmoo
Version: 1.0
# this marks the internal release version: libmoo-1.0-1.666.x86_64.rpm
Release: 1.666
License: BSD
# group you want your package in, mostly for GUI package browsers
# some example groups used by vendors:
# http://www.rpmfind.net/linux/RPM/Groups.html
Group: Development/Libraries
# your name for example
Packager:
#
Source: http://full.url.to.the/package/%{name}-%{version}.tar.gz
# list all your patches here:
Patch0: moo-1.0.etc.patch
Patch1: moo-1.0.documentation.patch
# list all packages required to build this package
BuildRequires: openssl-devel
Provides:
# list all packages that conflict with this one:
Conflicts: bse
BuildRoot: %{_tmppath}/%{name}-%{version}-build

####
# changes in the preamble for libmoo-devel package
%package devel
Summary: libmoo development files and headers
Group: Development/Libraries
# -devel requires the main package
Requires: %name = %version

####
# full length description
%description

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eros elit,
pretium eu vestibulum vel, blandit vel nisl. Fusce mattis volutpat
pellentesque. Etiam sit amet magna eget dui faucibus rutrum. Aliquam a ligula
erat. Proin metus tortor, sollicitudin et accumsan quis, hendrerit non leo.
Curabitur egestas neque sed nulla vulputate vel bibendum sapien tristique.
Vivamus malesuada, magna et semper iaculis, magna lorem adipiscing erat, vel
euismod enim nulla vel tortor. Vestibulum accumsan placerat sagittis. Sed
commodo pretium lectus et dignissim. Ut nec orci tellus.

####
# full description of the -devel package
%description devel

static libraries and headers for libmoo 

#####
# this prepares a fresh build directory in ~/build/BUILD, useful macros here
# are:
# %setup - cleans any previous builds and untargzips the source
# %patch - applies patches
# any other commands here are executed as standard sh commands
%prep

%setup
%patch
%patch1

./configure --enable-something --with-something-else

#####
# this tells rpmbuild how to build your package, rpmbuild runs it as a sh
# script
%build
make

#####
# all the steps necessary to install your package into $RPM_BUILD_ROOT
# first step is to clear $RPM_BUILD_ROOT
%install
[ "$RPM_BUILD_ROOT" != "/" ] &amp;&amp; rm -rf $RPM_BUILD_ROOT
#install all files under RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

# now you can remove uneeded stuff
rm -f $RPM_BUILD_ROOT{_prefix}/sbin/rc.moo

#####
# NOTE: this section is optional
# commands run just before the package is installed
%pre
/usr/sbin/useradd -c "moo user" -r -s /bin/false -u 666 -d / moo 2&gt; /dev/null
|| :

#####
# NOTE: this section is optional
# commands run before uninstalling the software
%preun
/sbin/service moo stop &gt; /dev/null 2&gt;&amp;1
/sbin/chkconfig --del moo

#####
# NOTE: this section is optional
# commands run after installing the package
%post
/sbin/ldconfi

#####
# NOTE: this section is optional
# commands run after unistalling the package
%postun
/sbin/ldconfig

#####
# list all the files that are part of the package. If a file is not in the
# list rpmbuild won't put it in the package
# see below on how to automate the process of creating this list.
# some useful macros here:
# %doc filename - installs filename into /usr/share/doc/moo-1.0/
# %doc /path/to/filename - installs filename into /path/to/filename and marks
# it as being documentation
# %config /etc/config_file - similar for configuration files
# %attr(mode, user, group) file - lets you specify file attributes applied
# during installation, use - if you want to use defaults
%files
%defattr(-,root,root,0755)
%attr(755,root,root) %_prefix/lib/lib*.so.*
%doc INSTALL ChangeLog

#####
# separate list of files for the -devel modules
%files devel
%defattr(-,root,root,0755)
%attr(755,root,root) %_prefix/lib/lib*.so
%attr(644,root,root) %_prefix/lib/*.a
#exclude *.la files
%exclude %_prefix/lib/*.la

#####
# document changes between package releases
%changelog
* Wed Jul 8 2009 Your Name
- another version of the package

* Mon Jul 6 2009 Your Name
- initial version of the package</pre>
<p>building the package with rpmbuild -ba libmoo-1.0.spec will produce two files:</p>
<p>libmoo-1.0-1.666.arch.rpm and libmoo-devel-1.0-1.666.arch.rpm</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/09/02/rpm-build-environment-on-centos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nagios plugin template in python</title>
		<link>http://bsd.dischaos.com/2009/04/29/nagios-plugin-template-in-python/</link>
		<comments>http://bsd.dischaos.com/2009/04/29/nagios-plugin-template-in-python/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 08:49:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[bsd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=95</guid>
		<description><![CDATA[A template for nagios plugins I use:

#!/usr/bin/env python
import sys, getopt
nagios_codes = &#123;&#8216;OK&#8217;: 0, 
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#8216;WARNING&#8217;: 1, 
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#8216;CRITICAL&#8217;: 2,
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#8216;UNKNOWN&#8217;: 3,
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#8216;DEPENDENT&#8217;: 4&#125;
def usage&#40;&#41;:
&#160; &#160; &#34;&#34;&#34; returns [...]]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://bsd.dischaos.com/files/nagios_plugin.py">template for nagios plugins</a> I use:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">#!/usr/bin/env python</span></p>
<p><span class="kw1">import</span> <span class="kw3">sys</span>, <span class="kw3">getopt</span></p>
<p>nagios_codes = <span class="br0">&#123;</span><span class="st0">&#8216;OK&#8217;</span>: <span class="nu0">0</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;WARNING&#8217;</span>: <span class="nu0">1</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;CRITICAL&#8217;</span>: <span class="nu0">2</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;UNKNOWN&#8217;</span>: <span class="nu0">3</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;DEPENDENT&#8217;</span>: <span class="nu0">4</span><span class="br0">&#125;</span></p>
<p><span class="kw1">def</span> usage<span class="br0">&#40;</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="st0">&quot; returns nagios status UNKNOWN with <br />
&nbsp; &nbsp; &nbsp; &nbsp; a one line usage description<br />
&nbsp; &nbsp; &nbsp; &nbsp; usage() calls nagios_return()<br />
&nbsp; &nbsp; &quot;</span><span class="st0">&quot;&quot;</span><br />
&nbsp; &nbsp; nagios_return<span class="br0">&#40;</span><span class="st0">&#8216;UNKNOWN&#8217;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;usage: {0} -h host&quot;</span>.<span class="me1">format</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></p>
<p><span class="kw1">def</span> nagios_return<span class="br0">&#40;</span><span class="kw3">code</span>, response<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="st0">&quot; prints the response message<br />
&nbsp; &nbsp; &nbsp; &nbsp; and exits the script with one<br />
&nbsp; &nbsp; &nbsp; &nbsp; of the defined exit codes<br />
&nbsp; &nbsp; &nbsp; &nbsp; DOES NOT RETURN <br />
&nbsp; &nbsp; &quot;</span><span class="st0">&quot;&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">print</span> <span class="kw3">code</span> + <span class="st0">&quot;: &quot;</span> + response<br />
&nbsp; &nbsp; <span class="kw3">sys</span>.<span class="me1">exit</span><span class="br0">&#40;</span>nagios_codes<span class="br0">&#91;</span><span class="kw3">code</span><span class="br0">&#93;</span><span class="br0">&#41;</span></p>
<p><span class="kw1">def</span> check_condition<span class="br0">&#40;</span>host<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="st0">&quot; a dummy check<br />
&nbsp; &nbsp; &nbsp; &nbsp; doesn&#8217;t really check anything <br />
&nbsp; &nbsp; &quot;</span><span class="st0">&quot;&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#123;</span><span class="st0">&quot;code&quot;</span>: <span class="st0">&quot;OK&quot;</span>, <span class="st0">&quot;message&quot;</span>: host + <span class="st0">&quot; ok&quot;</span><span class="br0">&#125;</span></p>
<p><span class="kw1">def</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="st0">&quot; example options processing<br />
&nbsp; &nbsp; &nbsp; &nbsp; here we&#8217;re expecting 1 option &quot;</span>-h<span class="st0">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; with a parameter<br />
&nbsp; &nbsp; &quot;</span><span class="st0">&quot;&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="kw2">len</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#41;</span> &lt; <span class="nu0">2</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; usage<span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">try</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; opts, args = <span class="kw3">getopt</span>.<span class="kw3">getopt</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">1</span>:<span class="br0">&#93;</span>, <span class="st0">&quot;h:&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">except</span> <span class="kw3">getopt</span>.<span class="me1">GetoptError</span>, err:<br />
&nbsp; &nbsp; &nbsp; &nbsp; usage<span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">for</span> o, value <span class="kw1">in</span> opts:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> o == <span class="st0">&quot;-h&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; host = value<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; usage<span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; result = check_condition<span class="br0">&#40;</span>host<span class="br0">&#41;</span><br />
&nbsp; &nbsp; nagios_return<span class="br0">&#40;</span>result<span class="br0">&#91;</span><span class="st0">&#8216;code&#8217;</span><span class="br0">&#93;</span>, result<span class="br0">&#91;</span><span class="st0">&#8216;message&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span></p>
<p><span class="kw1">if</span> __name__ == <span class="st0">&quot;__main__&quot;</span>:<br />
&nbsp; &nbsp; main<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/04/29/nagios-plugin-template-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fixing sound on ubuntu 8.10 intrepid and dell dimension e520</title>
		<link>http://bsd.dischaos.com/2009/01/30/fixing-sound-on-ubuntu-810-intrepid-and-dell-dimension-e520/</link>
		<comments>http://bsd.dischaos.com/2009/01/30/fixing-sound-on-ubuntu-810-intrepid-and-dell-dimension-e520/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 14:52:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[dimension e520]]></category>
		<category><![CDATA[intrepid]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=84</guid>
		<description><![CDATA[First check what version of the sound card you have in your dell:
# grep &#8216;Codec&#8217; /proc/asound/card0/codec#*
the command should return with &#8220;Codec: SigmaTel STAC9227&#8243;. If that&#8217;s the case add this line to your /etc/modprobe.d/alsa-base file:
options snd-hda-intel model=dell-3stack
and reboot.
]]></description>
			<content:encoded><![CDATA[<p>First check what version of the sound card you have in your dell:</p>
<blockquote><p># grep &#8216;Codec&#8217; /proc/asound/card0/codec#*</p></blockquote>
<p>the command should return with &#8220;Codec: SigmaTel STAC9227&#8243;. If that&#8217;s the case add this line to your <em>/etc/modprobe.d/alsa-base</em> file:</p>
<blockquote><p>options snd-hda-intel model=dell-3stack</p></blockquote>
<p>and reboot.</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/01/30/fixing-sound-on-ubuntu-810-intrepid-and-dell-dimension-e520/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>missing eth0 interface when moving between vmware hosts</title>
		<link>http://bsd.dischaos.com/2008/12/10/missing-eth0-interface-when-moving-between-vmware-hosts/</link>
		<comments>http://bsd.dischaos.com/2008/12/10/missing-eth0-interface-when-moving-between-vmware-hosts/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 17:19:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=71</guid>
		<description><![CDATA[This problem only happens when one uses udev to manage device node files and names of the network interfaces present in the system.
What can happen is that the eth0 interface present when running the server under one vmware instance can become missing after moving to another vmware host. Instead, the system will create a new [...]]]></description>
			<content:encoded><![CDATA[<p>This problem only happens when one uses udev to manage device node files and names of the network interfaces present in the system.</p>
<p>What can happen is that the eth0 interface present when running the server under one vmware instance can become missing after moving to another vmware host. Instead, the system will create a new eth interface &#8211; eth1.</p>
<p>This is because udev caches network attributes to interface name assignments to keep network interface names consistent between reboots. The problem is network card parameters (MAC address) can change with different instances of vmware. If the cached version doesn&#8217;t match the actual state udev creates a new device -&gt; name assignment.</p>
<p>To fix this in debian and debian-like distribution just delete this file: <em>/etc/udev/rules.d/z25_persistent-net.rules</em></p>
<p>The file will be generated again after rebooting (or restarting udev).</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2008/12/10/missing-eth0-interface-when-moving-between-vmware-hosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>recovering deleted files on an ext3 file system</title>
		<link>http://bsd.dischaos.com/2008/11/21/recovering-deleted-files-on-an-ext3-file-system/</link>
		<comments>http://bsd.dischaos.com/2008/11/21/recovering-deleted-files-on-an-ext3-file-system/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 16:49:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[ext3]]></category>
		<category><![CDATA[undelete]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=61</guid>
		<description><![CDATA[To my surprise this is actually possible. Moreover, it&#8217;s much easier than restoring files from ext2 partitions, where you have tools like foremost and photorec. With these tools you can restore contents of your files by looking for certain patterns in raw disk data. Restoring directory structure and file names isn&#8217;t that easy. The situation [...]]]></description>
			<content:encoded><![CDATA[<p>To my surprise this is actually possible. Moreover, it&#8217;s much easier than restoring files from ext2 partitions, where you have tools like foremost and photorec. With these tools you can restore contents of your files by looking for certain patterns in raw disk data. Restoring directory structure and file names isn&#8217;t that easy. The situation is a bit different with ext3 &#8211; all thanks to this great tool &#8211; ext3grep.</p>
<p>All one needs to restore deleted data is to unmount your hdd as soon as possible (or remount it ro) and take a copy of it using dd.</p>
<p>Download ext3grep from <a href="http://code.google.com/p/ext3grep/">http://code.google.com/p/ext3grep/</a> , untargzip it and compile. The easies way to use it I&#8217;ve found is to give it a date to undelete all files removed after.</p>
<blockquote><p>ext3grep /dev/sdb1 &#8211;restore-all &#8211;after=1226937993</p></blockquote>
<p>It will create a RESTORED_FILES directory and create all recovered files and directores there. It does take some time to do that, but after all it&#8217;s a bit complicated process <img src='http://bsd.dischaos.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  A very interesting and detailed document about the internals of ext3, file recovery and ext3grep (with more examples) is <a href="http://www.xs4all.nl/~carlo17/howto/undelete_ext3.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2008/11/21/recovering-deleted-files-on-an-ext3-file-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
