run.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. # parameter set
  39. log_path="./log/watch-daemon/"
  40. # extra function
  41. if [[ ! -d "$base_dir/log" ]]; then
  42. echo "log文件夹不存在,创建log文件夹" && mkdir "./log"
  43. fi
  44. # preparation check
  45. if [[ ! -f "$base_dir/watch-daemon" ]]; then
  46. log_err "文件夹中缺少watch-daemon(主程序),无法运行" && exit 1
  47. fi
  48. if [[ ! -x "$base_dir/watch-daemon" ]]; then
  49. log_err "watch-daemon无可执行权限,无法运行。请使用chmod" && exit 1
  50. fi
  51. ###################################################################################################
  52. if ps -auxc | grep "watch-daemon" | grep -v grep > /dev/null; then
  53. log_info "watch-daemon已在运行"
  54. else
  55. if [[ ! -d $log_path ]]; then
  56. mkdir "$log_path"
  57. fi
  58. log_file="watch-daemon_$(date "+%Y-%m-%d-%H:%M:%S").log"
  59. ./watch-daemon --config-file=$base_dir/config/config.xml &> "${log_path}${log_file}" &
  60. fi