blob: 385a424bd5e3d971a9de21e0c3b99d38f078f087 (
plain)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
#!/bin/sh
# -----------------------------------------------------------------------------
# Start/Stop Script for the NMS Client
#
# Environment Variable Prequisites
#
# NMSCLEINT_HOME May point at your Catalina "build" directory.
#
# NMSCLIENT_TASKDIR (Optional) Directory path location of taskresult directory
# Defaults to %NMSCLIENT_HOME%/task.
#
# NMSCLIENT_TMPDIR (Optional) Directory path location of temporary directory
# the JVM should use (java.io.tmpdir). Defaults to
# $NMSCLIENT_HOME/temp.
#
# JAVA_HOME Must point at your Java Development Kit installation.
# Required to run the with the "debug" argument.
#
# -----------------------------------------------------------------------------
# resolve links - $0 may be a softlink
PRG="$0"
if [ -f /etc/redhat-release ]; then
OS_TYPE=`cat /etc/redhat-release`
else
islsb=`which lsb_release | wc -l`
if [ "$islsb" != "0" ]; then
OS_TYPE=$( lsb_release -d| cut -d: -f2| cut -f2 )
else
OS_TYPE=`uname -a | awk '{print $1" "$2" "$3}'`
fi
fi
echo $OS_TYPE
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
# Get standard environment variables
PRGDIR=`dirname "$PRG"`
# Only set NMSCLEINT_HOME if not already set
[ -z "$NMSCLEINT_HOME" ] && NMSCLEINT_HOME=`cd "$PRGDIR/.." ; pwd`
cd "$NMSCLEINT_HOME"/shell
if [ -z "$NMSCLIENT_TMPDIR" ] ; then
NMSCLIENT_TMPDIR="$NMSCLEINT_HOME"/temp
fi
if [ ! -d $NMSCLIENT_TMPDIR ]
then
mkdir $NMSCLIENT_TMPDIR
fi
if [ -n "$4" ]; then
NMSCLIENT_TASKDIR=`dirname "$4"`
fi
if [ -z "$NMSCLIENT_TASKDIR" ] ; then
NMSCLIENT_TASKDIR="$NMSCLEINT_HOME"/task
fi
# -------- check jdk
# check nmsjdk
NMS_HOME=`cd "$NMSCLEINT_HOME/.." ; pwd`
cd "$NMSCLEINT_HOME"/shell
NMS_JDK="$NMS_HOME"/nmsjdk
if [ ! -e "$NMS_JDK" ]
then
echo "$NMS_JDK not exist"
exit 0
fi
# check java -version
javaversion=`$NMS_JDK/bin/java -version 2>&1|grep "java version"`
if [ ! -n "$javaversion" ]
then
echo "$NMS_JDK cannot use, please install"
exit 0
fi
# -------- set jdk path
export JAVA_HOME=$NMS_JDK
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$PATH
temp=$CLASSPATH
#setting libs path
libs="$NMSCLEINT_HOME"/lib/*
append(){
temp=$temp":"$1
}
for file in $libs; do
append $file
done
jars="$NMSCLEINT_HOME"/bin/*
for file in $jars; do
append $file
done
export NC_CLASSPATH=$temp:.:$NMSCLEINT_HOME/conf
export LD_LIBRARY_PATH=$NMSCLEINT_HOME/lib
export LANG=zh_CN.UTF-8
# Bugzilla 37848: When no TTY is available, don't output to console
have_tty=0
if [ "`tty`" != "not a tty" ]; then
have_tty=1
fi
# ----- Execute The Requested Command -----------------------------------------
# Bugzilla 37848: only output this if we have a TTY
if [ $have_tty -eq 1 ]; then
echo "Using NMSCLEINT_HOME: $NMSCLEINT_HOME"
echo "Using NMSCLIENT_TMPDIR: $NMSCLIENT_TMPDIR"
echo "Using JAVA_HOME: $JAVA_HOME"
echo "Using CLASSPATH: $NC_CLASSPATH"
fi
# ---- get jvm param
jvmconf_file=$NMSCLEINT_HOME"/conf/jvm.conf"
if [ -f $jvmconf_file ]
then
#sed -n '/Xmx=/p' $jvmconf_file | sed 's/Xmx=//g'
XmsOpt=`sed -n '/-Xms/p' $jvmconf_file`
XmxOpt=`sed -n '/-Xmx/p' $jvmconf_file`
JAVA_OPTS="$XmsOpt $XmxOpt -XX:+UseParNewGC"
else
JAVA_OPTS="-Xms64m -Xmx128m -XX:+UseParNewGC"
fi
program="com.nis.nmsclient.NmsClient"
name="NmsClient"
proc_id=
# handler agent upgrade result
handleTask()
{
if [ -d "$NMSCLIENT_TASKDIR" ]
then
cd $NMSCLIENT_TASKDIR
for i in *.upgrade;do mv "$i" "${i%.upgrade}.result";done >/dev/null 2>&1
cd "$NMSCLEINT_HOME"/shell
fi
}
writePid()
{
ps aux|grep java|grep $program|grep -v grep|awk '{print $2}' > $NMSCLIENT_TMPDIR/agentPid.temp
}
getPid()
{
unset proc_id
proc_id=`ps aux|grep java|grep $program|grep -v grep|awk '{print $2}'`
}
shouhu_proc="$NMSCLEINT_HOME"/shell/nmsclient_shouhu.sh
stopShouhuProc()
{
shouhu_proc_id=`ps aux|grep $shouhu_proc|grep -v grep|awk '{print $2}'`
if [ -n "$shouhu_proc_id" ]
then
echo "kill shouhu process ....."
kill -9 $shouhu_proc_id
fi
}
startShouhuProc()
{
shouhu_proc_id=`ps aux|grep $shouhu_proc|grep -v grep|awk '{print $2}'`
if [ ! -n "$shouhu_proc_id" ]
then
echo "start shouhu process ....."
nohup $shouhu_proc $NMSCLIENT_TASKDIR >/dev/null &
fi
}
if [ "$1" = "start" ] ; then
getPid
if [ -n "$proc_id" ]
then
echo "$name already running......"
else
nohup java $JAVA_OPTS -classpath $NC_CLASSPATH $program >/dev/null &
sleep 3
getPid
if [ -n "$proc_id" ]
then
echo "$name start success!!!!!"
writePid
else
echo "$name start error!!!!!"
fi
handleTask
fi
elif [ "$1" = "stop" ]; then
getPid
if [ -n "$proc_id" ]
then
stopShouhuProc
sleep 1
echo "$name is start, now kill......"
kill -9 $proc_id
writePid
echo "$name kill ok !!!!!!!!!!!!!"
else
echo "$name is not start!!!!!!!!!!!"
fi
elif [ "$1" = "restart" ] ; then
getPid
if [ -n "$proc_id" ]
then
echo "$name is start, now restart......"
stopShouhuProc
sleep 1
startShouhuProc
kill -9 $proc_id
getPid
if [ -n "$proc_id" ]
then
echo "$name stop error!!!!!!!!!!"
handleTask
exit 1
fi
else
echo "$name is not start, now start......"
fi
copyError=
if [ -n "$2" ] ; then
srcFile=$2
updateFile=/dev/null
if [ -d "$2" ]; then
srcFile="$2"/*
fi
if [ -n "$4" ]; then
updateFile=$4
fi
if [ -n "$3" ]; then
unalias cp >/dev/null 2>&1
cp -rvf $srcFile $3 >>$updateFile 2>&1 ||copyError=1
fi
rm -rf $2 >/dev/null 2>&1
fi
if [ -n "$copyError" ]
then
#----copy error
handleTask
else
#--------copy right, start proc
nohup java $JAVA_OPTS -classpath $NC_CLASSPATH $program >/dev/null &
sleep 3
getPid
if [ -n "$proc_id" ]
then
writePid
else
echo "$name restart error!!!!!!!!!!"
handleTask
fi
fi
else
echo "Usage: nmsagent.sh ( commands ... )"
echo "commands:"
echo " start Start $name in a separate window"
echo " restart ReStart $name in a separate window"
echo " stop Stop $name"
fi
|