6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
19 This script can be used to start a private cmserver to test your CM userconfighandler and/or validator plugins.
21 To test userconfighandlers and installation time validators do the following:
22 - Copy your userconfighandler to a target system under /opt/cmframework/userconfighandlers/ directory.
24 - Copy your validator to a target system under /opt/cmframework/validators directory.
26 - Start a private cmserver
27 ./start-private-cmserver.sh <some port number> no-cm-data
29 - The above command will print information about the temporary directory used for the private cmserver, it will also print the command to be used to access the cmserver e.g. the output can look like:
31 =======================================================================================================================
32 Use CLI /opt/bin/cmcli --ip 127.0.0.1 --port 51110
33 Root DIR /tmp/tmp.HcyehIQQoQ
34 =======================================================================================================================
36 - Test your plugins by running the following command:
37 /opt/bin/cmcli --ip 127.0.0.1 --port <port> bootstrap --config /opt/userconfig/user_config.yaml --plugin_path /<cmserver root>/opt/cmframework/userconfighandlers
39 - If the above succeeds then your userconfighandler and validator are working properly. You can view the configuration data by running the following command:
40 /opt/bin/cmcli --ip 127.0.0.1 --port <port> get-properties --matching-filter '.*'
42 To test run-time validation do the following:
43 - Copy your validator to a target system under /opt/cmframework/validators directory.
45 - Start a private cmserver
46 ./start-private-cmserver.sh <some port number> no-cm-data
48 - The above command will print information about the temporary directory used for the private cmserver, it will also print the command to be used to access the cmserver e.g. the output can look like:
50 =======================================================================================================================
51 Use CLI /opt/bin/cmcli --ip 127.0.0.1 --port 51110
52 Root DIR /tmp/tmp.HcyehIQQoQ
53 =======================================================================================================================
55 - Test your plugins by changing the configuration by running the following command:
56 /opt/bin/cmcli --ip 127.0.0.1 --port <port> set-property --property NAME VALUE
58 - If the above succeeds then your validator is working properly. You can view the configuration data by running the following command:
59 /opt/bin/cmcli --ip 127.0.0.1 --port <port> get-properties --matching-filter '.*'
66 CM_VALIDATORS=$ROOT_DIR/opt/cmframework/validators
67 CM_ACTIVATORS=$ROOT_DIR/opt/cmframework/activators
68 CM_LOG=$ROOT_DIR/var/log/cm.log
69 USER_CONFIG_HANDLERS=$ROOT_DIR/opt/cmframework/userconfighandlers
70 INVENTORY_HANDLERS=$ROOT_DIR/opt/cmframework/inventoryhandlers
71 INVENTORY_DATA=$ROOT_DIR/inventory.data
73 LOG_FILE=$ROOT_DIR/var/log/cm.log
78 CMCLI="/usr/local/bin/cmcli --ip $CM_IP --port $CM_PORT"
81 export CONFIG_PHASE="bootstrapping"
90 echo "$(date) ($priority) ${FUNCNAME[2]} ${@:2}"
91 echo "$(date) ($priority) ${FUNCNAME[2]} ${@:2}" >> $LOG_FILE
107 log_info "Running $@"
108 result=$(eval $@ 2>&1)
110 if [ $ret -ne 0 ]; then
111 log_error "Failed with error $result"
113 log_info "Command succeeded: $result"
119 function prepare_environment()
121 mkdir -p $(dirname $CM_LOG)
122 log_info "Creating directories under $ROOT_DIR"
123 run_cmd "mkdir -p $USER_CONFIG_HANDLERS"
124 run_cmd "mkdir -p $INVENTORY_HANDLERS"
125 run_cmd "mkdir -p $CM_VALIDATORS"
126 run_cmd "mkdir -p $CM_ACTIVATORS"
127 run_cmd "mkdir -p $DB_DIR"
129 log_info "Copying inventory handlers and user config handlers to $ROOT_DIR"
130 cp -f /opt/cmframework/userconfighandlers/* $USER_CONFIG_HANDLERS/
131 cp -f /opt/cmframework/inventoryhandlers/* $INVENTORY_HANDLERS/
132 cp -f /opt/cmframework/validators/* $CM_VALIDATORS/
134 if [ $NO_CM_DATA -eq 0 ]; then
135 log_info "Generating DB file under $DB_FILE"
136 /usr/local/bin/cmcli get-properties --matching-filter '.*' > $DB_FILE
141 function stop_process()
144 log_info "Stopping process $pid"
145 if ! [ -z $pid ]; then
146 if [ -d /proc/$pid ]; then
147 log_info "Shutting down process $pid gracefully"
148 run_cmd "pkill -TERM -g $pid"
149 log_info "Waiting for process $pid to exit"
150 for ((i=0; i<10; i++)); do
151 if ! [ -d /proc/$pid ]; then
152 log_info "Process $pid exited"
155 log_info "Process $pid is still running"
159 if [ -d /proc/$pid ]; then
160 log_error "Process $pid is still running, forcefully shutting it down"
161 run_cmd "pkill -KILL -g $pid"
169 log_info "Cleaning up"
176 log_info "Starting CM server $CM_IP $CM_PORT $CM_LOG"
178 if [ $NO_CM_DATA -eq 1 ]; then
179 extra_args="--install-phase"
181 setsid /usr/local/bin/cmserver --ip $CM_IP --port $CM_PORT --backend-api cmframework.filebackend.cmfilebackend.CMFileBackend --backend-uri $DB_FILE --activationstate-handler-api cmframework.utils.cmstatedummyhandler.CMStateDummyHandler --activationstate-handler-uri dummy_uri --alarmhandler-api cmframework.lib.cmalarmhandler_dummy.AlarmHandler_Dummy --snapshot-handler-api cmframework.utils.cmstatedummyhandler.CMStateDummyHandler --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 $extra_args 2> $CM_LOG 1>&2 &
183 log_info "cmserver pid is $CM_PID"
184 if ! [ -d /proc/$CM_PID ]; then
185 log_error "CM server is not running!"
186 log_info "Check $CM_LOG for details"
194 # prapare private environment
196 if [ $? -ne 0 ]; then
201 # start the configuration management server
203 if [ $? -ne 0 ]; then
212 echo "======================================================================================================================="
213 echo "Use CLI $CMCLI"
214 echo "Root DIR $ROOT_DIR"
215 echo "======================================================================================================================="
219 read -n1 -r -p "Press 'q' space to exit..." key
221 if [ "$key" = 'q' ]; then
231 if [ $# -lt 1 ]; then
232 echo "Usage:$0 <cmserver port> [no-cm-data]"
240 if [ "$arg" == "no-cm-data" ]; then
247 CMCLI="/usr/local/bin/cmcli --ip $CM_IP --port $CM_PORT"