control 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash
  2. WORKSPACE=$(cd $(dirname $0)/; pwd)
  3. cd $WORKSPACE
  4. mkdir -p var
  5. module=dashboard
  6. app=falcon-$module
  7. pidfile=var/app.pid
  8. logfile=var/app.log
  9. function check_pid() {
  10. if [ -f $pidfile ];then
  11. pid=`cat $pidfile`
  12. if [ -n $pid ]; then
  13. running=`ps -p $pid|grep -v "PID TTY" |wc -l`
  14. return $running
  15. fi
  16. fi
  17. return 0
  18. }
  19. function start() {
  20. source env/bin/activate
  21. hash gunicorn 2>&- || { echo >&2 "I require gunicorn but it's not installed. Aborting."; exit 1; }
  22. check_pid
  23. running=$?
  24. if [ $running -gt 0 ];then
  25. echo -n "$app now is running already, pid="
  26. cat $pidfile
  27. return 1
  28. fi
  29. gunicorn -c gunicorn.conf wsgi:app -D -t 6000 --pid $pidfile --error-logfile $logfile --log-level info
  30. sleep 1
  31. echo -n "$app started..., pid="
  32. cat $pidfile
  33. }
  34. function startfg() {
  35. source env/bin/activate
  36. hash gunicorn 2>&- || { echo >&2 "I require gunicorn but it's not installed. Aborting."; exit 1; }
  37. check_pid
  38. running=$?
  39. if [ $running -gt 0 ];then
  40. echo -n "$app now is running already, pid="
  41. cat $pidfile
  42. return 1
  43. fi
  44. gunicorn -c gunicorn.conf wsgi:app -t 6000 --pid $pidfile --error-logfile $logfile --log-level info
  45. sleep 1
  46. echo -n "$app started..., pid="
  47. cat $pidfile
  48. }
  49. function stop() {
  50. pid=`cat $pidfile`
  51. kill $pid
  52. echo "$app quit..."
  53. }
  54. function kill9() {
  55. pid=`cat $pidfile`
  56. kill -9 $pid
  57. echo "$app stoped..."
  58. }
  59. function restart() {
  60. stop
  61. sleep 2
  62. start
  63. }
  64. function status() {
  65. check_pid
  66. running=$?
  67. if [ $running -gt 0 ];then
  68. echo -n "$app now is running, pid="
  69. cat $pidfile
  70. else
  71. echo "$app is stoped"
  72. fi
  73. }
  74. function tailf() {
  75. tail -f $logfile
  76. }
  77. function show_version() {
  78. cat gitversion
  79. }
  80. function pack() {
  81. git log -1 --pretty=%h > gitversion
  82. file_list="control gunicorn.conf pip_requirements.txt README.md rrd wsgi.py"
  83. echo "...tar $app.tar.gz <= $file_list"
  84. gitversion=`cat gitversion`
  85. tar -zcf $app-$gitversion.tar.gz gitversion $file_list
  86. }
  87. function help() {
  88. echo "$0 start|stop|restart|status|tail|kill9|version|pack"
  89. }
  90. if [ "$1" == "" ]; then
  91. help
  92. elif [ "$1" == "stop" ];then
  93. stop
  94. elif [ "$1" == "kill9" ];then
  95. kill9
  96. elif [ "$1" == "start" ];then
  97. start
  98. elif [ "$1" == "startfg" ];then
  99. startfg
  100. elif [ "$1" == "restart" ];then
  101. restart
  102. elif [ "$1" == "status" ];then
  103. status
  104. elif [ "$1" == "tail" ];then
  105. tailf
  106. elif [ "$1" == "pack" ];then
  107. pack
  108. elif [ "$1" == "version" ];then
  109. show_version
  110. else
  111. help
  112. fi