~ibmcharmers/charms/trusty/layer-ibm-mobilefirst-server/devel

« back to all changes in this revision

Viewing changes to reactive/ibm-db2.sh

  • Committer: Suchitra Venugopal
  • Date: 2016-06-06 11:28:52 UTC
  • Revision ID: suchvenu@in.ibm.com-20160606112852-gtn2b7nd23cpl3vv
DB2 Review Rework

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
DB2_USER_PW=db2inst1
11
11
DB2_INSTALL_PATH=/opt/ibm/db2/V10.5
12
12
AUTH_KEY_FILE=/root/.ssh/authorized_keys
 
13
TEMP_KEY_FILE=key.txt
13
14
 
14
15
cfgusername=""
15
16
 
465
466
        fi
466
467
else
467
468
        juju-log "IBM DB2: Creating the DB names as passed by consumer"
468
 
        #parse the $dbnames string to get the names of dbs to be created
469
 
        count=1
470
 
        db_to_create="test"
471
 
        while [ "$db_to_create" != "" ]
472
 
        do
473
 
                db_to_create=`echo $dbnames | cut -d"," -f$count`
474
 
                if [ "$db_to_create" != "" ] ; then
475
 
                        create_database $db_to_create $servicename
476
 
                        if [ $isdbcreated == 1 ] ; then
477
 
                                dbs_created+=$db_to_create
478
 
                                dbs_created+="."
 
469
        if [ `echo $dbnames | grep -c "," ` -gt 0 ]
 
470
        then
 
471
                #parse the $dbnames string to get the names of dbs to be created
 
472
                count=1
 
473
                db_to_create="test"
 
474
                while [ "$db_to_create" != "" ]
 
475
                do
 
476
                        db_to_create=`echo $dbnames | cut -d"," -f$count`
 
477
                        juju-log "IBM DB2:db_to_create is $db_to_create"
 
478
                        if [ "$db_to_create" != "" ] ; then
 
479
                                create_database $db_to_create $servicename
 
480
                                juju-log "Created DB $db_to_create"
 
481
                                if [ $isdbcreated == 1 ] ; then
 
482
                                        dbs_created+=$db_to_create
 
483
                                        dbs_created+="."
 
484
                                fi
479
485
                        fi
480
 
                fi
481
 
                ((count=count+1))
482
 
        done
 
486
                        ((count=count+1))
 
487
                done
 
488
                juju-log "Suchitra - outside loop"
 
489
 
 
490
        else
 
491
                create_database $dbnames $servicename
 
492
                juju-log "Created DB $dbnames"
 
493
                dbs_created+=$dbnames
 
494
                dbs_created+="."
 
495
 
 
496
        fi
483
497
 
484
498
fi
485
499
isdbcreated=0
486
500
}
487
501
 
 
502
remove_sshkeys()
 
503
{
 
504
        servicename=$1
 
505
        #Read the key from the key.txt file and see whether it exists
 
506
        if grep -q "$servicename" $TEMP_KEY_FILE
 
507
        then
 
508
        key=`cat $TEMP_KEY_FILE | grep $servicename | cut -d":" -f2`
 
509
        juju-log "Key is $key"
 
510
        grep -v "$key" $AUTH_KEY_FILE > tempfile.txt
 
511
        mv tempfile.txt $AUTH_KEY_FILE
 
512
        if grep -q "$key" $AUTH_KEY_FILE
 
513
        then
 
514
                juju-log "IBM DB2: SSH Key not deleted from $AUTH_KEY_FILE"
 
515
        else
 
516
                juju-log "IBM DB2: SSH Key deleted from $AUTH_KEY_FILE"
 
517
        fi
 
518
        #Remove from the temporary file as well
 
519
        grep -v "$servicename:$key" $TEMP_KEY_FILE > tempfile1.txt
 
520
        mv tempfile1.txt $TEMP_KEY_FILE
 
521
        if grep -q "$key" $TEMP_KEY_FILE
 
522
        then
 
523
                juju-log "IBM DB2: SSH Key not deleted from $TEMP_KE    Y_FILE"
 
524
        else
 
525
                juju-log "IBM DB2: SSH Key deleted from $TEMP_KEY_F    ILE"
 
526
        fi
 
527
 
 
528
fi
 
529
 
 
530
}
 
