-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmq.sh
121 lines (107 loc) · 3.08 KB
/
mq.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
#!/bin/bash
# -*- mode: sh -*-
# © Copyright IBM Corporation 2015, 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
stop()
{
endmqm $MQ_QMGR_NAME
}
config()
{
: ${MQ_QMGR_NAME?"ERROR: You need to set the MQ_QMGR_NAME environment variable"}
: ${MQ_QUEUES?"ERROR: You need to set the MQ_QUEUES environment variable"}
# Populate and update the contents of /var/mqm - this is needed for
# bind-mounted volumes, and also to migrate data from previous versions of MQ
/opt/mqm/bin/amqicdir -i -f
ls -l /var/mqm
source /opt/mqm/bin/setmqenv -s
echo "----------------------------------------"
dspmqver
echo "----------------------------------------"
QMGR_EXISTS=`dspmq | grep ${MQ_QMGR_NAME} > /dev/null ; echo $?`
if [ ${QMGR_EXISTS} -ne 0 ]; then
echo "Checking filesystem..."
amqmfsck /var/mqm
echo "----------------------------------------"
crtmqm -q ${MQ_QMGR_NAME} || true
if [ ${MQ_QMGR_CMDLEVEL+x} ]; then
# Enables the specified command level, then stops the queue manager
strmqm -e CMDLEVEL=${MQ_QMGR_CMDLEVEL} || true
fi
echo "----------------------------------------"
fi
strmqm ${MQ_QMGR_NAME}
if [ ${QMGR_EXISTS} -ne 0 ]; then
echo "----------------------------------------"
if [ -f /etc/mqm/listener.mqsc ]; then
runmqsc ${MQ_QMGR_NAME} < /etc/mqm/listener.mqsc
fi
if [ -f /etc/mqm/config.mqsc ]; then
runmqsc ${MQ_QMGR_NAME} < /etc/mqm/config.mqsc
fi
fi
echo "----------------------------------------"
}
state()
{
dspmq -n -m ${MQ_QMGR_NAME} | awk -F '[()]' '{ print $4 }'
}
monitor()
{
# Loop until "dspmq" says the queue manager is running
until [ "`state`" == "RUNNING" ]; do
sleep 1
done
dspmq
# Loop until "dspmq" says the queue manager is not running any more
until [ "`state`" != "RUNNING" ]; do
sleep 5
done
# Wait until queue manager has ended before exiting
while true; do
STATE=`state`
case "$STATE" in
ENDED*) break;;
*) ;;
esac
sleep 1
done
dspmq
}
create_queue()
{
if [ ! -f /etc/mqm/queues.mqsc ]; then
echo "Create queue"
setmqaut -m ${MQ_QMGR_NAME} -t qmgr -g mqm +all
# queues=$(echo ${MQ_QUEUES} | tr ";" "\n")
IFS=";" read -ra ADDR <<< "${MQ_QUEUES}"
for i in "${ADDR[@]}"; do
echo "define qlocal($i)" >> /etc/mqm/queues.mqsc
# process "$i"
done
echo ${MQ_QUEUES}
cat /etc/mqm/queues.mqsc
if [ -f /etc/mqm/queues.mqsc ]; then
runmqsc ${MQ_QMGR_NAME} < /etc/mqm/queues.mqsc
echo "create queues"
cat /etc/mqm/queues.mqsc
fi
fi
}
#mq-license-check.sh
config
create_queue
trap stop SIGTERM SIGINT
monitor