0%

shell脚本定期重启tomcat

因tomcat项目运作,占用内存过大,无法自动释放,只能定期重启项目解决。

shell脚本如下:

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
#!/bin/sh
. /etc/profile
pid=`ps aux | grep tomcat | grep -v grep | grep new_2bulu | awk '{print $2}'`
dat=`date '+%Y-%m-%d %H:%M:%S'`

echo $dat
echo $pid

if [ -n "$pid" ]
then
{
echo ===========shutdown================
/data/application/nginx_tomcat/new_2bulu/bin/shutdown.sh
sleep 1
pid=`ps aux | grep tomcat | grep -v grep | grep new_2bulu| awk '{print $2}'`
if [ -n "$pid" ]
then
{
sleep 1
echo ========kill tomcat==============
kill -9 $pid
}
fi
sleep 1
echo ===========startup.sh==============
/data/application/nginx_tomcat/new_2bulu/bin/startup.sh
}
else
echo ===========startup.sh==============
/data/application/nginx_tomcat/new_2bulu/bin/startup.sh

fi