531
 
488
532
 
489
533
@when 'ibm-db2.installed'
490
534
@when_not 'ibm-base.license.accepted'
493
537
        status-set maintenance "IBM DB2 is getting uninstalled"
494
538
        remove_software
495
539
        remove_state 'ibm-db2.installed'
496
 
        remove_state 'ibm-db2.client.sshconfigured'
 
540
        #remove_state 'ibm-db2.client.sshconfigured'
497
541
        set_state 'ibm-db2.uninstalled'
498
542
        status-set maintenance "IBM DB2 is uninstalled"
 
543
        rm -rf $TEMP_KEY_FILE
499
544
        
500
545
}
501
546
 
507
552
        for service in $services; do
508
553
                juju-log "IBM DB2: Resetting states for the service $service"
509
554
                relation_call --state=db.available reset_states $service
 
555
                relation_call --state=db.departed dismiss_sshconfigured $service || true
510
556
        done
511
557
 
512
558
        remove_state 'ibm-db2.uninstalled'
615
661
        configure_system
616
662
        #Configure DFTDBPATH
617
663
        configure_dftdbpath
 
664
        echo "Tempory Key File" > $TEMP_KEY_FILE
618
665
        set_state 'ibm-db2.installed'
619
666
        remove_state 'ibm-db2.uninstalled'
620
667
        status-set active "IBM DB2 Installed"
640
687
 
641
688
                # Add the key to the authorized_keys file, if it exists
642
689
                set +e
 
690
                #Create a temp key file if it doesn't exist
 
691
                if [ -f $TEMP_KEY_FILE ]; then
 
692
                        juju-log "Temp file already exists"
 
693
                else
 
694
                        echo "Temp Key File" > $TEMP_KEY_FILE
 
695
                fi
643
696
                if [ -f $AUTH_KEY_FILE ]; then
644
697
                        # Append only if the key is not present
645
698
                        juju-log "IBM DB2: Updating the key file"
647
700
                        if [ $? != 0 ]; then
648
701
                                juju-log "IBM DB2: Updating authorized keys file"
649
702
                                echo "$key" >> $AUTH_KEY_FILE
 
703
                                echo "$service:$key" >> $TEMP_KEY_FILE
650
704
                        else
651
705
                                juju-log "IBM DB2: Key already present"
652
706
                        fi
653
707
                else
654
708
                        juju-log "IBM DB2: Creating authorized keys file"
655
709
                        echo "$key" > $AUTH_KEY_FILE
 
710
                        echo "$service:$key" > $TEMP_KEY_FILE
656
711
                fi
657
712
                set -e
658
713
        done
659
714
        juju-log "IBM DB2: Completed updating the authorized key"
660
 
        set_state 'ibm-db2.client.sshconfigured'
 
715
        #set_state 'ibm-db2.client.sshconfigured'
 
716
        relation_call --state=db.available set_sshconfigured $service || true
661
717
}
662
718
 
663
719
@when 'db.ready'
664
720
@when 'ibm-db2.installed'
665
 
@when 'ibm-db2.client.sshconfigured'
 
721
@when 'db.sshconfigured'
666
722
function create_consumer_dbs(){
667
723
        DB2_INSTALL_PATH=/opt/ibm/db2/V10.5
668
724
        services=$(relation_call --state=db.available services)
712
768
                else
713
769
                        juju-log "IBM DB2: DB2 is already stopped for the instance $cfgusername"
714
770
                fi
 
771
                #Remove the ssh key entry from ssh keys file
 
772
                remove_sshkeys $service
715
773
                relation_call --state=db.departed dismiss $service || true
 
774
                relation_call --state=db.departed dismiss_sshconfigured $service || true
716
775
        done
717
 
        remove_state 'ibm-db2.client.sshconfigured'
 
776
        #remove_state 'ibm-db2.client.sshconfigured'
718
777
}
719
778
 
720
779