container-up.sh 3.6 KB

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