6
6
#
7
7
# My ref: http://www.linode.com/?r=aadfce9845055011e00f0c6c9a5c01158c452deb
8
8
9
-
10
- function django_get_user_or_default {
11
- # django_get_user_or_default([user])
12
- if [ -z " $1 " ];
13
- then USER=" www-data"
14
- else USER=" $1 "
15
- fi
16
- echo " $USER "
17
- }
18
-
19
- function django_get_project_path {
20
- # django_get_project_path(project_name)
21
- PROJECT_NAME=" $1 "
22
- echo " /srv/$PROJECT_NAME "
23
- }
9
+ PROJECT_CODE_DIR=app
10
+ DJANGO_PROJECT=webapp
24
11
25
12
function django_change_project_owner {
26
13
# django_change_project_owner(project_path, user)
27
14
PROJECT_PATH=" $1 "
28
15
USER=" $2 "
29
- GROUP=" $USER "
30
- chown -R " $USER :$GROUP " " $PROJECT_PATH "
16
+ chown -R " $USER :$USER " " $PROJECT_PATH "
31
17
}
32
18
33
19
function django_create_project {
34
- # django_create_project(project_name )
20
+ # django_create_project(project_path )
35
21
36
- PROJECT_NAME =" $1 "
37
- if [ -z " $PROJECT_NAME " ]; then
38
- echo " django_create_project() requires the project name as the first argument"
22
+ PROJECT_PATH =" $1 "
23
+ if [ -z " $PROJECT_PATH " ]; then
24
+ echo " django_create_project() requires the project root path as the first argument"
39
25
return 1;
40
26
fi
41
- PROJECT_PATH=` django_get_project_path " $PROJECT_NAME " `
42
27
43
- mkdir -p " $PROJECT_PATH /app /conf/apache"
28
+ mkdir -p " $PROJECT_PATH /$PROJECT_CODE_DIR /conf/apache"
44
29
mkdir -p " $PROJECT_PATH /logs" " $PROJECT_PATH /run/eggs"
45
30
46
31
virtualenv " $PROJECT_PATH /venv"
47
- $PROJECT_PATH /venv/bin/pip install django
32
+ $PROJECT_PATH /venv/bin/pip install Django
48
33
49
- pushd " $PROJECT_PATH /app "
50
- " $PROJECT_PATH /venv/bin/python" " $PROJECT_PATH /venv/bin/django-admin.py" startproject webapp .
34
+ pushd " $PROJECT_PATH /$PROJECT_CODE_DIR "
35
+ " $PROJECT_PATH /venv/bin/python" " $PROJECT_PATH /venv/bin/django-admin.py" startproject " $DJANGO_PROJECT " .
51
36
popd
52
- mkdir -p " $PROJECT_PATH /app/webapp/static"
37
+ mkdir -p " $PROJECT_PATH /$PROJECT_CODE_DIR /$DJANGO_PROJECT /static"
38
+
39
+ echo " Django" >> " $PROJECT_PATH /$PROJECT_CODE_DIR /requirements.txt"
53
40
}
54
41
55
42
function django_install_db_driver {
56
43
# django_install_db_driver(project_path, driver_package)
57
- $1 /venv/bin/pip install django " $2 "
44
+ $1 /venv/bin/pip install " $2 "
45
+ echo " $2 " >> " $PROJECT_PATH /$PROJECT_CODE_DIR /requirements.txt"
58
46
}
59
47
60
48
function django_configure_db_settings {
61
49
# django_configure_db_settings(project_path, engine, name, user, password, [host, [port]])
62
-
63
- SETTINGS=" $1 /app/webapp /settings.py"
50
+ PROJECT_PATH= " $1 "
51
+ SETTINGS=" $PROJECT_PATH / $PROJECT_CODE_DIR / $DJANGO_PROJECT /settings.py"
64
52
sed -i -e " s/'ENGINE': 'django.db.backends.'/'ENGINE': 'django.db.backends.$2 '/" " $SETTINGS "
65
53
sed -i -e " s/'NAME': ''/'NAME': '$3 '/" " $SETTINGS "
66
54
sed -i -e " s/'USER': ''/'USER': '$4 '/" " $SETTINGS "
@@ -79,7 +67,7 @@ function django_configure_apache_virtualhost {
79
67
VHOST_HOSTNAME=" $1 "
80
68
PROJECT_PATH=" $2 "
81
69
USER=" $3 "
82
- GROUP=" $USER "
70
+ GROUP=" $USER "
83
71
84
72
if [ -z " $VHOST_HOSTNAME " ]; then
85
73
echo " django_configure_apache_virtualhost() requires the hostname as the first argument"
@@ -92,43 +80,43 @@ function django_configure_apache_virtualhost {
92
80
fi
93
81
94
82
APACHE_CONF=" 200-$VHOST_HOSTNAME "
95
- APACHE_CONF_PATH=" $PROJECT_PATH /app /conf/apache/$APACHE_CONF "
83
+ APACHE_CONF_PATH=" $PROJECT_PATH /$PROJECT_CODE_DIR /conf/apache/$APACHE_CONF "
96
84
97
85
cat > " $APACHE_CONF_PATH " << EOF
98
86
<VirtualHost *:80>
99
87
ServerAdmin root@$VHOST_HOSTNAME
100
88
ServerName $VHOST_HOSTNAME
101
89
ServerSignature Off
102
90
103
- Alias /static/ $PROJECT_PATH /app/webapp /static/
104
- Alias /robots.txt $PROJECT_PATH /app/webapp /static/robots.txt
105
- Alias /favicon.ico $PROJECT_PATH /app/webapp /static/favicon.ico
91
+ Alias /static/ $PROJECT_PATH /$PROJECT_CODE_DIR / $DJANGO_PROJECT /static/
92
+ Alias /robots.txt $PROJECT_PATH /$PROJECT_CODE_DIR / $DJANGO_PROJECT /static/robots.txt
93
+ Alias /favicon.ico $PROJECT_PATH /$PROJECT_CODE_DIR / $DJANGO_PROJECT /static/favicon.ico
106
94
107
95
SetEnvIf User_Agent "monit/*" dontlog
108
96
CustomLog "|/usr/sbin/rotatelogs $PROJECT_PATH /logs/access.log.%Y%m%d-%H%M 5M" combined env=!dontlog
109
97
ErrorLog "|/usr/sbin/rotatelogs $PROJECT_PATH /logs/error.log.%Y%m%d-%H%M 5M"
110
98
LogLevel warn
111
99
112
- WSGIScriptAlias / $PROJECT_PATH /app/webapp /wsgi.py
100
+ WSGIScriptAlias / $PROJECT_PATH /$PROJECT_CODE_DIR / $DJANGO_PROJECT /wsgi.py
113
101
114
- WSGIDaemonProcess $VHOST_HOSTNAME user=$USER group=$GROUP processes=2 threads=10 maximum-requests=10000 display-name=%{GROUP} python-path=$PROJECT_PATH /app :$PROJECT_PATH /venv/lib/python2.7/site-packages python-eggs=$PROJECT_PATH /run/eggs
102
+ WSGIDaemonProcess $VHOST_HOSTNAME user=$USER group=$GROUP processes=2 threads=10 maximum-requests=10000 display-name=%{GROUP} python-path=$PROJECT_PATH /$PROJECT_CODE_DIR :$PROJECT_PATH /venv/lib/python2.7/site-packages python-eggs=$PROJECT_PATH /run/eggs
115
103
WSGIProcessGroup $VHOST_HOSTNAME
116
- WSGIScriptAlias / $PROJECT_PATH /app/webapp /wsgi.py
104
+ WSGIScriptAlias / $PROJECT_PATH /$PROJECT_CODE_DIR / $DJANGO_PROJECT /wsgi.py
117
105
118
- <Directory $PROJECT_PATH /app/webapp /static>
106
+ <Directory $PROJECT_PATH /$PROJECT_CODE_DIR / $DJANGO_PROJECT /static>
119
107
Order deny,allow
120
108
Allow from all
121
109
Options -Indexes FollowSymLinks
122
110
</Directory>
123
111
124
- <Directory $PROJECT_PATH /app /conf/apache>
112
+ <Directory $PROJECT_PATH /$PROJECT_CODE_DIR /conf/apache>
125
113
Order deny,allow
126
114
Allow from all
127
115
</Directory>
128
116
129
117
</VirtualHost>
130
118
EOF
131
119
132
- ln -t /etc/apache2/sites-available/ " $APACHE_CONF_PATH "
120
+ ln -s - t /etc/apache2/sites-available/ " $APACHE_CONF_PATH "
133
121
a2ensite " $APACHE_CONF "
134
122
}
0 commit comments