This repository has been archived by the owner on Apr 7, 2022. It is now read-only.
/
tango_wca.in
221 lines (189 loc) · 3.96 KB
/
tango_wca.in
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
#!@SHELL@
#
# script to start TANGO database
#
TANGO_DB_PORT=10000
#
# Internal functions
#
checkmysql() {
NB=`$PS -ef | $GREP mysqld| $GREP -v $GREP | wc -l`
export NB
if [ $NB = 0 ]
then
return=1
export return
else
return=0
export return
fi
}
findproc() {
pid=`$PS -e | $GREP "$1" | $SED -e 's/^ *//' -e 's/ .*//'`
}
checkdatabaseds() {
NB=`$PS -ef | $GREP -i databaseds | $GREP -v $GREP | wc -l`
export NB
if [ $NB = 0 ]
then
return=1
else
return=0
fi
}
startproc() {
findproc $1
if [ "$pid" != "" ];
then
${ECHO} "$1 Server is already running"
'date' >> ${TANGO_LOG}
${ECHO} "$1 Server is already running" >> ${TANGO_LOG}
else
$2 &
${ECHO} "Starting Tango $1 Server"
'date' >> ${TANGO_LOG}
${ECHO} "Starting Tango $1 Server" >> ${TANGO_LOG}
# wait for a while before checking status
sleep 3
findproc $1
if [ "$pid" = "" ];
then
${ECHO} "Failed to start Tango $1 server"
'date' >> ${TANGO_LOG}
${ECHO} "Failed to start Tango $1 server" >> ${TANGO_LOG}
exit 1
fi
${ECHO} "$rc_done"
fi
}
killproc() {
pid=`$PS -e | $GREP "$1" | $SED -e 's/^ *//' -e 's/ .*//'`
[ "$pid" != "" ] && kill -9 $pid
}
#
# Check the platform used
#
OS=`uname -s`
#
# Settings common to all platforms
#
SERVERBINHOME=@prefix@/bin
LD_LIBRARY_PATH=@prefix@/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
#
# Platform specific settings
#
case "${OS}" in
"Linux")
PS="/bin/ps"
ECHO="/bin/echo -e"
GREP="grep"
SED="sed"
TANGO_LOG="/tmp/tango.log"
;;
"SunOS")
rc_failed=" failed"
rc_done=" OK"
PS="/bin/ps"
ECHO="/usr/ucb/echo"
GREP="grep"
SED="sed"
TANGO_LOG=/tmp/tango.log
;;
"HP-UX")
test -f /etc/rc.config && . /etc/rc.config
PS="/usr/bin/ps"
ECHO="/bin/echo "
GREP="/usr/bin/grep"
SED="/usr/bin/sed"
TANGO_LOG="/tmp/tango.log"
;;
*)
echo "Not supporting operating system: " ${OS}
exit 1
esac
#
# Main part
#
case "$1" in
start)
${ECHO} "Starting TANGO database"
# first check the MySQL server
checkmysql
export return
if [ ${return} = 1 ]
then
sleep 3
checkmysql
if [ ${return} = 1 ]
then
# MySQL is not there, we can't start Tango db
${ECHO} "PLEASE Start MySQL server\n"
'date' >> ${TANGO_LOG}
${ECHO} "Failed to start Tango database server" >> ${TANGO_LOG}
${ECHO} "MySQL is not running !!!" >> ${TANGO_LOG}
${ECHO} "$rc_failed"
exit 1
fi
fi
# Start the database device server if needed
startproc DataBase "${SERVERBINHOME}/DataBaseds 2 -ORBendPoint giop:tcp::$TANGO_DB_PORT"
# Start the tango control access server if needed
export SUPER_TANGO=true
startproc TangoAccessC "${SERVERBINHOME}/TangoAccessControl 1"
startproc TangoRestSer "${SERVERBINHOME}/TangoRestServer rest"
;;
stop)
${ECHO} "Shutting down TANGO control system"
# first shutdown the rest-server
'date' >> ${TANGO_LOG}
${ECHO} "Stopping TangoRestServer" >> ${TANGO_LOG}
killproc TangoRestSer
# second shutdown the control access device server
'date' >> ${TANGO_LOG}
${ECHO} "Stopping TANGO Control Access Server" >> ${TANGO_LOG}
killproc TangoAccessC
# then shutdown the database device server
'date' >> ${TANGO_LOG}
${ECHO} "Stopping TANGO Database Server" >> ${TANGO_LOG}
killproc DataBaseds
${ECHO} "$rc_done"
;;
restart)
$0 stop && sleep 2 && $0 start
;;
status)
checkmysql
if [ ${return} = 0 ]
then
${ECHO} "MySQL OK"
else
${ECHO} "MySQL : No process"
fi
findproc DataBase
if [ "$pid" != "" ];
then
${ECHO} "TANGO Database server OK"
else
${ECHO} "TANGO Database server : No process"
fi
findproc TangoAccessC
if [ "$pid" != "" ];
then
${ECHO} "TANGO Access Control server OK"
else
${ECHO} "TANGO Access Control server : No process"
fi
findproc TangoRestSer
if [ "$pid" != "" ];
then
${ECHO} "TangoRestServer server OK"
else
${ECHO} "TangoRestServer server : No process"
fi
;;
*)
${ECHO} "Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit 0