container-up.sh 3.7 KB

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