#!/bin/bash
# 2019.4.9 lcf
#-----------------命令路径
swoole="/usr/local/php/bin/php /data/att swoole/tcp"
queue="/usr/local/php/bin/php /data/att queue/list/run"
websocket="/usr/local/php/bin/php /data/att swoole/index"
#-----------------获取进程对应进程ID号
swoole_id=`ss -anplut | grep 9501 | awk -F',' '{print $2}' | awk -F '=' '{print $2}'`
queue_id=`ps aux | grep "att \queue" | awk '{print $2}'`
websocket_id=`ss -anplut | grep 9502 | awk -F',' '{print $2}' | awk -F '=' '{print $2}'`
#-----------------判断创建日志文件
if [ ! -d "/var/log/swoole.log" ];then
touch /var/log/swoole.log
fi
if [ ! -d "/var/log/queue.log" ];then
touch /var/log/queue.log
fi
if [ ! -d "/var/log/queue.log" ];then
touch /var/log/websocket.log
fi
#-----------------重启、启动、停止服务
all=($*)
if [ "$1" == "restart" ];then
for s in ${all[@]}
do
if [ $s == "-s" -o $s == "-q" -o $s == "-w" ];then
if [ $s == "-s" ];then
echo "----------> $(date) 服务重新启动...." &>> /var/log/swoole.log
kill $swoole_id &> /dev/null
$swoole &>> /var/log/swoole.log &
echo "swoole 进程已成功重启"
elif [ $s == "-q" ];then
echo "----------> $(date) 服务重新启动...." &>> /var/log/queue.log
kill $queue_id &> /dev/null
echo "----------> $(date) 服务重新启动...." &>> /var/log/websocket.log
$websocket &>> /var/log/queue.log &
echo "queue 进程已成功重启"
elif [ $s == "-w" ];then
kill $websocket_id &> /dev/null
echo "----------> $(date) 服务重新启动...." &>> /var/log/websocket.log
$websocket &>> /var/log/websocket.log &
echo "websocket 进程已成功重启"
fi
fi
done
elif [ "$1" == "stop" ];then
for s in ${all[@]}
do
if [ $s == "-s" -o $s == "-q" -o $s == "-w" ];then
if [ $s == "-s" ];then
kill $swoole_id &> /dev/null
echo "swoole 程序成功关闭"
elif [ $s == "-q" ];then
kill $queue_id &> /dev/null
echo "queue 程序成功关闭"
elif [ $s == "-w" ];then
kill $websocket_id &> /dev/null
echo "websocket 程序成功关闭"
fi
fi
done
elif [ "$1" == "start" ];then
for s in ${all[@]}
do
if [ $s == "-s" ];then
if [ ! $swoole_id ];then
$swoole &>> /var/log/swoole.log &
echo "swoole 启动成功."
else
echo "----------> $(date) swooole服务启动...." &>> /var/log/swoole.log
echo "swoole已经启动了,进程id是:$swoole_id"
fi
elif [ $s == "-q" ];then
if [ ! $queue_id ] && [[ $s == "-q" ]];then
echo "----------> $(date) queue服务启动...." &>> /var/log/queue.log
$queue &>> /var/log/queue.log &
echo "squeue 启动成功."
else
echo "queue已经启动了,进程id是:$queue_id"
fi
elif [ $s == "-w" ];then
if [ ! $websocket_id ] && [[ $s == "-w" ]];then
echo "----------> $(date) queue服务启动...." &>> /var/log/websocket.log
$websocket &>> /var/log/websocket.log &
echo "websocket 启动成功."
else
echo "websocket已经启动了,进程id是:$queue_id"
fi
fi
done
else
echo -e "可用参数[start/stop/restart] -q (表示queue程序) -s (表示swoole程序) -w (表示websocket) \n示例:gxc_link start -q -s -w 或 gxc_link restart -q -w (参数自由叠加)"
fi