5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 LOG_BASE_DIR=/srv/deployment/log
20 DB_LOG=${LOG_BASE_DIR}/redis.log
24 CM_VALIDATORS=/opt/cmframework/validators
25 CM_ACTIVATORS=/opt/cmframework/activators
26 CM_LOG=${LOG_BASE_DIR}/cm.log
27 USER_CONFIG_HANDLERS=/opt/cmframework/userconfighandlers
28 INVENTORY_HANDLERS=/opt/cmframework/inventoryhandlers
29 INVENTORY_DATA=/opt/cmframework/inventory.data
32 BOOTSTRAP_LOG=${LOG_BASE_DIR}/bootstrap.log
34 DB_STARTUP_CMD="/bin/redis-server ./redis.conf"
35 DB_CHECK_CMD="/bin/redis-cli -h $DB_IP --scan --pattern '*'"
36 CMCLI="/usr/local/bin/cmcli --ip $CM_IP --port $CM_PORT --client-lib cmframework.lib.cmclientimpl.CMClientImpl"
39 export CONFIG_PHASE="bootstrapping"
48 echo "$(date) ($priority) ${FUNCNAME[2]} ${@:2}"
49 echo "$(date) ($priority) ${FUNCNAME[2]} ${@:2}" >> $BOOTSTRAP_LOG
66 result=$(eval $@ 2>&1)
68 if [ $ret -ne 0 ]; then
69 log_error "Failed with error $result"
71 log_info "Command succeeded: $result"
77 function stop_process()
80 log_info "Stopping process $pid"
81 if ! [ -z $pid ]; then
82 if [ -d /proc/$pid ]; then
83 log_info "Shutting down process $pid gracefully"
84 run_cmd "pkill -TERM -g $pid"
85 log_info "Waiting for process $pid to exit"
86 for ((i=0; i<10; i++)); do
87 if ! [ -d /proc/$pid ]; then
88 log_info "Process $pid exited"
91 log_info "Process $pid is still running"
95 if [ -d /proc/$pid ]; then
96 log_error "Process $pid is still running, forcefully shutting it down"
97 run_cmd "pkill -KILL -g $pid"
105 log_info "Cleaning up"
106 #stop_process $DB_PID
113 log_info "Starting redis db using $DB_STARTUP_CMD"
114 #setsid $DB_STARTUP_CMD &
116 #log_info "DB pid is $DB_PID"
117 #if ! [ -d /proc/$DB_PID ]; then
118 # log_error "DB is not running!"
119 # log_info "Check /var/log/redis.log and $BOOTSTRAP_LOG for details"
122 systemctl start redis
123 log_info "Wait till DB is serving"
125 for ((i=0; i<10; i++)); do
126 run_cmd "$DB_CHECK_CMD"
128 if [ $dbok -eq 0 ]; then
131 log_info "DB still not running"
140 log_info "Starting CM server"
141 setsid /usr/local/bin/cmserver --ip $CM_IP --port $CM_PORT --backend-api cmframework.redisbackend.cmredisdb.CMRedisDB --backend-uri redis://:@$DB_IP:$DB_PORT --activationstate-handler-api cmframework.utils.cmstatedummyhandler.CMStateDummyHandler --activationstate-handler-uri dummy_uri --snapshot-handler-api cmframework.utils.cmstatedummyhandler.CMStateDummyHandler --alarmhandler-api cmframework.lib.cmalarmhandler_dummy.AlarmHandler_Dummy --snapshot-handler-uri dummy_uri --inventory-handlers $INVENTORY_HANDLERS --inventory-data $INVENTORY_DATA --validators $CM_VALIDATORS --activators $CM_ACTIVATORS --disable-remote-activation --log-dest console --log-level debug --verbose 2> $CM_LOG 1>&2 &
143 log_info "cmserver pid is $CM_PID"
144 if ! [ -d /proc/$CM_PID ]; then
145 log_error "CM server is not running!"
146 log_info "Check redis.log and $BOOTSTRATP_LOG for details"
152 function handle_user_config()
154 log_info "Handling user configuration from file $USER_CONFIG"
155 run_cmd "$CMCLI bootstrap --config $USER_CONFIG --plugin_path $USER_CONFIG_HANDLERS"
163 if [ $? -ne 0 ]; then
168 # start the configuration management server
170 if [ $? -ne 0 ]; then
178 echo "Use CLI $CMCLI"
181 read -n1 -r -p "Press space to exit..." key
183 if [ "$key" = '' ]; then
193 if [ $# -ne 1 ]; then
194 echo "Usage:$0 <cmserver ip>"
199 CMCLI="/usr/local/bin/cmcli --ip $CM_IP --port $CM_PORT --client-lib cmframework.lib.cmclientimpl.CMClientImpl"
200 mkdir -p ${LOG_BASE_DIR}