把下面的IM_SERVER_PATH改成你自己的im_server的目录,然后把这段脚本保存为tt.sh
开启TT服务,sh tt.sh start,关闭TT服务,sh tt.sh stop即可。
#!/bin/bash
this is a start scripts for TeamTalk
author: eason
date: 11/19/2015
setup im-server 下方的IM_SERVER_PATH请替换为您的TT安装路径
IM_SERVER=im-server-*
IM_SERVER_PATH=/home/eason/Teamtalk2/source/TeamTalk-master/auto_setup/im_server
FILE_SERVER=file_server
LOGIN_SERVER=login_server
MSG_SERVER=msg_server
ROUTE_SERVER=route_server
MSFS_SERVER=msfs
HTTP_MSG_SERVER=http_msg_server
PUSH_SERVER=push_server
DB_PROXY_SERVER=db_proxy_server
print_hello(){
echo "==========================================="
echo "start all servers for TeamTalk"
echo "==========================================="
}
run_nginx() {
ps -ef | grep -v 'grep' | grep nginx
if [ $? -eq 0 ]; then
echo "Warning: nginx is running."
return 0
fi
/etc/init.d/nginx start
service nginx start
ps -ef | grep -v 'grep' | grep nginx
if [ $? -eq 0 ]; then
echo "run nginx successed."
else
echo "Error: run nginx failed."
exit 1
fi
}
stop_nginx() {
ps -ef | grep -v 'grep' | grep nginx
if [ $? -eq 0 ]; then
echo "nginx is running.start to stop..."
return 0
fi
/etc/init.d/nginx stop
service nginx stop
ps -ef | grep -v 'grep' | grep nginx
if [ $? -eq 0 ]; then
echo "stop nginx successed."
else
echo "Error: stop nginx failed."
exit 1
fi
}
run_phpfpm() {
ps -ef | grep -v 'grep' | grep php-fpm
if [ $? -eq 0 ]; then
echo "warning: php-fpm is running."
return 0
fi
cd /usr/local/php5/sbin
./php-fpm -c /usr/local/php5/etc/php.ini -y /usr/local/php5/etc/php-fpm.conf
/etc/init.d/php-fpm start
ps -ef | grep -v 'grep' | grep php-fpm
if [ $? -eq 0 ]; then
echo "run php-fpm successed."
else
echo "Error: run php-fpm failed."
exit 1
fi
}
stop_phpfpm() {
ps -ef | grep -v 'grep' | grep php-fpm
if [ $? -eq 0 ]; then
echo "warning: php-fpm is running.start to stop..."
fi
/etc/init.d/php-fpm stop
killall php-fpm
if [ $? -eq 0 ]; then
echo "stop php-fpm successed."
else
echo "Error: stop php-fpm failed."
exit 1
fi
}
run_mysql() {
PROCESS=$(pgrep mysql)
if [ -z "$PROCESS" ]; then
echo "no mysql is running..."
#service mysql start
/etc/init.d/mysql start
if [ $? -eq 0 ]; then
echo "start mysql successed."
else
echo "Error: start mysql failed."
return 1
fi
else
echo "Warning: mysql is running"
fi
#set pwd
mysqladmin -u root password $MYSQL_PASSWORD
if [ $? -eq 0 ]; then
echo "set percona root password successed."
else
echo "Error: set percona root password failed."
return 1
fi
#create database
mysql -u root -p$MYSQL_PASSWORD < macim.sql
if [ $? -eq 0 ]; then
echo "run macim.sql successed."
cd ..
else
echo "Error: run macim.sql failed."
cd ..
return 1
fi
}
stop_mysql() {
PROCESS=$(pgrep mysql)
if [ -z "$PROCESS" ]; then
echo "Warning: no mysql is running"
else
/etc/init.d/mysql stop
service mysql stop
if [ $? -eq 0 ]; then
echo "stop mysql successed."
return 0
else
echo "Error: stop mysql failed."
return 1
fi
fi
}
run_redis() {
#eason add to check redis is running or not
PROCESS=$(pgrep redis)
if [ -z "$PROCESS" ]; then
echo "no redis is running,start run redis..."
else
echo "Warning: redis is running"
return 0
fi
/etc/init.d/redis start
/usr/local/bin/redis-server /usr/local/etc/redis.conf
ps -ef | grep -v 'grep' | grep redis-server
if [ $? -eq 0 ]; then
echo "run redis successed."
else
echo "Error: run redis failed."
exit 1
fi
}
stop_redis() {
#eason add to check redis is running or not
PROCESS=$(pgrep redis)
if [ -z "$PROCESS" ]; then
echo "no redis is running,no need to stop redis."
return 0
else
echo "redis is running,start to stop redis..."
fi
/usr/local/bin/redis-server /usr/local/etc/redis.conf
ps -ef | grep -v 'grep' | grep redis-server
/etc/init.d/redis stop
pkill -9 redis
if [ $? -eq 0 ]; then
echo "stop redis successed."
else
echo "Error: stop redis failed."
exit 1
fi
}
run_imserver() {
cd $IM_SERVER_PATH/$IM_SERVER
./restart.sh $DB_PROXY_SERVER
./restart.sh $ROUTE_SERVER
./restart.sh $FILE_SERVER
./restart.sh $MSFS_SERVER
./restart.sh $LOGIN_SERVER
./restart.sh $MSG_SERVER
./restart.sh $HTTP_MSG_SERVER
./restart.sh $PUSH_SERVER
}
stop_imserver() {
#these server no need to stop manual
pkill -9 $DB_PROXY_SERVER
pkill -9 $ROUTE_SERVER
pkill -9 $FILE_SERVER
pkill -9 $MSFS_SERVER
pkill -9 $LOGIN_SERVER
pkill -9 $MSG_SERVER
pkill -9 $HTTP_MSG_SERVER
pkill -9 $PUSH_SERVER
}
print_help() {
echo "Usage: "
echo " $0 run --- run scripts to start all servers"
}
case $1 in
start)
print_hello
run_redis
run_mysql
run_nginx
run_phpfpm
run_imserver
;;
stop)
print_hello
stop_imserver
stop_phpfpm
stop_nginx
stop_mysql
stop_redis
;;
*)
print_help
;;
esac