export LEVEL="error"
EXTERNAL="192.168.0.224"
ETCD="http://127.0.0.1:2379"
REDIS_HOST="127.0.0.1"
REDIS_PORT="6379"
MYSQL_HOST="127.0.0.1"
MYSQL_PORT="3306"
MYSQL_DATABASE_NAME="iot-hub"
MYSQL_USERNAME="root"
MYSQL_PASSWORD="zJv4DwFL6G2MgSvP@"
RABBIT_URI="amqp://guest:guest@127.0.0.1:5672"
BIN_PATH="/opt/go/bin"

for name in httpaccess bin/registry apiprovider devicemanager controller mqttaccess knowoapi fileaccess coapaccess
do
  p_id=`ps -ef| grep "$name" |grep -v "grep" | awk '{print $2}'`
  if [ -z "$p_id" ];
  then
    echo "[$name not found]"
  else
    kill -9 $p_id
    echo "killed $name"
  fi
done
echo "启动服务进程"
nohup $BIN_PATH/httpaccess -etcd $ETCD -httphost external:18100 -external $EXTERNAL -redishost $REDIS_HOST:$REDIS_PORT -loglevel $LEVEL > httpaccess.out 2>&1 &
nohup $BIN_PATH/registry -etcd $ETCD -rpchost internal:18101 -aeskey ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP -dbhost $MYSQL_HOST -dbname $MYSQL_DATABASE_NAME -dbport $MYSQL_PORT -dbuser $MYSQL_USERNAME -dbpass $MYSQL_PASSWORD -loglevel $LEVEL > registry.out 2>&1 &
nohup $BIN_PATH/apiprovider -etcd $ETCD -loglevel $LEVEL -httphost external:18102 -external $EXTERNAL > apiprovider.out 2>&1 &
nohup $BIN_PATH/devicemanager -etcd $ETCD -loglevel $LEVEL -rpchost internal:18103 -redishost $REDIS_HOST:$REDIS_PORT >devicemanager.out 2>&1 &
nohup $BIN_PATH/controller -etcd $ETCD -rabbithost $RABBIT_URI -loglevel $LEVEL -rpchost internal:18104 > controller.out 2>&1 &
nohup $BIN_PATH/mqttaccess -etcd $ETCD -loglevel $LEVEL -rpchost internal:18105 -tcphost external:18106 -external $EXTERNAL > mqttaccess.out 2>&1 &
nohup $BIN_PATH/knowoapi -etcd $ETCD -loglevel $LEVEL  -httphost external:18107 -dbhost $MYSQL_HOST -dbname $MYSQL_DATABASE_NAME -dbport $MYSQL_PORT -dbuser $MYSQL_USERNAME -dbpass $MYSQL_PASSWORD -aeskey ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP -external $EXTERNAL> konowapi.out 2>&1 &
nohup $BIN_PATH/fileaccess -etcd $ETCD -loglevel $LEVEL  -rpchost internal:18108 -httphost internal:18109 > fileaccess.out 2>&1 &