container-up.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. echo "Asia/Shanghai" > /etc/timezone
  3. # 写入环境变量
  4. if grep -q -w "PROGINN_FRONTEND_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. # 同步nginx配置
  13. ln -f -s /data/docker/config/nginx/nginx.conf /etc/nginx/nginx.conf
  14. ln -f -s /data/config/nginx.conf /etc/nginx/conf.d/proginn.conf
  15. rm -f /etc/nginx/sites-enabled/default
  16. # 同步phpfpm配置
  17. ln -f -s /code/config/php7/web/pool.test.conf /etc/php/7.2/fpm/pool.d/www.conf
  18. # sync cron
  19. cp /data/docker/config/crontab/container-code-up /etc/crontab
  20. # 更新代码
  21. chown -R www-data:www-data /code
  22. su -c "cd /code && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  23. su -c "cd /code && git checkout -f origin/$PROGINN_BRANCH" -s /bin/bash - www-data
  24. chown -R www-data:www-data /boss
  25. su -c "cd /boss && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  26. su -c "cd /boss && git checkout -f origin/$ROOTER_BRANCH" -s /bin/bash - www-data
  27. chown -R www-data:www-data /proginn-frontend
  28. su -c "cd /proginn-frontend && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  29. su -c "cd /proginn-frontend && git checkout -f origin/$PROGINN_FRONTEND_BRANCH" -s /bin/bash - www-data
  30. # 初始化目录
  31. chown -R www-data:www-data /var/www
  32. if [[ ! -d "/data/phphub" ]]; then
  33. mkdir /data/phphub
  34. fi
  35. cp -Rf /code/web/phphub/storage/* /data/phphub/
  36. chmod -R 0755 /data/phphub/
  37. chown -R www-data:www-data /data/phphub
  38. if [[ ! -d "/data/_fields" ]]; then
  39. mkdir /data/_fields
  40. fi
  41. if [[ ! -d "/data/log" ]]; then
  42. mkdir /data/log
  43. fi
  44. if [[ ! -d "/data/log/tmp" ]]; then
  45. mkdir /data/log/tmp
  46. fi
  47. if [[ ! -d "/data/log/proginn_cache" ]]; then
  48. mkdir /data/log/proginn_cache
  49. fi
  50. chown -R www-data:www-data /boss
  51. chmod -R 0755 /data/log
  52. chown -R www-data:www-data /data/log
  53. chown -R www-data:www-data /data/_fields
  54. # ulimit
  55. ulimit -Hn 1048576
  56. ulimit -Sn 1048576
  57. ulimit -Su 1048576
  58. ulimit -S -c unlimited
  59. if grep -q -w "nofile 1048576" /etc/security/limits.conf; then
  60. echo "already changed limit."
  61. else
  62. sed -i "55a * soft nofile 1048576\n* hard nofile 1048576" /etc/security/limits.conf
  63. fi
  64. service php7.2-fpm start
  65. service nginx start
  66. cd /proginn-frontend
  67. chown -R www-data:www-data .
  68. su -c "cd /workspace/kaifain/client && npx yarn --registry=https://registry.npm.taobao.org install && pm2 start ecosystem.config.yml" -s /bin/bash - www-data
  69. su -c "cd /proginn-frontend && pm2 start ecosystem.config.yml" -s /bin/bash - www-data
  70. # 启动定时脚本
  71. service cron restart
  72. tail -f /dev/null