container-up.sh 4.0 KB

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