Archive for December, 2007

How to get the absolute path to the folder of current program

Monday, December 24th, 2007
PROG_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
  • Share/Bookmark

How to determine Current Fedora version

Sunday, December 23rd, 2007

use rpm command:

rpm -q --queryformat '%{VERSION}' fedora-release

or check file:

cat /etc/fedora-release | sed 's/^.*release.([0-9]+).*$/1/'
  • Share/Bookmark

Setup rsync server

Thursday, December 20th, 2007

For example, we want to set up an rsync server to duplicate the subversion server data to other computers.

First, of cause we have to have rsync installed. For fedora, this should be included in default installation.

Then we will create the config folder and config in Fedora’s style:

cd /etc
mkdir rsyncd
cd rsyncd
touch rsyncd.conf
touch rsyncd.motd
touch rsyncd.secrets
chmod 600 rsyncd.secrets

Then will edit rsyncd.conf file:

pid file=/var/run/rsyncd.pid
port=873
address=192.168.2.111
uid=root
gid=root
use chroot=yes
read only=yes

# limit access to LANS
hosts allow=192.168.2.0/255.255.255.0
host deny=*

max connections=5
motd file=/etc/rsyncd/rsyncd.motd

log format=%t%a%m%f%b
syslog facility=local3
timeout=300

[svn]
path=/var/www/svn
list=yes
ignore errors
auth users=svnsyncer
secrets file=/etc/rsyncd/rsyncd.secrets
comment=SVN Repository

We will add the welcome message to /etc/rsyncd/rsyncd.motd

Welcome the SVN rsync service

Add user/password to /etc/rsyncd/rsyncd.secrets

svnsyncer:123456

And then, we will create our init start up script named /etc/init.d/rsyncd

#!/bin/sh
#
# Startup script for rsyncd daemon
#
# chkconfig: 35 90 10
# description: Server data for sync to other server
# processname rsync

# Source function library
. /etc/rc.d/init.d/functions

prog=rsync
conf=/etc/rsyncd/rsyncd.conf

case "$1" in
    start)
        echo -n "Starting rsync daemon: "
        daemon /usr/bin/$prog --daemon --config=$conf
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
        ;;
    stop)
        echo -n "Shutting down $prog: "
        killproc -d 60 $prog
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
        ;;
    status)
        status $prog
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac

exit 0

We will register and this service by

/sbin/chkconfig --add rsyncd
/sbin/service rsyncd start
  • Share/Bookmark

SSH no password login

Wednesday, December 19th, 2007

first, on your local machine, generate the key pair:

ssh-keygen -t dsa

Copy public key file .ssh/id_dsa.pub to server you are going to login.

Append the key to .ssh/authorized_keys by

cat id_dsa.pub >> .ssh/authorized_keys
  • Share/Bookmark

Install sun JDK on Fedora 8

Friday, December 7th, 2007

Download JDK from Sun’s website, and install it. The default install path should under /usr/java.

We create a new alternative entry:

/usr/sbin/alternatives --install
    /usr/bin/java java
    /usr/java/latest/jre/bin/java 2

and then we config the java alternative settings, select the sun version:

/usr/sbin/alternatives --config java

And we are good to go.

  • Share/Bookmark