run.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. echo $base_dir
  11. # ./auto_del_log.sh
  12. function log_warn() {
  13. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  14. local para=$1
  15. echo "[WARN] $date $1" | tee -a "./log/run_log"
  16. }
  17. function log_info() {
  18. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  19. local para=$1
  20. echo "[INFO] $date $1" | tee -a "./log/run_log"
  21. }
  22. function log_err() {
  23. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  24. local para=$1
  25. echo "[ERROR] $date $1" | tee -a "./log/run_log"
  26. }
  27. ulimit -n 100000
  28. if [[ $1 != "no_logo" ]]; then
  29. cat << 'LOGO'
  30. ###############################################################
  31. 配置文件:
  32. ./config/
  33. ###############################################################
  34. LOGO
  35. else
  36. shift 1
  37. fi
  38. BINARY_NAME="nsq-server"
  39. # parameter set
  40. log_path="./log/nsq-server/"
  41. # extra function
  42. if [[ ! -d "$base_dir/log" ]]; then
  43. echo "log文件夹不存在,创建log文件夹" && mkdir "./log"
  44. fi
  45. ###################################################################################################
  46. if pgrep -x "$BINARY_NAME"; then
  47. log_info "nsq-server已在运行"
  48. else
  49. if [[ ! -d $log_path ]]; then
  50. mkdir "$log_path"
  51. fi
  52. log_file="nsq-server_$(date "+%Y-%m-%d-%H:%M:%S").log"
  53. # ----- Start run -----
  54. echo "正在启动 nsq-server..."
  55. ./launcher.sh &> "${log_path}${log_file}"
  56. # ----- End run -----
  57. fi