shell 多程序快速启停脚本(参数可任意叠加)

#!/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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

璐程风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值