Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Install the Basic packages for the server
- sudo su
- sudo apt-get update
- sudo apt-get -y install git
- # Install POSTGRES 9.6 and POSTGIS 2.3
- sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- sudo apt update
- sudo apt-get -y install postgresql-9.6 postgresql-contrib-9.6
- sudo apt-get -y install postgis postgresql-9.6-postgis-2.3
- sudo apt-get install postgresql-9.6-postgis-3-scripts
- # Install other packages
- sudo apt-get -y install python-pip python-dev libpq-dev
- sudo apt-get -y install build-essential
- sudo apt-get update
- sudo -H pip install --upgrade pip
- sudo -H pip install virtualenv
- sudo apt-get install unzip
- sudo apt-get install dos2unix
- sudo apt-get -y install nginx
- sudo apt-get -y install curl
- sudo pip install supervisor
- # OPTIONAL BUT NOT NECESSARY: Install stackdriver monitoring and logging agent packages
- curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
- sudo bash install-monitoring-agent.sh
- curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
- sudo bash install-logging-agent.sh
- # Create the database and execute the queries below
- sudo -u postgres psql postgres
- 1. CREATE USER ali_lms WITH PASSWORD '@L1_lM$_@dm1n';
- 2. CREATE DATABASE aligatdb WITH ENCODING = 'UTF8';
- 3. ALTER DATABASE aligatdb SET timezone TO 'Asia/Manila';
- 4. \c aligatdb
- 5. ALTER ROLE ali_lms SET client_encoding TO 'UTF8';
- 6. ALTER ROLE ali_lms SET timezone TO 'Asia/Manila';
- 7. ALTER ROLE ali_lms SET default_transaction_isolation TO 'read committed';
- 8. CREATE EXTENSION postgis;
- 9. CREATE EXTENSION postgis_topology;
- 10. GRANT ALL PRIVILEGES ON DATABASE aligatdb TO ali_lms;
- 10.1. GRANT ALL PRIVILEGES ON ALL TABLES in schema public TO ali_lms;
- 11. \password postgres
- 12. P0$+gr3$U$3r
- 13. \q
- #Create a WWW folder in /var if it does not exist yet. This is where we will place our sites and pull from repository
- sudo su
- mkdir /var/www/html
- cd /var/www/html
- #!!!!IMPORTANT ==================
- # 1. IF THIS IS YOUR LOCAL/DEV SERVER THEN USE GIT REPOSITORY
- git clone https://github.com/Navagis-LLC/ali-lms.git
- mv ali-lms ali-gat
- cd ali-gat
- git checkout -b {name of latest branch} origin/{name of latest branch}
- # 2. IF THIS IS THE PROD SERVER OF THE CLIENT THEN Download zip file base code
- wget -P /var/www/html/ "https://storage.googleapis.com/ali_deployment/GAT_QA_SPRINT_8v.zip"
- unzip GAT_QA_SPRINT_8w.zip -d /var/www/html
- #================================
- # Remove the compiled files
- find /var/www/html/ali-gat/app/. -name "*.pyc" -type f -delete
- # Create logs and documents folders
- mkdir /var/www/html/ali-gat/logs
- mkdir /var/www/html/ali-gat/logs/nginx
- mkdir /var/www/html/documents
- mkdir /var/www/html/temp
- # IF THIS IS PROD SERVER THEN USE 'ubuntu' USER. Set owner of the entire project folder to ubuntu
- sudo chown -R ubuntu:ubuntu ali-gat
- #==================================
- # Activate Virtual Environment and create user tables =======
- cd /var/www/html/ali-gat
- sudo pip install -r requirements.txt
- #1. Activate virtual environment
- virtualenv venv
- source venv/bin/activate
- #2. Install requirements
- pip install -r requirements.txt
- #3. Install npm and bower to the client/public folder
- cd /var/www/html/ali-gat/client
- sudo apt-get -y install npm
- npm install
- npm install -g bower
- #4. Open a new terminal to go back to a normal user and not a super user
- cd /var/www/html/ali-gat/client
- bower install
- #5. Copy the template settings file and modify it (Change QA to PROD if it is for prod)
- cd /var/www/html/ali-gat
- cp lms/settings.qa.py lms/settings.py
- #6. IF YOU ARE RECREATING THE DATABASE ONTO THE LOCAL SERVER THEN DO BELOW
- nano /var/www/html/ali-gat/lms/settings.py
- edit the database config to use below user since migration needs superuser
- 'NAME': 'aligatdb',
- 'USER': 'postgres',#'{THE ORIG USER}',
- 'PASSWORD': 'P0$+gr3$U$3r',#'{THE ORIG USER}',
- #6a. start the migration process
- python manage.py makemigrations
- python manage.py migrate
- #6b. Create an admin user
- python manage.py createsuperuser
- admin
- admin@navagis.com
- alilmsadmin
- alilmsadmin
- nano /var/www/html/ali-gat/lms/settings.py
- edit the database config to use the original user
- \exit
- #6c. Create tables, stored procedures, triggers and insert database defaults
- cd /var/www/html/ali-gat/database/scripts/deployments/gat_v2
- chmod +x create_tables.sh
- dos2unix create_tables.sh
- ./create_tables.sh
- chmod +x create_functions.sh
- dos2unix create_functions.sh
- ./create_functions.sh
- chmod +x create_triggers.sh
- dos2unix create_triggers.sh
- ./create_triggers.sh
- chmod +x insert_defaults.sh
- dos2unix insert_defaults.sh
- ./insert_defaults.sh
- #7. IF YOU ARE CONNECTION TO THE COMMON DATABASE SERVER THEN DO BELOW
- nano /var/www/html/ali-gat/lms/settings.py
- edit the database config to use below user since migration needs superuser
- 'NAME': '{DB NAME}',
- 'USER': '{USER TO THE DB SERVER}',
- 'PASSWORD': '{PASSWORD TO THE DB SERVER}',
- 'HOST': '{IP TO YOUR DB SERVER}'
- #==============================================
- #Setup Database Server Accessing from Web/App server
- #This is done only if the DB server is separate from Web/App server
- sudo nano /etc/postgresql/9.6/main/postgresql.conf
- Look for this line: #listen_addresses = 'localhost'
- and change it to: listen_addresses = '*'
- sudo nano /etc/postgresql/9.6/main/pg_hba.conf
- add the lines below to the end of the file
- host all all 0.0.0.0/0 md5
- hostssl all all 0.0.0.0/0 md5
- sudo service postgresql restart
- # NOTE: UPDATE the file conf/nginx.conf and change
- nano /var/www/html/ali-gat/conf/nginx.conf
- change all the paths to refer to /var/www/html/ali-gat as the base
- #Set owner of the entire project folder to ubuntu(ONLY FOR PROD SERVER)=====
- cd /var/www/html
- sudo chown -R ubuntu:ubuntu ali-gat
- #================================
- #Setup nginx file
- cd /var/www/html/ali-gat
- chmod +x /var/www/html/ali-gat/bin/setup-nginx.sh
- dos2unix /var/www/html/ali-gat/bin/setup-nginx.sh
- ./bin/setup-nginx.sh
- chmod +x /var/www/html/ali-gat/bin/run-app.sh
- dos2unix /var/www/html/ali-gat/bin/run-app.sh
- #Start the server using gunicorn rather than "python manage.py runserver"
- #because gunicorn will persist even if the command line is closed
- #2 ways to start which can be seen below:
- #Option 1a: Manual running
- cd /var/www/html/ali-gat
- ./bin/run-app.sh
- #Option 1b: Manual running the python file
- cd /var/www/html/ali-gat
- python manage.py runserver
- #Option 2: Setup a Supervisor to manage the different processes that you like to run
- #A - Install
- sudo su
- pip install supervisor
- #B - Edit contents specifically paths
- mkdir /var/www/html/ali-gat/logs
- nano /var/www/html/ali-gat/conf/supervisord.conf
- #C - register new supervisor
- supervisord -c /var/www/html/ali-gat/conf/supervisord.conf
- supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf update
- supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf reread
- #D - check if gunicorn has already started listening. replace port number below to the port specified on the run-app.sh
- lsof -i :{port #}
- #E - if you want to stop gunicorn run the command below. If processes are still running then manually execute the kill commands below
- supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf stop all
- lsof -i :{port #}
- kill -9 {pid}
- #F - if gunicorn has not yet started then start it using supervisorctl command
- supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf start all
- #G - you can check status of supervisor by running the script below
- supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf status
- #H - if the program has stopped, you can restart it using its program name
- supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf restart ali_lms
- #When server is restarted, SUPERVISOR needs to start. We can do this by
- sudo nano /etc/rc.local
- #adding the lines below to rc.local
- sudo supervisord -c /var/www/html/ali-gat/conf/supervisord.conf
- sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf update
- sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf reread
- sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf restart ali_lms
- # Restart nginx web server
- sudo /etc/init.d/nginx restart
- # Restart Supervisor
- sudo su
- chmod +x /var/www/html/ali-gat/bin/setup-nginx.sh
- dos2unix /var/www/html/ali-gat/bin/setup-nginx.sh
- ./bin/setup-nginx.sh
- chmod +x /var/www/html/ali-gat/bin/run-app.sh
- dos2unix /var/www/html/ali-gat/bin/run-app.sh
- sudo supervisord -c /var/www/html/ali-gat/conf/supervisord.conf
- sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf reread
- sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf update
- sudo supervisorctl -c /var/www/html/ali-gat/conf/supervisord.conf restart ali_gat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement