Friday, June 29, 2012

DB2 Automatic startup for Linux/Unix

For many Tivoli installations, chances are you also need to setup DB2 for database services. One of the common issue with DB2 installations is that it is not setup to start automatically on reboot in Unix/Linux systems. IIRC, this feature was there in very old DB2 installations but removed for unknown reason.  So everytime your system reboots (however rare that may be), you would have to manually bring the service up.

To address this issue, usually the DB2 DBAs write a script to run DB2 automatically during startup.  If you don't have DBA support in your site, here is a very simple startup script that can be used to start DB2 automatically.   You will need root privileges to add this script to startup.


1.  Copy the following file and save it as /etc/init.d/db2server

#!/bin/bash
#
# chkconfig: - 91 35
# description: Starts and stops db2server. \

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0


prog="DB2"
inst="db2inst1"
start() {
    echo -n $"Starting $prog: "
    su - $inst -c "db2start"
}

stop() {
    echo -n $"Shutting down $prog: "
    su - $inst -c "db2stop force"
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        stop
        sleep 3
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac

2. Run the following commands as root. (Tested on RHEL5)
# chmod a+x /etc/init.d/db2server
# ln -s /etc/init.d/db2server /etc/rc.d/rc5.d/S99Db2Server
# ln -s /etc/init.d/db2server /etc/rc.d/rc3.d/S99Db2Server
# ln -s /etc/init.d/db2server /etc/rc.d/rc1.d/K10Db2Server
# ln -s /etc/init.d/db2server /etc/rc.d/rc0.d/K10Db2Server

That is it!   The above steps should work for Linux systems.  Please note that Unix systems (AIX, Solaris and HPUX) do follow different rc.d directory structure and you may have to link it to appropriate directory structure for your operating system. 

Also the script is setup to use db2inst1 as the DB2 instance owner. If your site uses different user, change the script accordingly. 

Hope this helps.

1 comment:

Unknown said...

I know it's an old article but normally with DB2 you use the "Fault Monitor Coordinator daemon" (db2fmcd) and you select which instance you want to start automatically with db2iauto

Just my 2¢ ;-)