control 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 stop() {
  35. pid=`cat $pidfile`
  36. kill $pid
  37. echo "$app quit..."
  38. }
  39. function kill9() {
  40. pid=`cat $pidfile`
  41. kill -9 $pid
  42. echo "$app stoped..."
  43. }
  44. function restart() {
  45. stop
  46. sleep 2
  47. start
  48. }
  49. function status() {
  50. check_pid
  51. running=$?
  52. if [ $running -gt 0 ];then
  53. echo -n "$app now is running, pid="
  54. cat $pidfile
  55. else
  56. echo "$app is stoped"
  57. fi
  58. }
  59. function tailf() {
  60. tail -f $logfile
  61. }
  62. function show_version() {
  63. cat gitversion
  64. }
  65. function pack() {
  66. git log -1 --pretty=%h > gitversion
  67. file_list="control gunicorn.conf pip_requirements.txt README.md rrd wsgi.py"
  68. echo "...tar $app.tar.gz <= $file_list"
  69. gitversion=`cat gitversion`
  70. tar -zcf $app-$gitversion.tar.gz gitversion $file_list
  71. }
  72. function help() {
  73. echo "$0 start|stop|restart|status|tail|kill9|version|pack"
  74. }
  75. if [ "$1" == "" ]; then
  76. help
  77. elif [ "$1" == "stop" ];then
  78. stop
  79. elif [ "$1" == "kill9" ];then
  80. kill9
  81. elif [ "$1" == "start" ];then
  82. start
  83. elif [ "$1" == "restart" ];then
  84. restart
  85. elif [ "$1" == "status" ];then
  86. status
  87. elif [ "$1" == "tail" ];then
  88. tailf
  89. elif [ "$1" == "pack" ];then
  90. pack
  91. elif [ "$1" == "version" ];then
  92. show_version
  93. else
  94. help
  95. fi