proginn-script-up.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. echo "Asia/Shanghai" > /etc/timezone
  3. # 写入环境变量
  4. if grep -q -w "PROGINN_BRANCH" /etc/environment; then
  5. echo "already changed env."
  6. else
  7. echo "ENV=test" >> /etc/environment
  8. echo "PROGINN_BRANCH=$PROGINN_BRANCH" >> /etc/environment
  9. echo "ROOTER_BRANCH=$ROOTER_BRANCH" >> /etc/environment
  10. echo "PROGINN_FRONTEND_BRANCH=$PROGINN_FRONTEND_BRANCH" >> /etc/environment
  11. fi
  12. # 更新代码
  13. su -c "cd /code && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  14. su -c "cd /code && git checkout $PROGINN_BRANCH" -s /bin/bash - www-data
  15. # 同步crontab
  16. cronfile=/code/config/php7/web/cron.test
  17. cp $cronfile /etc/crontab
  18. echo "*/2 * * * * www-data bash /data/docker/shell/script-code-update.sh\n" >> /etc/crontab
  19. # ulimit
  20. ulimit -Hn 1048576
  21. ulimit -Sn 1048576
  22. ulimit -Hu 1048576
  23. ulimit -Su 1048576
  24. ulimit -S -c unlimited
  25. if grep -q -w "nofile 1048576" /etc/security/limits.conf; then
  26. echo "already changed limit."
  27. else
  28. sed -i "55a * soft nofile 1048576\n* hard nofile 1048576" /etc/security/limits.conf
  29. fi
  30. if [[ ! -d "/data/log" ]]; then
  31. mkdir /data/log
  32. fi
  33. if [[ ! -d "/data/log/tmp" ]]; then
  34. mkdir /data/log/tmp
  35. fi
  36. if [[ ! -d "/data/log/proginn_cache" ]]; then
  37. mkdir /data/log/proginn_cache
  38. fi
  39. chmod -R 0755 /data/log
  40. chown -R www-data:www-data /data/log
  41. # 启动定时脚本
  42. service cron restart
  43. # 队列
  44. for (( i = 0; i < 5; i++ )); do
  45. su -c "QUEUE=highest,high,default,low,lowest COUNT=1 nohup php /code/web/bin/resque.php &" -s /bin/bash - www-data
  46. done
  47. su -c "INTERVAL=5 ENV=test nohup php /code/web/bin/resque-scheduler.php &" -s /bin/bash - www-data
  48. php /code/web/bin/queue_check.php &
  49. tail /dev/null -f