forked from CUBRID/cubrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_cubrid
executable file
·235 lines (198 loc) · 3.94 KB
/
start_cubrid
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/sh
# Find out if there is already a server for the given database. If
# not, start one up.
#
# $Revision: 1.7 $
# set -x
RootDir="CUBRID"
usage() {
echo "usage: $0 [-timeout seconds] database" 1>&2
echo " $0 -a : start all databases in this host" 1>&2
exit 1
}
# How long are you willing to wait for the server to come up?
timeout=0
db=
start_all=0
while [ $# -ne 0 ]
do
case $1 in
-timeout)
shift
timeout=$1
;;
-a|-all)
start_all=1
;;
-*)
usage
;;
*)
if [ -z "${db}" ]
then
db=$1
else
usage
fi
;;
esac
shift
done
if [ -z "${db}" -a $start_all -eq 0 ]
then
usage
fi
# Checking prefix
for i in $RootDir
do
seevar="echo \$$i"
#echo $seevar
dir=`eval $seevar`
if [ "$dir" != "" ]
then
title=$dir
fi
seevar="echo \$${i}_DATABASES"
dir=`eval $seevar`
if [ "$dir" != "" ]
then
databases=$dir/databases.txt
fi
if [ "$title" != "" ]
then
break
fi
done
if [ "$title" = "" ]
then
echo "Database Root Directory is not set or is set to NULL"
exit 1
fi
if [ "$databases" = "" ]
then
echo "Environment variable for database location is not set"
exit 1
fi
# Private labeling, ...
commdb=${title}/bin/cub_commdb
master=${title}/bin/cub_master
server=${title}/bin/cub_server
# How long between pings for server status?
interval=3
ping_master() {
if ${commdb} -P 2>&1 | egrep "Could not connect to master server on" >/dev/null
then
return 1
else
return 0
fi
}
ping_server() {
${commdb} -P 2>&1 | egrep " Server ${db}[ ,]" >/dev/null
}
check_process() {
ps -p ${server_pid} > /dev/null
}
start_master() {
if ping_master
then
# The master is up and running.
:
else
# Start the master
${master} </dev/null
time=0
while [ 1 ]
do
# Don't use ${interval} here; master seems to be picky
# about having enough time to get started up, and if
# you hit it too early it tends to go away.
sleep 3
ping_master && break;
if [ ${timeout} -ne 0 ]
then
time=`expr ${time} + 3`
if [ ${time} -gt ${timeout} ]
then
echo "$0: master process is not started after ${time} seconds; giving up" 1>&2
exit 1
fi
fi
done
fi
}
start_a_server() {
if [ -z "${db}" ]
then
return 1
fi
# if OS is the hp-ux, set LD_PRELOAD variable.
ostype=`eval uname`
if [ "$ostype" = "HP-UX" ]
then
/usr/bin/hp-pa
if [ $? = 0 ]
then
LD_PRELOAD=libjvm.sl
else
LD_PRELOAD=libjvm.so
fi
export LD_PRELOAD
fi
# Launch the server, and then sleep for a moment while it starts up.
echo "Starting server for database $db ..."
${server} ${db} &
server_pid=$!
trap 'kill ${server_pid}; exit' 2 3 # SIGINT, SIGQUIT
sleep ${interval}
# Now start a dance and wait for the server to stabilize. If it
# hasn't shown up in some decent interval, give up and notify the user
# of the failure.
time=${interval}
while [ 1 ]
do
if ping_server
then
# It's ready to go...
return 0
elif ping_master
then
# Master is still cooking, but the server isn't ready
# yet. Give up if we've already waited long enough;
# otherwise, wait some more.
if [ ${timeout} -ne 0 ]
then
time=`expr ${time} + ${interval}`
if [ ${time} -gt ${timeout} ]
then
echo "$0: server is not accepting connections after ${time} seconds; giving up" 1>&2
exit 1
fi
fi
if check_process
then
:
else
exit 1
fi
sleep ${interval}
else
# Some disaster has befallen us: the master appears to
# have gone away during startup.
echo "$0: master process has crashed during ${db} startup; giving up" 1>&2
kill -9 ${server_pid}
exit 1
fi
done
}
echo "This may take a long time depending on the amount of recovery works to do."
start_master
if [ $start_all -eq 1 ]
then
for db in `cut -d\ -f1 $databases`
do
start_a_server
done
else
start_a_server
fi