写了个shell控制swoole服务器的启动、停止、重启,这样不必每次定位到swoole的目录中执行一些操作。
创建shell脚本文件:
nano swoole.sh
shell内容如下:
#!/bin/bash
if [ $# -ne 1 ]; then
echo "error: there can only be one parameter"
exit 1
fi
killing(){
kill `lsof -t -i:3848`、
}
if [ "$1" = "start" -o "$1" = "restart" ]; then
SWOOLE_TCP_SERVER=/www/system/libraries/location/entrance.php
if [ ! -f $SWOOLE_TCP_SERVER ]; then
echo "error: swoole tcp server does not exists"
exit 1
fi
if [ "$1" = "restart" ];
then
killing
sleep 1
fi
php8.0 $SWOOLE_TCP_SERVER
exit 0
elif [ "$1" = "stop" ]; then
killing
exit 0
else
echo "usage: start|restart|stop"
exit 1
fi
使用方法:
./swoole.sh start #启动
./swoole.sh restart #重启
./swoole.sh stop #停止