service.sh 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. #
  3. #
  4. SERVICE_HOME="/opt/yunzhi/sgl-v2"
  5. LOG="$SERVICE_HOME/logs/nohup.log"
  6. JAR=$(ls -lt ${SERVICE_HOME}/*.jar|head -n1|rev|cut -d" " -f1|rev)
  7. start() {
  8. PID=`ps -ef|grep marketing-v|grep -v grep|awk '{print $2}'`
  9. if [[ "$PID" != "" ]]; then
  10. echo ""
  11. echo "Service is running. pid=$PID"
  12. echo ""
  13. exit 0
  14. else
  15. echo ""
  16. echo "Start service ..."
  17. echo "FILE: $JAR"
  18. nohup java -jar $JAR > $LOG 2>&1 &
  19. echo "Start finished"
  20. echo "Pls goto $LOG see process status"
  21. echo ""
  22. fi
  23. }
  24. stop() {
  25. echo ""
  26. echo "Stoping service ..."
  27. PID=`ps -ef|grep shigongli-|grep -v grep|awk '{print $2}'`
  28. if [[ "$PID" != "" ]]; then
  29. kill -9 $PID
  30. fi
  31. # 这个延迟不能去掉
  32. sleep 1s
  33. echo "Service is stoped"
  34. echo ""
  35. }
  36. case $1 in
  37. "start")
  38. start ;;
  39. "stop")
  40. stop ;;
  41. "reload"|"restart")
  42. stop
  43. start ;;
  44. *)
  45. echo "Usage: `basename $0` {start|stop|restart}"
  46. exit 1
  47. esac