Wednesday, November 26, 2008

Clear Swap Space in Linux

There have been times where it has been necessary for me to clear out the swap space on a Linux system. In order to do this, you must first make sure that you have enough free memory to hold what is being used by swap.
I usually do this in a few steps. You do need to be root to do this. First I want to see what is currently being used.
free

Then I run the actual commands that empty the swap:
swapoff -a && swapon -a

Then I check what is being used after doing this.
free

I have these three steps in a script and then I just run the script, but, the commands could easily be run from the command line.

Tuesday, November 18, 2008

Create Solaris Package from Source

For this example I will use stunnel since I had to create this package at work today. This software will be compiled from source and created as a package.

First we create a directory structure for our new package. In this example, I'll use /var/tmp/src, but it can be created anywhere.

# cd /var/tmp/src
# mkdir LDSstunnel InfoPath

In the InfoPath directory which we just created, use your favorite text editor (vi) to create a file named pkginfo with the following contents.

ARCH=SPARC
CATEGORY=application
NAME=stunnel
PKG=LDSstunnel
VERSION=4.26
DESC=allows to encrypt arbitrary TCP connections inside SSL
VENDOR=stunnel source taken from http://www.stunnel.org
- ARCH - is the architecture this package is built for. Can be sparc, i386 or ppc
- CATEGORY - list under which category to display the package
- NAME - short name of the package
- PKG - name of package. It is customary to make the first four letters unique to your company, such as a stock symbol.
- VERSION - version of package. In this case this is the version of stunnel
- DESC - descriptive information about the package
- VENDOR - used to describe the vendor that holds the software copyright
More information about these fields and other fields that can be used is in the pkginfo(4) man page.


Configure, compile, and install the software in a unique place

# ./configure --prefix=/opt/LDSstunnel
# make
# make install
# cd /opt/LDSstunnel
# mv * /
var/tmp/src/LDSstunnel/
# cd ..
# rmdir LDSstunnel

Make any changes that need to be made to config files, etc.
I copied a default configuration file into /var/tmp/src/LDSstunnel/etc/stunnel/

In the InfoPath directory create a file named prototype. This file can be created manually, however, it is much easier to use the pkgproto tool.
# cd /var/tmp/src
# pkgproto ./LDSstunnel > InfoPath/prototype

Add a line to the end of the prototype file with information about the pkginfo file
# echo "i pkginfo=/var/tmp/src/InfoPath/pkginfo" >> InfoPath/prototype

Use the pkgmk tool to create the package
# pkgmk -f InfoPath/prototype -b /var/tmp/src

We can now use the pkginfo command to get information about this new package which is in the /var/spool/pkg directory
# cd /var/spool/pkg
# pkginfo -d .
application LDSstunnel stunnel

Our package is located in the /var/spool/pkg directory. We could copy the contents of this directory to an nfs export or tarball it and copy it to the destination server and install.

Monday, November 17, 2008

vsftp and /etc/shells

I discovered today that there are a couple of issues with using local accounts with VSFTP. The first issue which is obvious is that local_enable=YES needs to be set in the vsftpd.conf file. The other issue that is not as obvious is that if you have a local user that has a shell set to /bin/false or /sbin/nologin, that user will get a incorrect login error when they try to login. The thing I did to fix this problem was added /sbin/nologin to /etc/shells. This worked on a SUSE Linux Enterprse Server 10 (SLES 10) server. The simple command that I used to do this was:

#echo /sbin/nologin >> /etc/shells