Advertisement
Guest User

/usr/local/bin/start_unicorn

a guest
Oct 7th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.27 KB | None | 0 0
  1. #!/bin/bash
  2. USUARIO="sistemas"
  3. if [ "`whoami`" != $USUARIO ]
  4. then
  5.     echo Execute este comando com o usuario \"$USUARIO\"
  6.     exit 1
  7. fi
  8. source /etc/profile
  9.  
  10. APP=`pwd | cut -d "/" -f5`
  11. PID=`ps ax | grep $APP | grep master | awk '{print $1}'`
  12.  
  13. #Se o processo nao estiver rodando, entao recebe o PID 0000 para efeitos de comparacao posterior
  14. if [ -z "$PID" ]
  15. then
  16. PID="0000"
  17. fi
  18.  
  19. #verifica se o PID que esta gravado no arquivo existe
  20. #Verifica se o arquivo existe
  21. if [ -e "tmp/pids/unicorn.pid" ]
  22. then
  23.         PID_FILE=`cat tmp/pids/unicorn.pid`
  24.         #Verifica aberracao (se o pc reiniciou e ficou o arquivo .pid com o PID do processo anterior)
  25.         if [ "$PID_FILE" -ne "$PID" ]
  26.         then
  27.         echo "Apagando o arquivo PID e iniciando a aplicacao" $APP
  28.         #Apagar o arquivo pid e iniciar a aplicacao
  29.         rm -rf tmp/pids/unicorn.pid
  30.         bundle exec unicorn_rails -E production -D --path /$APP -c `pwd`/config/unicorn.rb
  31.         else
  32.         echo "Apliacacao" $APP "ja esta em execucao, PID:" $PID
  33.         fi
  34.  
  35. #Se nao existe o arquivo ele nao esta rodando (a menos que alguem esteja sabotando e apagou o arquivo .pid)
  36. else
  37. echo "Iniciando a aplicacao" $APP
  38. bundle exec unicorn_rails -E production -D -c `pwd`/config/unicorn.rb --path /$APP
  39. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement