1 | #!/bin/bash |
---|
2 | echo 'setup-web2py-nginx-uwsgi-opensuse.sh' |
---|
3 | echo 'Requires OpenSUSE 12.3 32Bits and installs Nginx + uWSGI + Web2py' |
---|
4 | |
---|
5 | |
---|
6 | # Get Web2py Admin Password |
---|
7 | echo -e "Web2py Admin Password: \c " |
---|
8 | read PW |
---|
9 | |
---|
10 | zypper clean && zypper refresh && zypper up |
---|
11 | zypper in -y nginx python-xml python-pip unzip sudo |
---|
12 | zypper in -y gcc python-devel libxml2-devel python-pip unzip |
---|
13 | pip install --upgrade pip |
---|
14 | PIPPATH=`which pip` |
---|
15 | $PIPPATH install --upgrade uwsgi |
---|
16 | |
---|
17 | |
---|
18 | # Prepare folders for uwsgi |
---|
19 | mkdir /etc/uwsgi |
---|
20 | mkdir /var/log/uwsgi |
---|
21 | |
---|
22 | usermod -G www nginx |
---|
23 | |
---|
24 | mkdir -p /etc/nginx/vhosts.d/ |
---|
25 | mkdir -p /etc/nginx/ssl/ |
---|
26 | |
---|
27 | |
---|
28 | cd /etc/nginx/ssl |
---|
29 | openssl genrsa 1024 > web2py.key |
---|
30 | chmod 400 web2py.key |
---|
31 | openssl req -new -x509 -nodes -sha1 -days 1780 -key web2py.key > web2py.crt |
---|
32 | openssl x509 -noout -fingerprint -text < web2py.crt > web2py.info |
---|
33 | |
---|
34 | |
---|
35 | echo 'server { |
---|
36 | listen 80; |
---|
37 | server_name $hostname; |
---|
38 | #to enable correct use of response.static_version |
---|
39 | location ~* /(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ { |
---|
40 | alias /srv/www/web2py/applications/$1/static/$2; |
---|
41 | expires max; |
---|
42 | } |
---|
43 | location / { |
---|
44 | #uwsgi_pass 127.0.0.1:9001; |
---|
45 | uwsgi_pass unix:///tmp/web2py.socket; |
---|
46 | include /etc/nginx/uwsgi_params; |
---|
47 | uwsgi_param UWSGI_SCHEME $scheme; |
---|
48 | uwsgi_param SERVER_SOFTWARE nginx/$nginx_version; |
---|
49 | } |
---|
50 | } |
---|
51 | server { |
---|
52 | listen 443 default_server ssl; |
---|
53 | server_name $hostname; |
---|
54 | ssl_certificate /etc/nginx/ssl/web2py.crt; |
---|
55 | ssl_certificate_key /etc/nginx/ssl/web2py.key; |
---|
56 | ssl_prefer_server_ciphers on; |
---|
57 | ssl_session_cache shared:SSL:10m; |
---|
58 | ssl_session_timeout 10m; |
---|
59 | ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA; |
---|
60 | ssl_protocols SSLv3 TLSv1; |
---|
61 | keepalive_timeout 70; |
---|
62 | location ~* /(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ { |
---|
63 | alias /srv/www/web2py/applications/$1/static/$2; |
---|
64 | expires max; |
---|
65 | } |
---|
66 | location / { |
---|
67 | #uwsgi_pass 127.0.0.1:9001; |
---|
68 | uwsgi_pass unix:///tmp/web2py.socket; |
---|
69 | include /etc/nginx/uwsgi_params; |
---|
70 | uwsgi_param UWSGI_SCHEME $scheme; |
---|
71 | uwsgi_param SERVER_SOFTWARE nginx/$nginx_version; |
---|
72 | } |
---|
73 | |
---|
74 | }' >/etc/nginx/vhosts.d/web2py.conf |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | # Create configuration file /etc/uwsgi/web2py.xml |
---|
79 | echo '<uwsgi> |
---|
80 | <socket>/tmp/web2py.socket</socket> |
---|
81 | <pythonpath>/srv/www/web2py/</pythonpath> |
---|
82 | <mount>/=wsgihandler:application</mount> |
---|
83 | <master/> |
---|
84 | <processes>4</processes> |
---|
85 | <harakiri>60</harakiri> |
---|
86 | <reload-mercy>8</reload-mercy> |
---|
87 | <cpu-affinity>1</cpu-affinity> |
---|
88 | <stats>/tmp/stats.socket</stats> |
---|
89 | <max-requests>2000</max-requests> |
---|
90 | <limit-as>512</limit-as> |
---|
91 | <reload-on-as>256</reload-on-as> |
---|
92 | <reload-on-rss>192</reload-on-rss> |
---|
93 | <uid>nginx</uid> |
---|
94 | <gid>www</gid> |
---|
95 | <cron>0 0 -1 -1 -1 python /srv/www/web2py/web2py.py -Q -S welcome -M -R scripts/sessions2trash.py -A -o</cron> |
---|
96 | <no-orphans/> |
---|
97 | </uwsgi>' >/etc/uwsgi/web2py.xml |
---|
98 | |
---|
99 | |
---|
100 | cd /srv/www/ |
---|
101 | wget http://web2py.com/examples/static/web2py_src.zip |
---|
102 | unzip web2py_src.zip |
---|
103 | rm web2py_src.zip |
---|
104 | mv web2py/handlers/wsgihandler.py web2py/wsgihandler.py |
---|
105 | chown -R nginx:www web2py |
---|
106 | cd /srv/www/web2py |
---|
107 | sudo -u nginx python -c "from gluon.main import save_password; save_password('$PW',443)" |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | ## Daemons /start/stop |
---|
112 | |
---|
113 | echo '#!/bin/sh |
---|
114 | # Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany. |
---|
115 | # |
---|
116 | # Author: James Oakley |
---|
117 | # |
---|
118 | # /etc/init.d/uwsgi |
---|
119 | # and its symbolic link |
---|
120 | # /(usr/)sbin/rcuwsgi |
---|
121 | # |
---|
122 | # LSB compatible service control script; see http://www.linuxbase.org/spec/ |
---|
123 | # |
---|
124 | ### BEGIN INIT INFO |
---|
125 | # Provides: uwsgi |
---|
126 | # Required-Start: $syslog $remote_fs |
---|
127 | # Should-Start: $time ypbind smtp |
---|
128 | # Required-Stop: $syslog $remote_fs |
---|
129 | # Should-Stop: ypbind smtp |
---|
130 | # Default-Start: 3 5 |
---|
131 | # Default-Stop: 0 1 2 6 |
---|
132 | # Short-Description: Application Container Server for Networked/Clustered Web Applications |
---|
133 | # Description: Application Container Server for Networked/Clustered Web Applications |
---|
134 | ### END INIT INFO |
---|
135 | |
---|
136 | # Check for missing binaries (stale symlinks should not happen) |
---|
137 | UWSGI_BIN=/usr/bin/uwsgi |
---|
138 | test -x $UWSGI_BIN || { echo "$UWSGI_BIN not installed"; |
---|
139 | if [ "$1" = "stop" ]; then exit 0; |
---|
140 | else exit 5; fi; } |
---|
141 | |
---|
142 | UWSGI_EMPEROR_MODE=true |
---|
143 | UWSGI_VASSALS="/etc/uwsgi/" |
---|
144 | UWSGI_OPTIONS="--logto /var/log/uwsgi/uwsgi.log" |
---|
145 | |
---|
146 | |
---|
147 | UWSGI_OPTIONS="$UWSGI_OPTIONS --autoload" |
---|
148 | |
---|
149 | if [ "$UWSGI_EMPEROR_MODE" = "true" ] ; then |
---|
150 | UWSGI_OPTIONS="$UWSGI_OPTIONS --emperor $UWSGI_VASSALS" |
---|
151 | fi |
---|
152 | |
---|
153 | . /etc/rc.status |
---|
154 | |
---|
155 | rc_reset |
---|
156 | |
---|
157 | case "$1" in |
---|
158 | start) |
---|
159 | echo -n "Starting uWSGI " |
---|
160 | /sbin/startproc $UWSGI_BIN $UWSGI_OPTIONS |
---|
161 | rc_status -v |
---|
162 | ;; |
---|
163 | stop) |
---|
164 | echo -n "Shutting down uWSGI " |
---|
165 | /sbin/killproc $UWSGI_BIN |
---|
166 | rc_status -v |
---|
167 | ;; |
---|
168 | try-restart|condrestart) |
---|
169 | if test "$1" = "condrestart"; then |
---|
170 | echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}" |
---|
171 | fi |
---|
172 | $0 status |
---|
173 | if test $? = 0; then |
---|
174 | $0 restart |
---|
175 | else |
---|
176 | rc_reset |
---|
177 | fi |
---|
178 | rc_status |
---|
179 | ;; |
---|
180 | restart) |
---|
181 | $0 stop |
---|
182 | $0 start |
---|
183 | rc_status |
---|
184 | ;; |
---|
185 | force-reload) |
---|
186 | echo -n "Reload service uWSGI " |
---|
187 | /sbin/killproc -HUP $UWSGI_BIN |
---|
188 | rc_status -v |
---|
189 | ;; |
---|
190 | reload) |
---|
191 | echo -n "Reload service uWSGI " |
---|
192 | /sbin/killproc -HUP $UWSGI_BIN |
---|
193 | rc_status -v |
---|
194 | ;; |
---|
195 | status) |
---|
196 | echo -n "Checking for service uWSGI " |
---|
197 | /sbin/checkproc $UWSGI_BIN |
---|
198 | rc_status -v |
---|
199 | ;; |
---|
200 | probe) |
---|
201 | echo -n "uWSGI does not support probe " |
---|
202 | rc_failed 3 |
---|
203 | rc_status -v |
---|
204 | ;; |
---|
205 | *) |
---|
206 | echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" |
---|
207 | exit 1 |
---|
208 | ;; |
---|
209 | esac |
---|
210 | rc_exit '> /etc/init.d/uwsgi |
---|
211 | |
---|
212 | |
---|
213 | chmod +x /etc/init.d/uwsgi |
---|
214 | /etc/init.d/uwsgi start |
---|
215 | /etc/init.d/nginx restart |
---|
216 | |
---|
217 | |
---|
218 | chkconfig --add uwsgi |
---|
219 | chkconfig --add nginx |
---|
220 | |
---|
221 | ## you can reload uwsgi with |
---|
222 | #/etc/init.d/uwsgi restart |
---|
223 | ## to reload web2py only (without restarting uwsgi) |
---|
224 | # touch /etc/uwsgi/web2py.xml |
---|