#!/bin/bash
cd $(cd `dirname $0`; pwd)
gost_stop(){
ID=`ps -ef | grep "gost" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
for id in $ID
do
kill -9 $id
echo "killed $id"
done
}
gost_ps(){
ps -e -o "%p  |  %a" | grep "gost" | grep -v "grep" | grep -v "$0" 
}
case "$1" in
"runs")
gost_stop
echo "---------------"
nohup ./gost -L "relay+ws://:89?path=/ws&rbuf=4096&wbuf=4096&compression=false" >/dev/null 2>&1 &
echo "restart server"
gost_ps
;;
"run")
gost_stop
echo "---------------"
if [ ! -n "$2" ] ;then
file="default"
else
file="$2"
fi
bash $file".sh"
echo "restart client"
gost_ps
;;
"stop")
gost_stop
;;
*)
gost_ps
;;
esac