Advertisement
Guest User

Untitled

a guest
May 19th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # ====== CONFIG ======
  4. INSTALLATION_DIRECTORY=/usr/share/mayan-edms/
  5. DB_NAME=mayan_edms
  6. DB_USERNAME=mayan
  7. DB_PASSWORD=test123
  8. # ==== END CONFIG ====
  9.  
  10. cat << EOF | sudo tee -a /etc/motd.tail
  11. **********************************
  12.  
  13. Mayan EDMS Vagrant Production Box
  14.  
  15. **********************************
  16. EOF
  17.  
  18. echo -e "\n -> Running apt-get update & upgrade \n"
  19. sudo apt-get -qq update
  20. sudo apt-get -y upgrade
  21.  
  22. echo -e "\n -> Installing core binaries \n"
  23. apt-get install nginx supervisor redis-server postgresql libpq-dev libjpeg-dev libmagic1 libpng-dev libreoffice libtiff-dev gcc ghostscript gpgv python-dev python-virtualenv tesseract-ocr unpaper poppler-utils -y
  24.  
  25. echo -e "\n -> Setting up virtualenv \n"
  26. rm -f ${INSTALLATION_DIRECTORY}
  27. virtualenv ${INSTALLATION_DIRECTORY}
  28. source ${INSTALLATION_DIRECTORY}bin/activate
  29.  
  30. echo -e "\n -> Installing Mayan EDMS from PyPI \n"
  31. pip install mayan-edms
  32.  
  33. echo -e "\n -> Installing Python client for PostgreSQL, Redis, and uWSGI \n"
  34. pip install psycopg2 redis uwsgi
  35.  
  36. echo -e "\n -> Creating the database for the installation \n"
  37. #sudo -u postgres createuser -P mayan $DB_PASSWORD
  38. #sudo -u postgres echo "CREATE USER mayan WITH password $DB_PASSWORD" | psql
  39. echo "CREATE USER mayan WITH PASSWORD '$DB_PASSWORD';" | sudo -u postgres psql
  40. sudo -u postgres createdb -O $DB_USERNAME $DB_NAME
  41.  
  42. echo -e "\n -> Creating the directories for the logs \n"
  43. mkdir /var/log/mayan
  44.  
  45. echo -e "\n -> Making a convenience symlink \n"
  46. cd ${INSTALLATION_DIRECTORY}
  47. ln -s lib/python2.7/site-packages/mayan .
  48.  
  49. echo -e "\n -> Creating an initial settings file \n"
  50. mayan-edms.py createsettings
  51.  
  52. echo -e "\n -> Updating the mayan/settings/local.py file \n"
  53. cat >> mayan/settings/local.py << EOF
  54. DATABASES = {
  55. 'default': {
  56. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  57. 'NAME': '$DB_NAME',
  58. 'USER': '$DB_USERNAME',
  59. 'PASSWORD': '$DB_PASSWORD',
  60. 'HOST': 'localhost',
  61. 'PORT': '5432',
  62. }
  63. }
  64.  
  65. BROKER_URL = 'redis://127.0.0.1:6379/0'
  66. CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/0'
  67. EOF
  68.  
  69. echo -e "\n -> Migrating the database or initialize the project \n"
  70. mayan-edms.py initialsetup
  71.  
  72. echo -e "\n -> Disabling the default NGINX site \n"
  73. rm -f /etc/nginx/sites-enabled/default
  74.  
  75. echo -e "\n -> Creating a uwsgi.ini file \n"
  76. cat > uwsgi.ini << EOF
  77. [uwsgi]
  78. chdir = ${INSTALLATION_DIRECTORY}lib/python2.7/site-packages/mayan
  79. chmod-socket = 664
  80. chown-socket = www-data:www-data
  81. env = DJANGO_SETTINGS_MODULE=mayan.settings.production
  82. gid = www-data
  83. logto = /var/log/uwsgi/%n.log
  84. pythonpath = ${INSTALLATION_DIRECTORY}lib/python2.7/site-packages
  85. master = True
  86. max-requests = 5000
  87. socket = ${INSTALLATION_DIRECTORY}uwsgi.sock
  88. uid = www-data
  89. vacuum = True
  90. wsgi-file = ${INSTALLATION_DIRECTORY}lib/python2.7/site-packages/mayan/wsgi.py
  91. EOF
  92.  
  93. echo -e "\n -> Creating the directory for the uWSGI log files \n"
  94. mkdir -p /var/log/uwsgi
  95.  
  96. echo -e "\n -> Creating the NGINX site file for Mayan EDMS, /etc/nginx/sites-available/mayan \n"
  97. cat > /etc/nginx/sites-available/mayan << EOF
  98. server {
  99. listen 80;
  100. server_name localhost;
  101.  
  102. location / {
  103. include uwsgi_params;
  104. uwsgi_pass unix:${INSTALLATION_DIRECTORY}uwsgi.sock;
  105.  
  106. client_max_body_size 30M; # Increse if your plan to upload bigger documents
  107. proxy_read_timeout 30s; # Increase if your document uploads take more than 30 seconds
  108. }
  109.  
  110. location /static {
  111. alias ${INSTALLATION_DIRECTORY}mayan/media/static;
  112. expires 1h;
  113. }
  114.  
  115. location /favicon.ico {
  116. alias ${INSTALLATION_DIRECTORY}mayan/media/static/appearance/images/favicon.ico;
  117. expires 1h;
  118. }
  119. }
  120. EOF
  121.  
  122. echo -e "\n -> Enabling the NGINX site for Mayan EDMS \n"
  123. ln -s /etc/nginx/sites-available/mayan /etc/nginx/sites-enabled/
  124.  
  125. echo -e "\n -> Creating the supervisor file for the uWSGI process, /etc/supervisor/conf.d/mayan-uwsgi.conf \n"
  126. cat > /etc/supervisor/conf.d/mayan-uwsgi.conf << EOF
  127. [program:mayan-uwsgi]
  128. command = ${INSTALLATION_DIRECTORY}bin/uwsgi --ini ${INSTALLATION_DIRECTORY}uwsgi.ini
  129. user = root
  130. autostart = true
  131. autorestart = true
  132. redirect_stderr = true
  133. EOF
  134.  
  135. echo -e "\n -> Creating the supervisor file for the Celery worker, /etc/supervisor/conf.d/mayan-celery.conf \n"
  136. cat > /etc/supervisor/conf.d/mayan-celery.conf << EOF
  137. [program:mayan-worker]
  138. command = ${INSTALLATION_DIRECTORY}bin/python ${INSTALLATION_DIRECTORY}bin/mayan-edms.py celery --settings=mayan.settings.production worker -Ofair -l ERROR
  139. directory = ${INSTALLATION_DIRECTORY}
  140. user = www-data
  141. stdout_logfile = /var/log/mayan/worker-stdout.log
  142. stderr_logfile = /var/log/mayan/worker-stderr.log
  143. autostart = true
  144. autorestart = true
  145. startsecs = 10
  146. stopwaitsecs = 10
  147. killasgroup = true
  148. priority = 998
  149.  
  150. [program:mayan-beat]
  151. command = ${INSTALLATION_DIRECTORY}bin/python ${INSTALLATION_DIRECTORY}bin/mayan-edms.py celery --settings=mayan.settings.production beat -l ERROR
  152. directory = ${INSTALLATION_DIRECTORY}
  153. user = www-data
  154. numprocs = 1
  155. stdout_logfile = /var/log/mayan/beat-stdout.log
  156. stderr_logfile = /var/log/mayan/beat-stderr.log
  157. autostart = true
  158. autorestart = true
  159. startsecs = 10
  160. stopwaitsecs = 1
  161. killasgroup = true
  162. priority = 998
  163. EOF
  164.  
  165. echo -e "\n -> Collecting the static files \n"
  166. mayan-edms.py collectstatic --noinput
  167.  
  168. echo -e "\n -> Making the installation directory readable and writable by the webserver user \n"
  169. chown www-data:www-data ${INSTALLATION_DIRECTORY} -R
  170.  
  171. echo -e "\n -> Restarting the services \n"
  172. /etc/init.d/nginx restart
  173. /etc/init.d/supervisor restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement