summaryrefslogtreecommitdiffstats
path: root/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/change_cassandra_pass.sh.erb
blob: d3f5da6b12a6e6a5c83c1361849bb9e298e0bdb3 (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
#!/bin/bash

CASSANDRA_PASS=<%= @cassandra_pwd %>
CASSANDRA_IP=<%= @cassandra_ip %>
CASSANDRA_PORT=<%= @cassandra_port %>

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 cassandra $CASSANDRA_IP $CASSANDRA_PORT
   res1=$?
   echo "exit" | cqlsh -u cassandra -p $CASSANDRA_PASS $CASSANDRA_IP $CASSANDRA_PORT
   res2=$?

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

if [ $res1 -eq 0 -a $res2 -eq 1 -a $is_up -eq 1 ]; then
 echo "Modify cassandra password"
 echo "ALTER USER cassandra WITH PASSWORD '$CASSANDRA_PASS';" | cqlsh -u cassandra -p cassandra $CASSANDRA_IP $CASSANDRA_PORT
elif [ $res1 -eq 1 -a $res2 -eq 0 -a $is_up -eq 1 ]; then
 echo "cassandra password already modified"
else exit 1
fi