#!/bin/bash

source activate easy_ml

PATH_APP=$(pwd)

function get_pid() {
  APP_PID=$(ps -ef | grep "python $PATH_APP/app.py" | grep -v grep | awk '{print $2}')
}

function kill_app() {
  if [ -n $APP_PID ]; then
    for v in $APP_PID; do
      echo $(date +%F%n%T) "开始杀死已有进程: $v"
      kill -9 $v
    done
  fi
}

function start_app() {
  echo $(date +%F%n%T) "开始启动 app..."
  PYTHONIOENCODING=utf-8 nohup python $PATH_APP/app.py > $PATH_APP/nohup.out 2>&1 &
  sleep 3
  echo $(tail -50 $PATH_APP/nohup.out)
  echo "启动完成..."
  echo "日志请查看 $PATH_APP/nohup.out"
}

get_pid
kill_app
start_app
