datasync.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. export LANG=zh_CN.utf8
  2. export LC_ALL=zh_CN.utf8
  3. #改变工作目录到当前脚本所在路径
  4. if [[ "$0" =~ / ]]; then cd "${0%/*}"; fi
  5. export CWD=`pwd`
  6. if [[ "$MATRIXROOT" == "" ]]; then
  7. export MATRIXROOT="/opt/matrix"
  8. fi
  9. export STDERROR=$MATRIXROOT/var/logs/datasync/out.log
  10. printusage(){
  11. echo "type '${0} stop' to stop it"
  12. echo " or '${0} restart' to restart it"
  13. echo " or '${0} status' to check status"
  14. echo "cat $STDERROR for detail information"
  15. }
  16. #检查正在运行的实例
  17. pid=`ps -ef | grep "$CWD/datasync" | grep -v grep | awk '{print $2}'`
  18. if [[ "$1" == "stop" || "$1" == "restart" ]]; then
  19. if [[ "${pid}" != "" ]]; then
  20. echo "stop last running datasync, pid=${pid}"
  21. kill -9 ${pid}
  22. while [[ "${pid}" != "" ]]; do
  23. sleep 1
  24. pid=`ps -ef | grep "$CWD/datasync" | grep -v grep | awk '{print $2}'`
  25. done
  26. fi
  27. if [[ "$1" == "stop" ]]; then
  28. exit 0
  29. fi
  30. elif [[ "$1" == "status" ]]; then
  31. if [[ "${pid}" == "" ]]; then
  32. echo "datasync is shutdown"
  33. else
  34. echo "datasync is running, pid=${pid}"
  35. fi
  36. exit 0
  37. elif [[ "$1" == "help" ]]; then
  38. printusage
  39. exit 0
  40. elif [[ "${pid}" != "" ]]; then
  41. echo "datasync is running, pid=${pid}"
  42. printusage
  43. exit 0
  44. fi
  45. #开始启动
  46. nohup $CWD/datasync "$@" 1>/dev/null 2>${STDERROR} &
  47. echo "datasync is started"
  48. printusage