run.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. set +u
  3. set -e
  4. # set -x
  5. # base_dir=$(
  6. # cd "$(dirname "$0")"
  7. # pwd
  8. # )
  9. # cd $base_dir
  10. ROOT=$(cd `dirname $0`/../; pwd)
  11. app_name="CloudflareServer"
  12. app_path="${ROOT}/lib/"
  13. log_path="${ROOT}/logs/${app_name}/"
  14. # ./auto_del_log.sh
  15. function log_warn() {
  16. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  17. local para=$1
  18. echo "[WARN] $date $1" | tee -a "./log/run_log"
  19. }
  20. function log_info() {
  21. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  22. local para=$1
  23. echo "[INFO] $date $1" | tee -a "./log/run_log"
  24. }
  25. function log_err() {
  26. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  27. local para=$1
  28. echo "[ERROR] $date $1" | tee -a "./log/run_log"
  29. }
  30. if ps -auxw | grep "${app_name}" | grep -v grep > /dev/null; then
  31. log_info "${app_name} 已在运行"
  32. elif [[ ! -f "${app_path}${app_name}" ]]; then
  33. log_info "未找到 ${app_name} , 跳过"
  34. else
  35. if [[ ! -d ${log_path} ]]; then
  36. mkdir -p "${log_path}"
  37. fi
  38. log_file="${app_name}_$(date "+%Y-%m-%d-%H:%M:%S").log"
  39. ${app_path}${app_name} &>> "${log_path}${log_file}" &
  40. sleep 1
  41. if grep -E 'cannot|not defined|License does not exist' "${log_path}${log_file}" >> /dev/null; then
  42. log_err "${app_name} 启动遇到问题,请检查 ${log_file}"
  43. else
  44. log_info "${app_name} 启动成功!"
  45. fi
  46. fi