安装配置git-webhook

安装mysql, redis

  1. 基础安装

  2. 创建数据库

  1. CREATE DATABASE `git_webhook` /*!40100 DEFAULT CHARACTER SET dec8 */;

安装git-webhook

  1. 安装python2.7

  2. pip安装

  3. 创建配置

  4. 初始化数据库结构

  5. 运行应用

  1. pip install git-webhook
  2. gitwebhook config
  3. gitwebhook createdb
  4. gitwebhook runserver & gitwebhook celery &

配置WebHook

  1. 在网页中获取WebHook的URL

  2. 在github中添加连接并测试(JSON格式)

git保存密码

git config —global credential.helper store

部署脚本

  1. #!/bin/sh
  2. #
  3. # service script
  4. # Check the application status
  5. #
  6. # This function checks if the application is running
  7. check_status() {
  8. # Running ps with some arguments to check if the PID exists
  9. # -C : specifies the command name
  10. # -o : determines how columns must be displayed
  11. # h : hides the data header
  12. # s=`ps -C 'java -jar ~/ushare/target/ushare-0.0.1-SNAPSHOT.jar' -o pid h`
  13. s=`ps -ef | grep -v 'grep' | grep $b | awk '{print $2}'`
  14. echo $s
  15. # In any another case, return 0
  16. if [[ ! -n "$s" ]] ; then
  17. return 0
  18. fi
  19. # If somethig was returned by the ps command, this function returns the PID
  20. return $s
  21. }
  22. # Starts the application
  23. start() {
  24. # At first checks if the application is already started calling the check_status
  25. # function
  26. pid=$(check_status)
  27. if [[ "$pid" -eq "" ]]
  28. then
  29. pid=0
  30. fi
  31. if [ $pid -ne 0 ] ; then
  32. echo "The application is already started"
  33. return
  34. fi
  35. # If the application isn't running, starts it
  36. echo -n "Starting application: "
  37. # Redirects default and error output to a log file
  38. #java -jar /path/to/application.jar >> /path/to/logfile 2>&1 &
  39. java -jar $a >> ~/logs/console.log 2>&1 &
  40. echo "OK"
  41. }
  42. # Stops the application
  43. stop() {
  44. # Like as the start function, checks the application status
  45. pid=$(check_status)
  46. if [[ "$pid" -eq "" ]]
  47. then
  48. pid=0
  49. fi
  50. if [ $pid -eq 0 ] ; then
  51. echo "Application is already stopped"
  52. return
  53. fi
  54. # Kills the application process
  55. echo -n "Stopping application: "
  56. kill -9 $pid &
  57. echo "OK"
  58. }
  59. # Redeploys the application
  60. redeploy() {
  61. stop
  62. currentDir=`pwd`
  63. #echo $currentDir
  64. cd $d
  65. git pull
  66. mvn clean install -DskipTests
  67. cd $currentDir
  68. #echo `pwd`
  69. start
  70. }
  71. # Show the application status
  72. status() {
  73. # The check_status function, again...
  74. pid=$(check_status)
  75. # If the PID was returned means the application is running
  76. if [ "$pid" -ne 0 ] ; then
  77. echo "Application is started: $pid"
  78. else
  79. echo "Application is stopped"
  80. fi
  81. }
  82. # global var
  83. # a is short for application name
  84. # b is short for basename
  85. # d is short for directory
  86. a=`find ~/$2 -name "$2*.jar"`
  87. if [[ ! -n "$a" ]]; then
  88. echo "Application not found"
  89. exit 0
  90. else
  91. echo "Found application at $a"
  92. fi
  93. b=`basename $a`
  94. d="$HOME/$2"
  95. # Main logic, a simple case to call functions
  96. case "$1" in
  97. start)
  98. start
  99. ;;
  100. stop)
  101. stop
  102. ;;
  103. status)
  104. status
  105. ;;
  106. redeploy)
  107. redeploy
  108. ;;
  109. restart)
  110. stop
  111. start
  112. ;;
  113. *)
  114. echo "Usage: $0 {start|stop|restart|reload|status} appname"
  115. exit 1
  116. esac
  117. exit 0