freeswitch 啟動服務指令碼(shell)
阿新 • • 發佈:2019-01-03
#!/bin/bash basedir='/usr/local/freeswitch' bindir="$basedir/bin" pidfile="$basedir/run/freeswitch.pid" #Configure Script Variables red='\033[31m' green='\033[32m' end='\033[0m' #Socket Information sk_port='8000' sk_host='172.17.177.80' sk_pass='[email protected]' #Start timeout sum=0 timeout='40' #script function help_(){ echo "Usage: $0 {start|stop|restart|reload|status}" } running(){ echo -e "${green}Service is running PID is `cat $pidfile`${end}" } not_running(){ echo -e "${red}Service is not running${end}" } start_fs(){ if test -f $pidfile;then running exit 1 fi $bindir/freeswitch -nc &> /dev/null echo -n "Start service" while [ $sum -le $timeout ];do let sum++ && sleep 1 $bindir/fs_cli -H $sk_host -P $sk_port -p $sk_pass -x version &> /dev/null if [ $? -eq 0 ];then echo -n -e "${green}Succeeded !!${end}\n" && exit 1 elif [ $? -eq 1 ];then echo -n "." fi if test $sum == $timeout ;then echo -n -e "${red}Failed !!!${end}\n" && exit 1 fi done } stop_fs(){ if test -f $pidfile ;then echo -n "Stop server" $bindir/fs_cli -H $sk_host -P $sk_port -p $sk_pass -x shutdown &> /dev/null while true ;do sleep 1 if [ -f $pidfile ] ;then echo -n "." elif [ $? -eq 1 ];then echo -n -e "${green}Stoped${end}\n" && break fi done else not_running fi } status_fs(){ if test -f $pidfile ;then running else not_running fi } reload_fs(){ if [ -f $pidfile ] ;then $bindir/fs_cli -H $sk_host -P $sk_port -p $sk_pass -x reloadxml | grep -i error &> /dev/null if [ $? -eq 1 ] ;then echo -e "${green}Service reload Succeeded !!!!${end}" else echo -e "${red}Service reload Failed !!!${end}" fi else not_running fi } #Perform initialization check if [ ! -d $basedir ];then echo -e "${red}ERROR:${end} $basedir Directory does not exist" exit 1 elif [ $# == 0 ];then help_ exit 1 fi #Query and start services case $1 in start) start_fs ;; stop) stop_fs ;; status) status_fs ;; reload) reload_fs ;; restart) stop_fs && start_fs ;; *) help_ ;; esac