Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.92 KB | None | 0 0
  1. # Install the Basic packages for the server
  2. sudo su
  3. sudo apt-get update
  4. sudo apt-get -y install git
  5.  
  6. # Install POSTGRES 9.6 and POSTGIS 2.3
  7. sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
  8. wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  9. sudo apt update
  10. sudo apt-get -y install postgresql-9.6 postgresql-contrib-9.6
  11. sudo apt-get -y install postgis postgresql-9.6-postgis-2.3
  12. sudo apt-get install postgresql-9.6-postgis-3-scripts
  13.  
  14. # Install other packages
  15. sudo apt-get -y install python-pip python-dev libpq-dev
  16. sudo apt-get -y install build-essential
  17. sudo apt-get update
  18. sudo -H pip install --upgrade pip
  19. sudo -H pip install virtualenv
  20. sudo apt-get install unzip
  21. sudo apt-get install dos2unix
  22. sudo apt-get -y install nginx
  23. sudo apt-get -y install curl
  24. sudo pip install supervisor
  25.  
  26.  
  27. # OPTIONAL BUT NOT NECESSARY: Install stackdriver monitoring and logging agent packages
  28. curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
  29. sudo bash install-monitoring-agent.sh
  30. curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
  31. sudo bash install-logging-agent.sh
  32.  
  33. # Create the database and execute the queries below
  34. sudo -u postgres psql postgres
  35. 1. CREATE USER ali_lms WITH PASSWORD '@L1_lM$_@dm1n';
  36. 2. CREATE DATABASE aligatdb WITH ENCODING = 'UTF8';
  37. 3. ALTER DATABASE aligatdb SET timezone TO 'Asia/Manila';
  38. 4. \c aligatdb
  39. 5. ALTER ROLE ali_lms SET client_encoding TO 'UTF8';
  40. 6. ALTER ROLE ali_lms SET timezone TO 'Asia/Manila';
  41. 7. ALTER ROLE ali_lms SET default_transaction_isolation TO 'read committed';
  42. 8. CREATE EXTENSION postgis;
  43. 9. CREATE EXTENSION postgis_topology;
  44. 10. GRANT ALL PRIVILEGES ON DATABASE aligatdb TO ali_lms;
  45. 10.1. GRANT ALL PRIVILEGES ON ALL TABLES in schema public TO ali_lms;
  46. 11. \password postgres
  47. 12. P0$+gr3$U$3r
  48. 13. \q
  49.  
  50. #Create a WWW folder in /var if it does not exist yet. This is where we will place our sites and pull from repository
  51. sudo su
  52. mkdir /var/www/html
  53. cd /var/www/html
  54.  
  55. #!!!!IMPORTANT ==================
  56. # 1. IF THIS IS YOUR LOCAL/DEV SERVER THEN USE GIT REPOSITORY
  57. git clone https://github.com/Navagis-LLC/ali-lms.git
  58. mv ali-lms ali-gat
  59. cd ali-gat
  60. git checkout -b {name of latest branch} origin/{name of latest branch}
  61.  
  62.  
  63. # 2. IF THIS IS THE PROD SERVER OF THE CLIENT THEN Download zip file base code
  64. wget -P /var/www/html/ "https://storage.googleapis.com/ali_deployment/GAT_QA_SPRINT_8v.zip"
  65. unzip GAT_QA_SPRINT_8w.zip -d /var/www/html
  66. #================================
  67.  
  68. # Remove the compiled files
  69. find /var/www/html/ali-gat/app/. -name "*.pyc" -type f -delete
  70.  
  71. # Create logs and documents folders
  72. mkdir /var/www/html/ali-gat/logs
  73. mkdir /var/www/html/ali-gat/logs/nginx
  74. mkdir /var/www/html/documents
  75. mkdir /var/www/html/temp
  76.  
  77. # IF THIS IS PROD SERVER THEN USE 'ubuntu' USER. Set owner of the entire project folder to ubuntu
  78. sudo chown -R ubuntu:ubuntu ali-gat
  79. #==================================
  80.  
  81.  
  82. # Activate Virtual Environment and create user tables =======
  83. cd /var/www/html/ali-gat
  84. sudo pip install -r requirements.txt
  85. #1. Activate virtual environment
  86. virtualenv venv
  87. source venv/bin/activate
  88. #2. Install requirements
  89. pip install -r requirements.txt
  90. #3. Install npm and bower to the client/public folder
  91. cd /var/www/html/ali-gat/client
  92. sudo apt-get -y install npm
  93. npm install
  94. npm install -g bower
  95. #4. Open a new terminal to go back to a normal user and not a super user
  96. cd /var/www/html/ali-gat/client
  97. bower install
  98. #5. Copy the template settings file and modify it (Change QA to PROD if it is for prod)
  99. cd /var/www/html/ali-gat
  100. cp lms/settings.qa.py lms/settings.py
  101.  
  102. #6. IF YOU ARE RECREATING THE DATABASE ONTO THE LOCAL SERVER THEN DO BELOW
  103. nano /var/www/html/ali-gat/lms/settings.py
  104. edit the database config to use below user since migration needs superuser
  105. 'NAME': 'aligatdb',
  106. 'USER': 'postgres',#'{THE ORIG USER}',
  107. 'PASSWORD': 'P0$+gr3$U$3r',#'{THE ORIG USER}',
  108. #6a. start the migration process
  109. python manage.py makemigrations
  110. python manage.py migrate
  111. #6b. Create an admin user
  112. python manage.py createsuperuser
  113. admin
  114. admin@navagis.com
  115. alilmsadmin
  116. alilmsadmin
  117. nano /var/www/html/ali-gat/lms/settings.py
  118. edit the database config to use the original user
  119. \exit
  120. #6c. Create tables, stored procedures, triggers and insert database defaults
  121. cd /var/www/html/ali-gat/database/scripts/deployments/gat_v2
  122. chmod +x create_tables.sh
  123. dos2unix create_tables.sh
  124. ./create_tables.sh
  125. chmod +x create_functions.sh
  126. dos2unix create_functions.sh
  127. ./create_functions.sh
  128. chmod +x create_triggers.sh
  129. dos2unix create_triggers.sh
  130. ./create_triggers.sh
  131. chmod +x insert_defaults.sh
  132. dos2unix insert_defaults.sh
  133. ./insert_defaults.sh
  134.  
  135. #7. IF YOU ARE CONNECTION TO THE COMMON DATABASE SERVER THEN DO BELOW
  136. nano /var/www/html/ali-gat/lms/settings.py
  137. edit the database config to use below user since migration needs superuser
  138. 'NAME': '{DB NAME}',
  139. 'USER': '{USER TO THE DB SERVER}',
  140. 'PASSWORD': '{PASSWORD TO THE DB SERVER}',
  141. 'HOST': '{IP TO YOUR DB SERVER}'
  142. #==============================================
  143.  
  144.  
  145. #Setup Database Server Accessing from Web/App server
  146. #This is done only if the DB server is separate from Web/App server
  147. sudo nano /etc/postgresql/9.6/main/postgresql.conf
  148. Look for this line: #listen_addresses = 'localhost'
  149. and change it to: listen_addresses = '*'
  150. sudo nano /etc/postgresql/9.6/main/pg_hba.conf
  151. add the lines below to the end of the file
  152. host all all 0.0.0.0/0 md5
  153. hostssl all all 0.0.0.0/0 md5
  154. sudo service postgresql restart
  155.  
  156.  
  157. # NOTE: UPDATE the file conf/nginx.conf and change
  158. nano /var/www/html/ali-gat/conf/nginx.conf
  159. change all the paths to refer to /var/www/html/ali-gat as the base
  160.  
  161. #Set owner of the entire project folder to ubuntu(ONLY FOR PROD SERVER)=====
  162. cd /var/www/html
  163. sudo chown -R ubuntu:ubuntu ali-gat
  164. #================================
  165.  
  166. #Setup nginx file
  167. cd /var/www/html/ali-gat
  168. chmod +x /var/www/html/ali-gat/bin/setup-nginx.sh
  169. dos2unix /var/www/html/ali-gat/bin/setup-nginx.sh
  170. ./bin/setup-nginx.sh
  171. chmod +x /var/www/html/ali-gat/bin/run-app.sh
  172. dos2unix /var/www/html/ali-gat/bin/run-app.sh
  173.  
  174.  
  175. #Start the server using gunicorn rather than "python manage.py runserver"
  176. #because gunicorn will persist even if the command line is closed
  177. #2 ways to start which can be seen below:
  178.  
  179. #Option 1a: Manual running
  180. cd /var/www/html/ali-gat
  181. ./bin/run-app.sh
  182.  
  183. #Option 1b: Manual running the python file
  184. cd /var/www/html/ali-gat
  185. python manage.py runserver
  186.  
  187. #Option 2: Setup a Supervisor to manage the different processes that you like to run
  188. #A - Install
  189. sudo su
  190. pip install supervisor
  191. #B - Edit contents specifically paths
  192. mkdir /var/www/html/ali-gat/logs
  193. nano /var/www/html/ali-gat/conf/supervisord.conf
  194. #C - register new supervisor
  195. supervisord -c /var/www/html/ali-gat/conf/supervisord.conf
  196. supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf update
  197. supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf reread
  198. #D - check if gunicorn has already started listening. replace port number below to the port specified on the run-app.sh
  199. lsof -i :{port #}
  200. #E - if you want to stop gunicorn run the command below. If processes are still running then manually execute the kill commands below
  201. supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf stop all
  202. lsof -i :{port #}
  203. kill -9 {pid}
  204. #F - if gunicorn has not yet started then start it using supervisorctl command
  205. supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf start all
  206. #G - you can check status of supervisor by running the script below
  207. supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf status
  208. #H - if the program has stopped, you can restart it using its program name
  209. supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf restart ali_lms
  210.  
  211.  
  212. #When server is restarted, SUPERVISOR needs to start. We can do this by
  213. sudo nano /etc/rc.local
  214. #adding the lines below to rc.local
  215. sudo supervisord -c /var/www/html/ali-gat/conf/supervisord.conf
  216. sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf update
  217. sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf reread
  218. sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf restart ali_lms
  219.  
  220. # Restart nginx web server
  221. sudo /etc/init.d/nginx restart
  222.  
  223. # Restart Supervisor
  224. sudo su
  225. chmod +x /var/www/html/ali-gat/bin/setup-nginx.sh
  226. dos2unix /var/www/html/ali-gat/bin/setup-nginx.sh
  227. ./bin/setup-nginx.sh
  228. chmod +x /var/www/html/ali-gat/bin/run-app.sh
  229. dos2unix /var/www/html/ali-gat/bin/run-app.sh
  230. sudo supervisord -c /var/www/html/ali-gat/conf/supervisord.conf
  231. sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf reread
  232. sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf update
  233. sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf restart ali_gat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement