You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # imports - module imports
  2. from bench.utils import run_playbook
  3. from bench.utils.system import setup_sudoers
  4. # imports - third party imports
  5. import click
  6. extra_vars = {"production": True}
  7. @click.group(help="Install system dependencies for setting up Xhiveframework environment")
  8. def install():
  9. pass
  10. @click.command(
  11. "prerequisites",
  12. help="Installs pre-requisite libraries, essential tools like b2zip, htop, screen, vim, x11-fonts, python libs, cups and Redis",
  13. )
  14. def install_prerequisites():
  15. run_playbook("site.yml", tag="common, redis")
  16. @click.command(
  17. "mariadb", help="Install and setup MariaDB of specified version and root password"
  18. )
  19. @click.option("--mysql_root_password", "--mysql-root-password",
  20. "--mariadb_root_password", "--mariadb-root-password", default="")
  21. @click.option("--version", default="10.3")
  22. def install_mariadb(mysql_root_password, version):
  23. if mysql_root_password:
  24. extra_vars.update(
  25. {
  26. "mysql_root_password": mysql_root_password,
  27. }
  28. )
  29. extra_vars.update({"mariadb_version": version})
  30. run_playbook("site.yml", extra_vars=extra_vars, tag="mariadb")
  31. @click.command("wkhtmltopdf", help="Installs wkhtmltopdf v0.12.3 for linux")
  32. def install_wkhtmltopdf():
  33. run_playbook("site.yml", extra_vars=extra_vars, tag="wkhtmltopdf")
  34. @click.command("nodejs", help="Installs Node.js v8")
  35. def install_nodejs():
  36. run_playbook("site.yml", extra_vars=extra_vars, tag="nodejs")
  37. @click.command("psutil", help="Installs psutil via pip")
  38. def install_psutil():
  39. run_playbook("site.yml", extra_vars=extra_vars, tag="psutil")
  40. @click.command(
  41. "supervisor",
  42. help="Installs supervisor. If user is specified, sudoers is setup for that user",
  43. )
  44. @click.option("--user")
  45. def install_supervisor(user=None):
  46. run_playbook("site.yml", extra_vars=extra_vars, tag="supervisor")
  47. if user:
  48. setup_sudoers(user)
  49. @click.command(
  50. "nginx", help="Installs NGINX. If user is specified, sudoers is setup for that user"
  51. )
  52. @click.option("--user")
  53. def install_nginx(user=None):
  54. run_playbook("site.yml", extra_vars=extra_vars, tag="nginx")
  55. if user:
  56. setup_sudoers(user)
  57. @click.command("virtualbox", help="Installs virtualbox")
  58. def install_virtualbox():
  59. run_playbook("vm_build.yml", tag="virtualbox")
  60. @click.command("packer", help="Installs Oracle virtualbox and packer 1.2.1")
  61. def install_packer():
  62. run_playbook("vm_build.yml", tag="packer")
  63. @click.command(
  64. "fail2ban",
  65. help="Install fail2ban, an intrusion prevention software framework that protects computer servers from brute-force attacks",
  66. )
  67. @click.option(
  68. "--maxretry",
  69. default=6,
  70. help="Number of matches (i.e. value of the counter) which triggers ban action on the IP.",
  71. )
  72. @click.option(
  73. "--bantime",
  74. default=600,
  75. help="The counter is set to zero if no match is found within 'findtime' seconds.",
  76. )
  77. @click.option(
  78. "--findtime",
  79. default=600,
  80. help='Duration (in seconds) for IP to be banned for. Negative number for "permanent" ban.',
  81. )
  82. def install_failtoban(**kwargs):
  83. extra_vars.update(kwargs)
  84. run_playbook("site.yml", extra_vars=extra_vars, tag="fail2ban")
  85. install.add_command(install_prerequisites)
  86. install.add_command(install_mariadb)
  87. install.add_command(install_wkhtmltopdf)
  88. install.add_command(install_nodejs)
  89. install.add_command(install_psutil)
  90. install.add_command(install_supervisor)
  91. install.add_command(install_nginx)
  92. install.add_command(install_failtoban)
  93. install.add_command(install_virtualbox)
  94. install.add_command(install_packer)