2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-12 00:06:36 +00:00

refactor: bench.command.install

* sorted imports
    * consistent formatting and use of docstrings
    * help added for click commands
This commit is contained in:
Gavin D'souza 2020-02-18 12:24:18 +05:30
parent 9621686597
commit 063e4a85be

View File

@ -1,21 +1,34 @@
import os, sys, json, click # imports - standard imports
import os
import sys
import json
# imports - module imports
from bench.utils import run_playbook, setup_sudoers, is_root from bench.utils import run_playbook, setup_sudoers, is_root
extra_vars = {"production": True} # imports - third party imports
import click
@click.group()
extra_vars = {
"production": True
}
@click.group(help="Install system dependencies for setting up Frappe environment")
def install(): def install():
"Install system dependancies"
pass pass
@click.command('prerequisites') @click.command('prerequisites')
def install_prerequisites(): def install_prerequisites():
run_playbook('site.yml', tag='common, redis') run_playbook('site.yml', tag='common, redis')
@click.command('mariadb')
@click.option('--mysql_root_password') @click.command('mariadb', help="Install and setup MariaDB of specified version and root password")
@click.option('--mysql_root_password', '--mysql-root-password', default="")
@click.option('--version', default="10.3") @click.option('--version', default="10.3")
def install_maridb(mysql_root_password='', version=''): def install_maridb(mysql_root_password, version):
if mysql_root_password: if mysql_root_password:
extra_vars.update({ extra_vars.update({
"mysql_root_password": mysql_root_password, "mysql_root_password": mysql_root_password,
@ -27,41 +40,49 @@ def install_maridb(mysql_root_password='', version=''):
run_playbook('site.yml', extra_vars=extra_vars, tag='mariadb') run_playbook('site.yml', extra_vars=extra_vars, tag='mariadb')
@click.command('wkhtmltopdf')
@click.command('wkhtmltopdf', help="Installs wkhtmltopdf v0.12.3 for linux")
def install_wkhtmltopdf(): def install_wkhtmltopdf():
run_playbook('site.yml', extra_vars=extra_vars, tag='wkhtmltopdf') run_playbook('site.yml', extra_vars=extra_vars, tag='wkhtmltopdf')
@click.command('nodejs')
@click.command('nodejs', help="Installs Node.js v8")
def install_nodejs(): def install_nodejs():
run_playbook('site.yml', extra_vars=extra_vars, tag='nodejs') run_playbook('site.yml', extra_vars=extra_vars, tag='nodejs')
@click.command('psutil')
@click.command('psutil', help="Installs psutil via pip")
def install_psutil(): def install_psutil():
run_playbook('site.yml', extra_vars=extra_vars, tag='psutil') run_playbook('site.yml', extra_vars=extra_vars, tag='psutil')
@click.command('supervisor')
@click.command('supervisor', help="Installs supervisor. If user is specified, sudoers is setup for that user")
@click.option('--user') @click.option('--user')
def install_supervisor(user=None): def install_supervisor(user=None):
run_playbook('site.yml', extra_vars=extra_vars, tag='supervisor') run_playbook('site.yml', extra_vars=extra_vars, tag='supervisor')
if user: if user:
setup_sudoers(user) setup_sudoers(user)
@click.command('nginx')
@click.command('nginx', help="Installs NGINX. If user is specified, sudoers is setup for that user")
@click.option('--user') @click.option('--user')
def install_nginx(user=None): def install_nginx(user=None):
run_playbook('site.yml', extra_vars=extra_vars, tag='nginx') run_playbook('site.yml', extra_vars=extra_vars, tag='nginx')
if user: if user:
setup_sudoers(user) setup_sudoers(user)
@click.command('virtualbox')
@click.command('virtualbox', help="Installs supervisor")
def install_virtualbox(): def install_virtualbox():
run_playbook('vm_build.yml', tag='virtualbox') run_playbook('vm_build.yml', tag='virtualbox')
@click.command('packer')
@click.command('packer', help="Installs Oracle virtualbox and packer 1.2.1")
def install_packer(): def install_packer():
run_playbook('vm_build.yml', tag='packer') run_playbook('vm_build.yml', tag='packer')
@click.command('fail2ban')
@click.command("fail2ban", help="Install fail2ban, an intrusion prevention software framework that protects computer servers from brute-force attacks")
@click.option('--maxretry', default=6, help="Number of matches (i.e. value of the counter) which triggers ban action on the IP.") @click.option('--maxretry', default=6, help="Number of matches (i.e. value of the counter) which triggers ban action on the IP.")
@click.option('--bantime', default=600, help="The counter is set to zero if no match is found within 'findtime' seconds.") @click.option('--bantime', default=600, help="The counter is set to zero if no match is found within 'findtime' seconds.")
@click.option('--findtime', default=600, help='Duration (in seconds) for IP to be banned for. Negative number for "permanent" ban.') @click.option('--findtime', default=600, help='Duration (in seconds) for IP to be banned for. Negative number for "permanent" ban.')
@ -69,6 +90,7 @@ def install_failtoban(**kwargs):
extra_vars.update(kwargs) extra_vars.update(kwargs)
run_playbook('site.yml', extra_vars=extra_vars, tag='fail2ban') run_playbook('site.yml', extra_vars=extra_vars, tag='fail2ban')
install.add_command(install_prerequisites) install.add_command(install_prerequisites)
install.add_command(install_maridb) install.add_command(install_maridb)
install.add_command(install_wkhtmltopdf) install.add_command(install_wkhtmltopdf)