fabfile.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # @File : fabfile.py
  4. # @Author: becivells
  5. #@Contact : becivells@gmail.com
  6. # @Date : 2017/12/6
  7. #@Software : PyCharm
  8. # @Desc :
  9. from fabric.api import settings
  10. from fabric.api import cd,run,env,put
  11. from install_config import *
  12. env.hosts = ['192.168.233.136']
  13. env.user='root'
  14. env.password = 'password'
  15. def pip_mirror():
  16. run(("mkdir -p ~/.pip/ "))
  17. with cd('~/.pip/'):
  18. put(LOCAL_PIP_CONF_PATH,'~/.pip/')
  19. run('pip install -r %s' % (REMOTE_PIP_REQUIREMENT_PATH))
  20. def supervisor_install():
  21. run('yum install supervisor -y')
  22. run('mkdir -p /etc/supervisord.d/')
  23. put(LOCAL_SUPERVISORD_CONF_PATH,'/etc/')
  24. run('systemctl enable supervisord')
  25. run('systemctl start supervisord')
  26. def init():
  27. run('yum update -y && yum install epel-release && yum update -y')
  28. run('yum install -y python-pip')
  29. run('yum install -y git')
  30. def create_user():
  31. with settings(warn_only=True):
  32. run('useradd -s /usr/sbin/nologin -d {APP_USER_PATH} {APP_USER}'.format(
  33. APP_USER=APP_USER,
  34. APP_USER_PATH=APP_USER_PATH)
  35. )
  36. def upload_web():
  37. run('mkdir -p %s'%(APP_PATH))
  38. with cd(APP_PATH):
  39. put('%s/*'%(LOCAL_BASE_DIR),APP_PATH,mode=777)
  40. run('chown {APP_USER}:{APP_USER} -R {APP_PATH}'.format(
  41. APP_PATH=APP_PATH,
  42. APP_USER=APP_USER)
  43. )
  44. def web_install():
  45. init()
  46. supervisor_install()
  47. create_user()
  48. upload_web()
  49. pip_mirror()
  50. # get_config()
  51. put(LOCAL_GUNICORN_CONF_PATH, '/etc/supervisord.d/')
  52. run('systemctl daemon-reload')
  53. run('systemctl restart supervisord')
  54. run('supervisorctl reload')
  55. run('supervisorctl status')