服务器上的启动脚本
#!/usr/bin/env bash
docker_name=ip-flow
project_path=/home/code/ip-flow
port=8001
image=xiaochonghao/django1.11.1:v2
echo "git tag" $1
echo "project path" ${project_path}
echo "docker name" ${docker_name}
echo "port" ${port}
echo "image" ${image}
cd ${project_path}
git pull
git checkout $1
echo "restart ip-flow service....."
echo "ensure old service start______________________________________"
docker ps
echo 'stop and rm old service'
echo "stop docker " ${docker_name}
docker stop ${docker_name}
echo "docker rm" ${docker_name}
docker rm ${docker_name}
echo "start new service"
docker run -d --name ${docker_name} -p ${port}:80 -v ${project_path}:/data/ip-flow ${image} /bin/sh -c 'sh /data/ip-flow/bin/run.sh test | pro;'
docker ps
docker容器执行的命令
#!/usr/bin/env bash
wsgi_name=wsgi_pro.py
if [ $# -ge 1 ]; then
if [ $1 != 'pro' ] && [ $1 != 'pre' ] && [ $1 != 'dev' ] && [ $1 != 'test' ]; then
echo 'usage: ./run_api.sh [pro|pre|dev|test]'
fi
if [ $1 == 'pre' ]; then
wsgi_name=wsgi_pre.py
fi
if [ $1 == 'dev' ]; then
wsgi_name=wsgi_dev.py
fi
if [ $1 == 'test' ]; then
wsgi_name=wsgi_test.py
fi
fi
cat >> /usr/local/apache2/conf/httpd.conf <<EOF
ServerName localhost:8001
LoadModule wsgi_module modules/mod_wsgi.so
AddType text/html .py
WSGIScriptAlias / /data/console-end/console-end/${wsgi_name}
WSGIPythonPath /data/console-end/console-end/
<Directory /data/console-end/console-end>
<Files ${wsgi_name}>
Require all granted
</Files>
</Directory>
Alias /static/ /usr/local/lib/python2.7/site-packages/rest_framework_swagger/static/
<Directory /usr/local/lib/python2.7/site-packages/rest_framework_swagger/static>
Require all granted
</Directory>
EOF
service httpd start
chmod -R 777 /data/console-end/logs/
tail -f /var/log/messages
网友评论