Advertisement
Guest User

OSQA + nginx installation script

a guest
Mar 9th, 2012
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #### Copied from http://fartersoft.com/blog/2010/12/12/installing-osqa-with-nginx-uwsgi-and-sqlite3-on-ubuntu-lucid-10-04-minimal/
  4.  
  5. #### Unsure which version of the script it is.
  6.  
  7. ####################
  8. # Settings section #
  9. ####################
  10.  
  11. # Osqa settings
  12. # Whether development version should be used
  13. # Svn revision 602 used by meta.osqa.net is used if this is set to 'no'
  14. OSQA_USE_DEV_VERSION=yes
  15.  
  16. # Where to put osqa folder
  17. OSQA_DIR_BASE="/home"
  18.  
  19. # Folder to hold osqa files
  20. OSQA_DIR="osqa"
  21.  
  22. # Sqlite3 database file
  23. OSQA_DB_FILE="osqa_sqlite3.db"
  24.  
  25. # Single-space separated list of unused modules
  26. # See http://wiki.osqa.net/display/docs/OSQA+Installation+and+Upgrade+Guides
  27. # IMPORTANT: at least one badges module should be enabled
  28. OSQA_DISABLED_MODULES=""
  29.  
  30. # Localization-related settings
  31. # Supported locales: de/en/es/fr/pt/zh_CN
  32. OSQA_LOCALE=
  33. OSQA_TIMEZONE=
  34.  
  35. # Nginx settings
  36. # Domain name used for osqa site
  37. OSQA_SERVER_DOMAIN="example.com"
  38.  
  39. # Number of nginx worker processes
  40. # Tweak this according to your host hardware specification
  41. NGINX_PROCESS=2
  42.  
  43. # Uwsgi settings
  44. # Number of uwsgi worker processes
  45. UWSGI_PROCESS=4
  46.  
  47. ###################################
  48. # Dependency-installation section #
  49. ###################################
  50.  
  51. # Update system
  52. apt-get update
  53. apt-get upgrade -y
  54.  
  55. # Install utilities and dependencies
  56. for i in busybox-static \
  57.          syslog-ng \
  58.          sqlite3 \
  59.          subversion \
  60.          python-setuptools \
  61.          python-pip \
  62.          python-software-properties \
  63.          ; do
  64.   apt-get install $i -yf
  65. done
  66.  
  67. # Uncomment to use postfix as mail server
  68. # Select 'Internet Site' and set mail name to OSQA_SERVER_DOMAIN
  69. apt-get install postfix -yf
  70.  
  71. # OPTIONAL
  72. # Uncomment to disable inbound mail
  73. #sed -i "s%^\(inet_interfaces\ =\ \).*%\1loopback-only%" /etc/postfix/main.cf
  74.  
  75. # Install osqa python dependencies
  76. for i in django \
  77.          elementtree \
  78.          south \
  79.          markdown \
  80.          html5lib \
  81.          python-openid \
  82.          sphinx \
  83.          sphinxsearch \
  84.          ; do
  85.   pip install $i
  86. done
  87.  
  88. #############################
  89. # Osqa installation section #
  90. #############################
  91.  
  92. # Install osqa
  93. mkdir -p $OSQA_DIR_BASE
  94. cd $OSQA_DIR_BASE
  95. rm -rf $OSQA_DIR
  96. if [ "$OSQA_USE_DEV_VERSION" = no ]; then
  97.   svn co -r 602 http://svn.osqa.net/svnroot/osqa/trunk $OSQA_DIR
  98. else
  99.   svn co http://svn.osqa.net/svnroot/osqa/trunk $OSQA_DIR
  100. fi
  101.  
  102. # Unicode safety fix
  103. sed -i "s/mark_safe\((settings.*\)/mark_safe(unicode\1)/g" \
  104.   $OSQA_DIR/forum/skins/default/templates/notifications/*.html
  105.  
  106. # Configure osqa
  107. cat $OSQA_DIR/settings_local.py.dist | \
  108.   sed -e "s%^\(DATABASE_NAME\ =\ \).*%\1'$OSQA_DIR_BASE/$OSQA_DIR/$OSQA_DB_FILE'%" \
  109.       -e "s%^\(DATABASE_ENGINE\ =\ \).*%\1'sqlite3'%" \
  110.       -e "s%^\(APP_URL\ =\ 'http://\).*%\1$OSQA_SERVER_DOMAIN'%" \
  111.   > $OSQA_DIR/settings_local.py
  112.  
  113. [ -n "$OSQA_LOCALE" ] && sed -i "s%^\(LANGUAGE_CODE\ =\ \).*%\1'$OSQA_LOCALE'%" \
  114.   $OSQA_DIR/settings_local.py
  115.  
  116. [ -n "$OSQA_TIMEZONE" ] && \
  117.   sed -i "s%^\(TIME_ZONE\ =\ \).*%\1'$OSQA_TIMEZONE'%" $OSQA_DIR/settings_local.py
  118.  
  119. for i in $OSQA_DISABLED_MODULES; do
  120.   sed -i "s%^\(DISABLED_MODULES.*\)]%\1,\ '$i']%" $OSQA_DIR/settings_local.py
  121. done
  122.  
  123. # Setup symlink to django admin interface
  124. ln -s /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media \
  125.   $OSQA_DIR/admin_media
  126.  
  127. # OPTIONAL
  128. # Uncomment to hide post content in rss feeds for anti-scraping purpose
  129. #sed -i "s/item\.html/\"\"/g" $OSQA_DIR/forum/feed.py
  130. #sed -i "s/question\.html/\"\"/g" $OSQA_DIR/forum/feed.py
  131.  
  132. cat $OSQA_DIR/osqa.wsgi.dist | \
  133.   sed -e "s%/path/to_dir_above%$OSQA_DIR_BASE%g" > $OSQA_DIR/osqa.wsgi
  134.  
  135. # It's not necessary to create 'superuser' at this step
  136. python $OSQA_DIR/manage.py syncdb --all || exit 1
  137. python $OSQA_DIR/manage.py migrate forum --fake
  138.  
  139. # Set ownership and permissions
  140. chown -R www-data $OSQA_DIR
  141. chmod -R g+w $OSQA_DIR/forum/upfiles $OSQA_DIR/log $OSQA_DIR/$OSQA_DB_FILE
  142.  
  143. ####################################
  144. # Nginx/Uwsgi installation section #
  145. ####################################
  146.  
  147. # Install and configure nginx and uwsgi
  148. add-apt-repository ppa:stevecrozz/ppa
  149. apt-get update
  150. apt-get install uwsgi nginx -yf
  151.  
  152. # Create uwsgi config file
  153. cat > /etc/uwsgi.xml << EOF
  154. <uwsgi>
  155.   <gid>www-data</gid>
  156.   <uid>www-data</uid>
  157.   <single-interpreter/>
  158.   <disable-logging/>
  159.   <socket>127.0.0.1:9090</socket>
  160.   <python-path>$OSQA_DIR_BASE/$OSQA_DIR</python-path>
  161.   <wsgi-file>$OSQA_DIR_BASE/$OSQA_DIR/osqa.wsgi</wsgi-file>
  162.   <processes>$UWSGI_PROCESS</processes>
  163.   <master/>
  164.   <harakiri>20</harakiri>
  165.   <limit-as>128</limit-as>
  166.   <memory-report/>
  167.   <no-orphans/>
  168. </uwsgi>
  169. EOF
  170.  
  171. # Set nginx worker process number
  172. sed -i "s%\(worker_processes\).*%\1\ \ $NGINX_PROCESS;%" /etc/nginx/nginx.conf
  173.  
  174. # Create nginx site
  175. cat > /etc/nginx/sites-enabled/$OSQA_SERVER_DOMAIN << EOF
  176. server {
  177.   listen          80 default;
  178.   server_name     $OSQA_SERVER_DOMAIN;
  179.  
  180.   location /m/ {
  181.     alias $OSQA_DIR_BASE/$OSQA_DIR/forum/skins/;
  182.   }
  183.  
  184.   location /upfiles/ {
  185.     alias $OSQA_DIR_BASE/$OSQA_DIR/forum/upfiles/;
  186.   }
  187.  
  188.   location /admin_media/ {
  189.     alias $OSQA_DIR_BASE/$OSQA_DIR/admin_media/;
  190.   }
  191.  
  192.   location / {
  193.     include uwsgi_params;
  194.     uwsgi_pass 127.0.0.1:9090;
  195.   }
  196. }
  197. EOF
  198.  
  199. # OPTIONAL: disable nginx default site for security
  200. rm -f /etc/nginx/sites-enabled/default
  201.  
  202. # Start services
  203. service uwsgi restart || exit 1
  204. service nginx restart || exit 1
  205.  
  206. echo "OSQA has been successfully installed."
  207. echo "Visit $OSQA_SERVER_DOMAIN now, create superuser and customize OSQA."
  208.  
  209. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement