aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool/sdc-cassandra-init/chef-repo/cookbooks/cassandra-actions/templates/default/create_cassandra_user.sh.erb
blob: 426eed83dfb35f911dbe6baece220a1e1b820ff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash

CASSANDRA_IP=<%= @cassandra_ip %>
CASSANDRA_PORT=<%= @cassandra_port %>
CS_PASSWORD=<%= @cassandra_pwd %>
SDC_USER=<%= @sdc_usr %>
SDC_PASSWORD=<%= @sdc_pwd %>


pass_changed=99
retry_num=1
is_up=0
while [ $is_up -eq 0 -a $retry_num -le 100 ]; do

   echo "exit" | cqlsh -u cassandra -p $CS_PASSWORD $CASSANDRA_IP $CASSANDRA_PORT  > /dev/null 2>&1
   res1=$?

   if [ $res1 -eq 0 ]; then
      echo "`date` --- cqlsh is enabled to connect."
      is_up=1
   else
      echo "`date` --- cqlsh is NOT enabled to connect yet. sleep 5"
      sleep 5
   fi
   let "retry_num++"
done

cassandra_user_exist=`echo "list users;" | cqlsh -u cassandra -p $CS_PASSWORD $CASSANDRA_IP $CASSANDRA_PORT | grep -c $SDC_USER`
        if [ $cassandra_user_exist -eq 1 ] ; then
                echo "cassandra user $SDC_USER already exist"
        else
                echo "Going to create $SDC_USER"
                echo "create user $SDC_USER with password '$SDC_PASSWORD' nosuperuser;" | cqlsh -u cassandra -p $CS_PASSWORD $CASSANDRA_IP $CASSANDRA_PORT
        fi