通过该脚本可k快速重启,关闭,php服务,如swoole。
~~~
#!/bin/bash
if [ "$1" = "" -o "$2" = "" ];then
echo "Usage:sh $0 file {start|stop|restart}"
exit
fi
filename="$1"
if [ ! -f $filename ];then
echo "$1 file is not exists"
exit
fi
user="www"
phppath="/usr/local/php/bin/php"
filepath="/dt/hongyuan_socket/"
# start
start() {
process_num=$(ps -ef|grep $filepath$filename|grep -v grep|wc -l)
if [ $process_num != "0" ];then
echo "$filename is running..."
else
echo "starting $filename..."
$(/usr/bin/sudo -u $user $phppath $filepath$filename)
fi
}
# stop
stop() {
process_num=$(ps -ef|grep $filepath$filename|grep -v grep|wc -l)
if [ $process_num != "0" ];then
echo "stoping $filename start"
ps -ef|grep $filepath$filename|grep -v grep|cut -c 9-15|xargs sudo -u $user kill -9
echo "stoping $filename end"
else
echo "$filename is not running..."
fi
}
case "$2" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage:sh $0 $1 {start|stop|restart}"
exit
esac
~~~