#!/bin/bash echo "Asia/Shanghai" > /etc/timezone # 写入环境变量 if grep -q -w "PROGINN_FRONTEND_BRANCH" /etc/environment; then echo "already changed env." else echo "ENV=test" >> /etc/environment echo "PROGINN_BRANCH=$PROGINN_BRANCH" >> /etc/environment echo "ROOTER_BRANCH=$ROOTER_BRANCH" >> /etc/environment echo "PROGINN_FRONTEND_BRANCH=$PROGINN_FRONTEND_BRANCH" >> /etc/environment fi # 同步nginx配置 ln -f -s /data/docker/config/nginx/nginx.conf /etc/nginx/nginx.conf ln -f -s /data/config/nginx.conf /etc/nginx/conf.d/proginn.conf rm -f /etc/nginx/sites-enabled/default # 同步phpfpm配置 ln -f -s /code/config/php7/web/pool.test.conf /etc/php/7.2/fpm/pool.d/www.conf # sync cron cp /data/docker/config/crontab/container-code-up /etc/crontab if [[ ! -d "~/.ssh" ]]; then mkdir ~/.ssh fi cp -Rf /data/docker/config/id_rsa ~/.ssh/ cp -Rf /data/docker/config/id_rsa.pub ~/.ssh/ chmod 700 ~/.ssh/id_rsa chmod 700 ~/.ssh/id_rsa.pub # 更新代码 chown -R www-data:www-data /code su -c "cd /code && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data su -c "cd /code && git checkout -f origin/$PROGINN_BRANCH" -s /bin/bash - www-data chown -R www-data:www-data /boss su -c "cd /boss && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data su -c "cd /boss && git checkout -f origin/$ROOTER_BRANCH" -s /bin/bash - www-data chown -R www-data:www-data /proginn-user su -c "cd /proginn-user && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data su -c "cd /proginn-user && git checkout -f origin/dev" -s /bin/bash - www-data chown -R www-data:www-data /proginn-bituni su -c "cd /proginn-bituni && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data su -c "cd /proginn-bituni && git checkout -f origin/dev" -s /bin/bash - www-data chown -R www-data:www-data /proginn-frontend su -c "cd /proginn-frontend && git pull || git reset --hard FETCH_HEAD" -s /bin/bash - www-data su -c "cd /proginn-frontend && git checkout -f origin/$PROGINN_FRONTEND_BRANCH" -s /bin/bash - www-data # 初始化目录 chown -R www-data:www-data /var/www if [[ ! -d "/data/phphub" ]]; then mkdir /data/phphub fi cp -Rf /code/web/phphub/storage/* /data/phphub/ chmod -R 0755 /data/phphub/ chown -R www-data:www-data /data/phphub if [[ ! -d "/data/_fields" ]]; then mkdir /data/_fields fi if [[ ! -d "/data/log" ]]; then mkdir /data/log fi if [[ ! -d "/data/log/tmp" ]]; then mkdir /data/log/tmp fi if [[ ! -d "/data/log/proginn_cache" ]]; then mkdir /data/log/proginn_cache fi chown -R www-data:www-data /boss chmod -R 0755 /data/log chown -R www-data:www-data /data/log chown -R www-data:www-data /data/_fields # ulimit ulimit -Hn 1048576 ulimit -Sn 1048576 ulimit -Su 1048576 ulimit -S -c unlimited if grep -q -w "nofile 1048576" /etc/security/limits.conf; then echo "already changed limit." else sed -i "55a * soft nofile 1048576\n* hard nofile 1048576" /etc/security/limits.conf fi service php7.2-fpm start service nginx start cd /proginn-frontend chown -R www-data:www-data . 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 su -c "cd /proginn-frontend && rm -rf node_modules && npx yarn --registry=https://registry.npm.taobao.org install" -s /bin/bash - www-data su -c "cd /proginn-frontend && pm2 start ecosystem.config.yml" -s /bin/bash - www-data su -c "cd /proginn-child && rm -rf node_modules && npx yarn --registry=https://registry.npm.taobao.org install" -s /bin/bash - www-data su -c "cd /proginn-child && pm2 start --name proginn-child npm -- run start" -s /bin/bash - www-data # 启动定时脚本 service cron restart tail -f /dev/null