freeswitch-start.sh
1.57 KB
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
#!/bin/bash
proc_name="/usr/local/freeswitch" # 进程名
file_name="/usr/local/freeswitch/log/freeswitch-run.log" # 日志文件
pid=0
proc_num() # 计算进程数
{
num=`ps -ef | grep "$proc_name.*-nc" | grep -v grep | grep -v vim | grep -v "vi " | grep -v tail | grep -v freeswitch-start | wc -l`
return $num
}
proc_id() # 进程号
{
pid=`ps -ef | grep "$proc_name.*-nc" | grep -v grep | grep -v vim | grep -v "vi " | grep -v tail | grep -v freeswitch-start | awk '{print $2}'`
}
proc_num
number=$?
echo $number >> $file_name
if [ $number -eq 0 ] # 判断进程是否存在
then
source /etc/profile && source /root/.bash_profile && source /root/.bashrc
echo $LD_LIBRARY_PATH >> $file_name
export PGPASSWORD=ccc
result=`psql -h 192.168.96.110 -p 5432 -U ccc -d ipcc -c "select 1" | grep "\-\-\-\-"`
echo $result >>$file_name
if [ ${#result} -gt 0 ]
then
ulimit -s 240 -n 99999
/usr/local/freeswitch/bin/freeswitch -nc -nonat -np
else
echo "freeswitch down but postgresql haven't start now" >> $file_name
fi
text=`date`
hn=`hostname`
#mail -s "$hn === $text, freeswitch restart" smithlp_2.0@163.com
proc_id # 获取新进程号
echo ${pid}, `date` >> $file_name # 将新进程号和重启时间记录
fi