This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
forked from informix/informix-server-dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
informix_setup_hqagent.sh
145 lines (106 loc) · 3.79 KB
/
informix_setup_hqagent.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
#
# name: informix_setup_hqagent.sh:
# description: Setup HQ server on docker image
# Called by: informix_entry.sh
PROP_PATH=$INFORMIXDIR/hq/agent.properties
HQLOG=$INFORMIXDIR/hq/hq.log
SLEEP=60
ITER=10
HQLOG ">>> HQAGENT: "
HQLOG ">>> HQADMIN_PASSWORD: ${env_HQADMIN_PASSWORD}"
HQLOG ">>> INFORMIX_PASSWORD: ${env_INFORMIX_PASSWORD}"
HQLOG ">>> HOSTNAME : $HOSTNAME"
HQLOG ">>> HQSERVER_MAPPED_HOSTNAME: ${env_HQSERVER_MAPPED_HOSTNAME}"
HQLOG ">>> HQSERVER_MAPPED_HTTP_PORT: ${env_HQSERVER_MAPPED_HTTP_PORT}"
HQLOG ">>> MAPPED_HOSTNAME: ${env_MAPPED_HOSTNAME}"
HQLOG ">>> HQSERVER : $env_HQSERVER"
HQSERVER_ID=0
HQAGENT_ID=0
###
### Register Server attempt(s)
###
register_hqagent_with_hqserver() {
HQLOG ">>> REGISTERING HQAGENT with HQSERVER"
HQLOG ">>> REGISTER ATTEMPT $i"
for i in $(eval echo "{1..$ITER}")
do
REGISTERED_ID=`curl -basic -u admin:${env_HQADMIN_PASSWORD} -H 'Content-Type: application/json' -H 'Accept: application/json' http://${env_HQSERVER_MAPPED_HOSTNAME}:${env_HQSERVER_MAPPED_HTTP_PORT}/api/informix --data-binary "{'groupId': 0, 'alias': '${env_MAPPED_HOSTNAME}', 'hostname': '${env_MAPPED_HOSTNAME}', 'port': ${env_MAPPED_SQLI_PORT}, 'monitorUser': 'informix', 'monitorPassword': '${env_INFORMIX_PASSWORD}', 'adminUser': 'informix', 'adminPassword': '${env_INFORMIX_PASSWORD}'}" 2>/dev/null | jq '.id'`
HQLOG ">>> REGISTER ATTEMPT $i"
if [[ ! -z ${REGISTERED_ID} ]]
then
break
fi
sleep $SLEEP
done
HQAGENT_ID=$REGISTERED_ID
HQLOG ">>> HQAGENT SERVER ID $HQAGENT_ID"
}
###
### Create Properties file
###
create_properties_file() {
sudo echo "" > $PROP_PATH
sudo chmod 644 $PROP_PATH
sudo echo "informixServer.id=$HQAGENT_ID" >> $PROP_PATH
sudo echo "server.host=${env_HQSERVER_MAPPED_HOSTNAME}" >> $PROP_PATH
sudo echo "server.port=${env_HQSERVER_MAPPED_HTTP_PORT}" >> $PROP_PATH
cat $PROP_PATH >> $HQLOG
}
###
### Run hqagent
###
start_hqagent() {
cd $INFORMIXDIR/hq
java -jar $INFORMIXDIR/hq/informixhq-agent.jar >> $HQLOG &
}
##
## Get Server list, find server id, pass in string
get_server_id() {
SERVNAME=$1
for i in $(eval echo "{1..$ITER}")
do
HQLOG "GET server($SERVNAME) ID ATTEMPT: $i"
SERVER_LIST=`curl -basic -u admin:${env_HQADMIN_PASSWORD} -H 'Content-Type: application/json' -H 'Accept: application/json' http://${env_HQSERVER_MAPPED_HOSTNAME}:${env_HQSERVER_MAPPED_HTTP_PORT}/api/informix/groups/0 2>/dev/null `
if [[ ! -z ${SERVER_LIST} ]]
then
FOUND_SERVER_ID=`echo $SERVER_LIST| jq '.servers[] | select(.alias=="'$SERVNAME'") | .id '`
if [[ ! -z $FOUND_SERVER_ID ]]
then
break
fi
fi
sleep $SLEEP
done
HQLOG ">>> HQSERVER ($SERVNAME) ID: ${FOUND_SERVER_ID}"
echo $FOUND_SERVER_ID
}
## Register hqserver id, as storage database server
## and hqmon as the database
set_server_storage() {
for i in $(eval echo "{1..$ITER}")
do
REGISTER=`curl -X PUT -basic -u admin:${env_HQADMIN_PASSWORD} -H 'Content-Type: application/json' -H 'Accept: application/json' http://${env_HQSERVER_MAPPED_HOSTNAME}:${env_HQSERVER_MAPPED_HTTP_PORT}/api/informix/${HQAGENT_ID}/agent --data-binary "{'config': { 'repositoryServerId' : ${HQSERVER_ID}, 'database' : 'hqmon' }}" 2>/dev/null`
if [[ ! -z ${REGISTER} ]]
then
break
fi
sleep $SLEEP
done
sudo echo "REGISTER Storage: $REGISTER" >> $HQLOG
}
HQSERVER_ID=$(get_server_id ${env_HQSERVER_MAPPED_HOSTNAME})
if [[ `echo ${env_HQSERVER}|tr /a-z/ /A-Z/` == "START" ]]
then
HQAGENT_ID=$HQSERVER_ID
else
HQLOG ">>> DEBUG: register hqagent with hqserver"
register_hqagent_with_hqserver
fi
create_properties_file
if [[ `echo ${env_HQAGENT}|tr /a-z/ /A-Z/` = "START" ]]
then
HQLOG ">>> DEBUG: hqagent = start"
start_hqagent
set_server_storage
fi