-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·103 lines (99 loc) · 3.28 KB
/
deploy.sh
File metadata and controls
executable file
·103 lines (99 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
usage(){
echo "usage:$0 [package [output_path]|unpackage <file>|clean|start [dev|deploy] [ini file]|reload|stop]|start-celery"
}
check_deploy_env(){
if [ -z "$DEPLOY" ];then
echo "Not in deployment environment. Exiting..."
exit 2
fi
}
main(){
VENV_DIR=${VENV_DIR-venv}
case "$1" in
package)
BUILD_DIR=builds
BUILD_NAME=`TZ='America/New York' date +%F_%H-%M-%S`.tar.gz
BUILD_PATH=$BUILD_DIR/$BUILD_NAME
[ ! -d ./packages ] && mkdir $BUILD_DIR
tar zvc ./deploy.sh ./imods ./uwsgi.ini ./requirements.txt ./extra_dep -f "${2-$BUILD_PATH}"
echo ${2-$BUILD_PATH}
;;
unpackage)
if [ -z "$2" ];then
usage
return 1
fi
check_deploy_env
tar zxv -C ~/app -f $2
tar xv -C ~/app/extra_dep -f ~/extra_dep/python-apt_0.9.3.5.tar.xz
;;
clean)
check_deploy_env
rm -rf packages
rm -rf ~/app/*
rm -rf ~/tmp*
;;
start)
TARGET=${2-dev}
CONFIG=${3-uwsgi.ini}
case "$TARGET" in
dev)
python ./run.py
;;
dev-uwsgi)
uwsgi --ini $CONFIG:dev
;;
deploy)
check_deploy_env
VENV_DIR=${VENV_DIR-venv}\
IMODS_DB_DIR=${IMODS_DB_DIR-/var/db/imods.wunderkind.us}\
IMODS_CONFIG=${IMODS_CONFIG-imods.configs.production}\
uwsgi --ini $CONFIG:deploy
;;
*)
uwsgi --ini $CONFIG:$TARGET
esac
;;
start-celery)
celery -A imods.celery.celery worker -l info --autoreload
;;
reload)
if [ ! -r /tmp/uwsgi_imods.pid ];then
echo "uwsgi not started"
return 0
fi
uwsgi --reload /tmp/uwsgi_imods.pid
;;
stop)
pkill -INT uwsgi
;;
init)
check_deploy_env
cd ~/app
echo "Creating virtualenv in ~/app..."
virtualenv ${VENV_DIR-venv}
source $VENV_DIR/bin/activate
echo "Installing packages using pip..."
TEMP_REQUIREMENT_PATH=`mktemp`
# Skip compiling and installing uwsgi, because it's slow
# uwsgi should be already installed globally on the server
grep -v 'uWSGI==' requirements.txt > $TEMP_REQUIREMENT_PATH
pip install -r $TEMP_REQUIREMENT_PATH
rm $TEMP_REQUIREMENT_PATH
pushd .
cd ~/app/extra_dep/python-apt-0.9.3.5/
python setup.py install
popd
VENV_DIR=${VENV_DIR-venv}\
IMODS_DB_DIR=${IMODS_DB_DIR-/var/db/imods.wunderkind.us}\
IMODS_CONFIG=${IMODS_CONFIG-imods.configs.production}\
python -c 'from imods import app,db;from imods.db import add_defaults; add_defaults(app,db);print "ok"'
;;
test)
IMODS_TESTING=1 python -m unittest discover -v tests
;;
*) usage;;
esac
}
main $*