martedì 23 settembre 2014

How to Auto Start more then one instance of DB2 in linux environment

When a DB2 server has more than one instance in a linux environment, it may be useful to prepare different scripts for automatic startup of the instances to riavvo server.

In linux environment each instance has a "user" owner, and only that user can start the instance correctly, in parallel, in most cases you do not want the service to run with root privileges.

to solve the problem it is sufficient to copy the following script in /etc/init.d
give you the rights to run and specify the user under which to boot, change the parameter

DB2_USER

and assign it with  the user name which to run DB2.


    #!/bin/sh
    #
    # Startup script for DB2
    # by A.F.
    #


   DB2_USER=db2inst1

    ### BEGIN INIT INFO
    # Provides:       $DB2_USER
    # Required-Start: $network $remote_fs
    # Required-Stop: $network $remote_fs
    # Default-Start: 3
    # Default-Stop: 0 1 2 5 6
    # Short-Description: DB2 $DB2_USER job service
    # Description:  DB2 Instance $DB2_USER job service
    ### END INIT INFO

    # Find the name of the script
    NAME=`basename $0`

    start() {
        DB2_START=$"Starting ${NAME} service: "

        su - $DB2_USER -c '. ./sqllib/db2profile; \
            ./sqllib/adm/db2start > /dev/null'

        ret=$?
        if [ $ret -eq 0 ]
        then
                echo "$DB2_START Success."
        else
                echo "$DB2_START Failed!"
                exit 1
        fi
        echo
    }

    stop() {
        echo -n $"Stopping ${NAME} service: "

        su - $DB2_USER -c '. ./sqllib/db2profile; \
            ./sqllib/adm/db2stop > /dev/null'

        ret=$?
        if [ $ret -eq 0 ]
        then
                echo "Success."
        else
                echo "Failed!"
                exit 1
        fi
      echo
    }
    restart() {
        stop
        start
    }
    case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        restart)
            restart
            ;;
        *)
            echo $"Usage: $0 {start|stop|restart}"
            exit 1
    esac
    exit 0














Nessun commento:

Posta un commento