container-up.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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-user
  28. su -c "cd /proginn-user && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  29. su -c "cd /proginn-user && git checkout -f origin/dev" -s /bin/bash - www-data
  30. chown -R www-data:www-data /proginn-bituni
  31. su -c "cd /proginn-bituni && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  32. su -c "cd /proginn-bituni && git checkout -f origin/dev" -s /bin/bash - www-data
  33. chown -R www-data:www-data /proginn-frontend
  34. su -c "cd /proginn-frontend && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  35. su -c "cd /proginn-frontend && git checkout -f origin/$PROGINN_FRONTEND_BRANCH" -s /bin/bash - www-data
  36. chown -R www-data:www-data /proginn-child
  37. su -c "cd /proginn-child && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  38. su -c "cd /proginn-child && git checkout -f origin/$PROGINN_FRONTEND_BRANCH" -s /bin/bash - www-data
  39. # 初始化目录
  40. chown -R www-data:www-data /var/www
  41. if [[ ! -d "/data/phphub" ]]; then
  42. mkdir /data/phphub
  43. fi
  44. cp -Rf /code/web/phphub/storage/* /data/phphub/
  45. chmod -R 0755 /data/phphub/
  46. chown -R www-data:www-data /data/phphub
  47. if [[ ! -d "/data/_fields" ]]; then
  48. mkdir /data/_fields
  49. fi
  50. if [[ ! -d "/data/log" ]]; then
  51. mkdir /data/log
  52. fi
  53. if [[ ! -d "/data/log/tmp" ]]; then
  54. mkdir /data/log/tmp
  55. fi
  56. if [[ ! -d "/data/log/proginn_cache" ]]; then
  57. mkdir /data/log/proginn_cache
  58. fi
  59. chown -R www-data:www-data /boss
  60. chmod -R 0755 /data/log
  61. chown -R www-data:www-data /data/log
  62. chown -R www-data:www-data /data/_fields
  63. # ulimit
  64. ulimit -Hn 1048576
  65. ulimit -Sn 1048576
  66. ulimit -Su 1048576
  67. ulimit -S -c unlimited
  68. if grep -q -w "nofile 1048576" /etc/security/limits.conf; then
  69. echo "already changed limit."
  70. else
  71. sed -i "55a * soft nofile 1048576\n* hard nofile 1048576" /etc/security/limits.conf
  72. fi
  73. service php7.2-fpm start
  74. service nginx start
  75. cd /proginn-frontend
  76. chown -R www-data:www-data .
  77. 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
  78. su -c "cd /proginn-frontend && rm -rf node_modules && npx yarn --registry=https://registry.npm.taobao.org install" -s /bin/bash - www-data
  79. su -c "cd /proginn-frontend && pm2 start ecosystem.config.yml" -s /bin/bash - www-data
  80. su -c "cd /proginn-child && rm -rf node_modules && npx yarn --registry=https://registry.npm.taobao.org install" -s /bin/bash - www-data
  81. su -c "cd /proginn-child && pm2 start npm -- run start" -s /bin/bash - www-data
  82. # 启动定时脚本
  83. service cron restart
  84. tail -f /dev/null