himanshu208

Untitled

Sep 22nd, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. from fabric import *
  2. from fabric import transfer
  3. #connecting to the instance
  4. c = Connection('i-0a1fc1786ff0ca089')
  5. #installing the packages - nginx,unzip, pip, virtualenv
  6. c.sudo('apt-get update')
  7. c.sudo('apt-get install nginx -y')
  8. c.sudo('apt-get install unzip -y')
  9. c.sudo('apt install python-pip -y')
  10. c.sudo('apt-get install python3-venv -y')
  11. #creating a virtualenv for our django project
  12. c.sudo('mkdir -p /opt/wwc/mysites')
  13. c.sudo('python3 -m venv /opt/wwc/mysites/virtualenv')
  14. #setting permission to ubuntu user to run everything smoothly
  15. c.sudo('chown -R ubuntu:ubuntu /opt/wwc/*')
  16. #installing django project dependencies
  17. c.run('/opt/wwc/mysites/virtualenv/bin/pip install "django==2.1"')
  18. c.run('/opt/wwc/mysites/virtualenv/bin/pip install boto3')
  19. #importing the project from local server to the instance
  20. c.put('lab.zip', remote='/opt/wwc/mysites/', preserve_mode=True)
  21. #copying the nginx config file from local to instance
  22. c.put('default.txt', remote='/opt/wwc/mysites/', preserve_mode=True)
  23. c.sudo('rm /etc/nginx/sites-available/default')
  24. c.sudo('mv /opt/wwc/mysites/default.txt /etc/nginx/sites-available/default')
  25. #restarting nginx to impliment changes to config file
  26. c.sudo('service nginx restart')
  27. #extracting the project
  28. c.sudo('unzip /opt/wwc/mysites/lab.zip -d /opt/wwc/mysites/')
  29. #running the server
  30. c.sudo('/opt/wwc/mysites/virtualenv/bin/python /opt/wwc/mysites/lab/manage.py runserver 8000')
Add Comment
Please, Sign In to add comment