container-up.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. # 同步phpfpm配置
  16. ln -f -s /code/config/php7/web/pool.test.branch.conf /etc/php/7.2/fpm/pool.d/www.conf
  17. # sync cron
  18. cp /data/docker/config/crontab/container-code-up /etc/crontab
  19. # 更新代码
  20. su -c "cd /code && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  21. su -c "cd /code && git checkout $PROGINN_BRANCH" -s /bin/bash - www-data
  22. su -c "cd /boss && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  23. su -c "cd /boss && git checkout $ROOTER_BRANCH" -s /bin/bash - www-data
  24. su -c "cd /proginn-frontend && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data
  25. su -c "cd /proginn-frontend && git checkout $PROGINN_FRONTEND_BRANCH" -s /bin/bash - www-data
  26. # 初始化目录
  27. chown -R www-data:www-data /var/www
  28. if [[ ! -d "/data/phphub" ]]; then
  29. mkdir /data/phphub
  30. fi
  31. cp -Rf /code/web/phphub/storage/* /data/phphub/
  32. chmod -R 0755 /data/phphub/
  33. chown -R www-data:www-data /data/phphub
  34. if [[ ! -d "/data/log" ]]; then
  35. mkdir /data/log
  36. fi
  37. if [[ ! -d "/data/log/tmp" ]]; then
  38. mkdir /data/log/tmp
  39. fi
  40. if [[ ! -d "/data/log/proginn_cache" ]]; then
  41. mkdir /data/log/proginn_cache
  42. fi
  43. chown -R www-data:www-data /boss
  44. chmod -R 0755 /data/log
  45. chown -R www-data:www-data /data/log
  46. # ulimit
  47. ulimit -Hn 1048576
  48. ulimit -Sn 1048576
  49. ulimit -Hu 1048576
  50. ulimit -Su 1048576
  51. ulimit -S -c unlimited
  52. if grep -q -w "nofile 1048576" /etc/security/limits.conf; then
  53. echo "already changed limit."
  54. else
  55. sed -i "55a * soft nofile 1048576\n* hard nofile 1048576" /etc/security/limits.conf
  56. fi
  57. service php7.2-fpm start
  58. service nginx start
  59. cd /proginn-frontend
  60. chown -R www-data:www-data .
  61. su -c "cd /proginn-frontend && npx yarn --registry=https://registry.npm.taobao.org install && npm run build" -s /bin/bash - www-data
  62. su -c "cd /proginn-frontend && pm2 start npm --name proginn-frontend -- run start" -s /bin/bash - www-data
  63. tail -f /dev/null