container-up.sh 3.3 KB

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