From 549d442aa784fb7790d6a29157a853b41bf34e0d Mon Sep 17 00:00:00 2001 From: hansel Date: Tue, 6 Jun 2017 12:40:11 +0800 Subject: [PATCH 01/16] use certbot with -n option allows us to use yes | bench setup lets-encrypt {clientsite} it gets rid of certbot prompt Cert not yet due for renewal You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry. (ref: /etc/letsencrypt/renewal/stupidclientid.erp.openb.net.conf) What would you like to do? ------------------------------------------------------------------------------- 1: Keep the existing certificate for now 2: Renew & replace the cert (limit ~5 per 7 days) ------------------------------------------------------------------------------- automatically chooses option 1 --- bench/config/lets_encrypt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/config/lets_encrypt.py b/bench/config/lets_encrypt.py index f09a75bf..63be14dc 100755 --- a/bench/config/lets_encrypt.py +++ b/bench/config/lets_encrypt.py @@ -56,7 +56,7 @@ def run_certbot_and_setup_ssl(site, custom_domain, bench_path): get_certbot() try: - exec_cmd("{path} --config /etc/letsencrypt/configs/{site}.cfg certonly".format(path=get_certbot_path(), site=custom_domain or site)) + exec_cmd("{path} -n --config /etc/letsencrypt/configs/{site}.cfg certonly".format(path=get_certbot_path(), site=custom_domain or site)) except CommandFailedError: service('nginx', 'start') print("There was a problem trying to setup SSL for your site") From 794287d971a4c25a5bc9972bb4da29ab8b3f0fa9 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 5 Jul 2017 09:19:01 +0530 Subject: [PATCH 02/16] [fixes] --- bench/app.py | 4 ++-- bench/commands/__init__.py | 3 +-- bench/commands/make.py | 10 ---------- bench/commands/setup.py | 5 +++-- bench/config/production_setup.py | 6 +++--- bench/utils.py | 16 +--------------- 6 files changed, 10 insertions(+), 34 deletions(-) diff --git a/bench/app.py b/bench/app.py index 281a0f8f..84827ea8 100755 --- a/bench/app.py +++ b/bench/app.py @@ -55,7 +55,7 @@ def get_app(git_url, branch=None, bench_path='.', build_asset_files=True, verbos #Gets repo name from URL repo_name = git_url.rsplit('/', 1)[1].rsplit('.', 1)[0] logger.info('getting app {}'.format(repo_name)) - shallow_clone = '--depth 1' if check_git_for_shallow_clone() else '' + shallow_clone = '--depth 1 --no-single-branch' if check_git_for_shallow_clone() else '' branch = '--branch {branch}'.format(branch=branch) if branch else '' exec_cmd("git clone {git_url} {branch} {shallow_clone} --origin upstream".format( @@ -135,7 +135,7 @@ def remove_app(app, bench_path='.'): def pull_all_apps(bench_path='.', reset=False): '''Check all apps if there no local changes, pull''' rebase = '--rebase' if get_config(bench_path).get('rebase_on_pull') else '' - + # chech for local changes if not reset: for app in get_apps(bench_path=bench_path): diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index 1bf61806..e31debab 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -21,12 +21,11 @@ def bench_command(bench_path='.'): setup_logging(bench_path=bench_path) -from bench.commands.make import init, get_app, new_app, remove_app, new_site +from bench.commands.make import init, get_app, new_app, remove_app bench_command.add_command(init) bench_command.add_command(get_app) bench_command.add_command(new_app) bench_command.add_command(remove_app) -bench_command.add_command(new_site) from bench.commands.update import update, retry_upgrade, switch_to_branch, switch_to_master, switch_to_develop diff --git a/bench/commands/make.py b/bench/commands/make.py index 8059f62f..e8a0d893 100755 --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -46,13 +46,3 @@ def remove_app(app_name): remove_app(app_name) -@click.command('new-site') -@click.option('--mariadb-root-password', help="MariaDB root password") -@click.option('--admin-password', help="admin password to set for site") -@click.argument('site') -def new_site(site, mariadb_root_password=None, admin_password=None): - "Create a new site in the bench" - from bench.utils import new_site - new_site(site, mariadb_root_password=mariadb_root_password, admin_password=admin_password) - - diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 76921023..5c635933 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -49,11 +49,12 @@ def setup_fonts(): @click.command('production') +@click.option('--yes', is_flag=True, default=False, help='Dont prompt for confirmation') @click.argument('user') -def setup_production(user): +def setup_production(user, yes=False): "setup bench for production" from bench.config.production_setup import setup_production - setup_production(user=user) + setup_production(user=user, yes=yes) @click.command('auto-update') diff --git a/bench/config/production_setup.py b/bench/config/production_setup.py index 3106f41f..afde3ff8 100755 --- a/bench/config/production_setup.py +++ b/bench/config/production_setup.py @@ -3,9 +3,9 @@ from bench.config.supervisor import generate_supervisor_config from bench.config.nginx import make_nginx_conf import os, subprocess -def setup_production(user, bench_path='.'): - generate_supervisor_config(bench_path=bench_path, user=user) - make_nginx_conf(bench_path=bench_path) +def setup_production(user, bench_path='.', yes=False): + generate_supervisor_config(bench_path=bench_path, user=user, yes=yes) + make_nginx_conf(bench_path=bench_path, yes=yes) fix_prod_setup_perms(bench_path, frappe_user=user) remove_default_nginx_configs() diff --git a/bench/utils.py b/bench/utils.py index 8ef8b70a..bd82d835 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -139,20 +139,6 @@ def setup_env(bench_path='.'): def setup_socketio(bench_path='.'): exec_cmd("npm install socket.io redis express superagent cookie", cwd=bench_path) -def new_site(site, mariadb_root_password=None, admin_password=None, bench_path='.'): - logger.info('creating new site {}'.format(site)) - mariadb_root_password_fragment = '--root_password {}'.format(mariadb_root_password) if mariadb_root_password else '' - admin_password_fragment = '--admin_password {}'.format(admin_password) if admin_password else '' - exec_cmd("{frappe} {site} --install {db_name} {mariadb_root_password_fragment} {admin_password_fragment}".format( - frappe=get_frappe(bench_path=bench_path), - site=site, - db_name = hashlib.sha1(site).hexdigest()[:10], - mariadb_root_password_fragment=mariadb_root_password_fragment, - admin_password_fragment=admin_password_fragment - ), cwd=os.path.join(bench_path, 'sites')) - if len(get_sites(bench_path=bench_path)) == 1: - exec_cmd("{frappe} --use {site}".format(frappe=get_frappe(bench_path=bench_path), site=site), cwd=os.path.join(bench_path, 'sites')) - def patch_sites(bench_path='.'): bench.set_frappe_version(bench_path=bench_path) @@ -601,7 +587,7 @@ def update_translations(app, lang): f.flush() print('downloaded for', app, lang) - + def download_chart_of_accounts(): charts_dir = os.path.join('apps', "erpnext", "erpnext", 'accounts', 'chart_of_accounts', "submitted") csv_file = os.path.join(translations_dir, lang + '.csv') From 9b24458a9685ce6e1459cf865660573f47bbe7cc Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Mon, 9 Apr 2018 11:43:07 +0530 Subject: [PATCH 03/16] Set default shell as bash for frappe user - Commented the reason for using particular version of wkhtmltopdf - Changes the default shell to bash for frappe user --- playbooks/create_user.yml | 2 ++ playbooks/roles/wkhtmltopdf/tasks/main.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/playbooks/create_user.yml b/playbooks/create_user.yml index 38295f3f..acda02e2 100644 --- a/playbooks/create_user.yml +++ b/playbooks/create_user.yml @@ -33,4 +33,6 @@ recurse: yes when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'CentOS' or ansible_distribution == 'Debian' + - name: Change default shell to bash + shell: "chsh {{ frappe_user }} -s $(which bash)" ... \ No newline at end of file diff --git a/playbooks/roles/wkhtmltopdf/tasks/main.yml b/playbooks/roles/wkhtmltopdf/tasks/main.yml index ba5ee81f..18ea0016 100644 --- a/playbooks/roles/wkhtmltopdf/tasks/main.yml +++ b/playbooks/roles/wkhtmltopdf/tasks/main.yml @@ -17,6 +17,8 @@ - xfonts-base when: ansible_os_family == 'Debian' +# wkhtmltopdf has been locked down to 0.12.3 intentionally since 0.12.4 has problems. +# I you want to upgrade try it on multiple platforms and then decide - name: download wkthmltox linux get_url: url=https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-{{ "amd64" if ansible_architecture == "x86_64" else "i386"}}.tar.xz dest=/tmp/wkhtmltox.tar.xz From 4061c811d8c2745cb5025422570739b98477d292 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Mon, 9 Apr 2018 11:53:51 +0530 Subject: [PATCH 04/16] Added option to set default site name --- playbooks/roles/bench/tasks/main.yml | 2 +- playbooks/roles/bench/tasks/setup_erpnext.yml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/playbooks/roles/bench/tasks/main.yml b/playbooks/roles/bench/tasks/main.yml index b6230e80..0a963b30 100644 --- a/playbooks/roles/bench/tasks/main.yml +++ b/playbooks/roles/bench/tasks/main.yml @@ -63,7 +63,7 @@ creates: "{{ bench_path }}/config/redis_socketio.conf" chdir: "{{ bench_path }}" - # Setup an ERPNext site called site1.local + # Setup an ERPNext site - include_tasks: setup_erpnext.yml when: not run_travis diff --git a/playbooks/roles/bench/tasks/setup_erpnext.yml b/playbooks/roles/bench/tasks/setup_erpnext.yml index 15e5106d..b7f83691 100644 --- a/playbooks/roles/bench/tasks/setup_erpnext.yml +++ b/playbooks/roles/bench/tasks/setup_erpnext.yml @@ -10,18 +10,18 @@ chdir: "{{ bench_path }}" when: not app.stat.exists - - name: Check whether a site called site1.local exists - stat: path="{{ bench_path }}/sites/site1.local" + - name: Check whether the site already exists + stat: path="{{ bench_path }}/sites/{{ site }}" register: site_folder - name: Create a new site - command: bench new-site site1.local --admin-password {{ admin_password }} --mariadb-root-password {{ mysql_root_password }} + command: "bench new-site {{ site }} --admin-password {{ admin_password }} --mariadb-root-password {{ mysql_root_password }}" args: chdir: "{{ bench_path }}" when: not site_folder.stat.exists - name: Install ERPNext to default site - command: bench --site site1.local install-app erpnext + command: "bench --site {{ site }} install-app erpnext" args: chdir: "{{ bench_path }}" ... \ No newline at end of file From dd20a9a8e0ab43d043a5aa3226e347a254cd0eee Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Mon, 9 Apr 2018 11:59:12 +0530 Subject: [PATCH 05/16] removed unnecessary install shell script --- install_scripts/setup_frappe.sh | 483 -------------------------------- 1 file changed, 483 deletions(-) delete mode 100755 install_scripts/setup_frappe.sh diff --git a/install_scripts/setup_frappe.sh b/install_scripts/setup_frappe.sh deleted file mode 100755 index e6c7ac7c..00000000 --- a/install_scripts/setup_frappe.sh +++ /dev/null @@ -1,483 +0,0 @@ -#!/bin/bash - -set -e - - -## Utils - -print_msg() { - echo "Frappe password: $FRAPPE_USER_PASS" - echo "MariaDB root password: $MSQ_PASS" - echo "Administrator password: $ADMIN_PASS" -} - -get_passwd() { - echo `cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1` -} - -set_opts () { - OPTS=`getopt -o v --long verbose,mysql-root-password:,frappe-user:,bench-branch:,setup-production,skip-install-bench,skip-setup-bench,help -n 'parse-options' -- "$@"` - - if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi - - eval set -- "$OPTS" - - VERBOSE=false - HELP=false - FRAPPE_USER=false - BENCH_BRANCH="master" - SETUP_PROD=false - INSTALL_BENCH=true - SETUP_BENCH=true - - if [ -f ~/frappe_passwords.sh ]; then - source ~/frappe_passwords.sh - else - FRAPPE_USER_PASS=`get_passwd` - MSQ_PASS=`get_passwd` - ADMIN_PASS=`get_passwd` - - echo "FRAPPE_USER_PASS=$FRAPPE_USER_PASS" > ~/frappe_passwords.sh - echo "MSQ_PASS=$MSQ_PASS" >> ~/frappe_passwords.sh - echo "ADMIN_PASS=$ADMIN_PASS" >> ~/frappe_passwords.sh - fi - - while true; do - case "$1" in - -v | --verbose ) VERBOSE=true; shift ;; - -h | --help ) HELP=true; shift ;; - --mysql-root-password ) MSQ_PASS="$2"; shift; shift ;; - --frappe-user ) FRAPPE_USER="$2"; shift; shift ;; - --setup-production ) SETUP_PROD=true; shift;; - --bench-branch ) BENCH_BRANCH="$2"; shift;; - --skip-setup-bench ) SETUP_BENCH=false; shift;; - --skip-install-bench ) INSTALL_BENCH=false; shift;; - -- ) shift; break ;; - * ) break ;; - esac - done -} - -get_distro() { - ARCH=$(uname -m | sed 's/x86_/amd/;s/i[3-6]86/x86/') - - if [ $ARCH == "amd64" ]; then - T_ARCH="x86_64" - WK_ARCH="amd64" - else - T_ARCH="i386" - WK_ARCH="i386" - fi - - if [ -f /etc/redhat-release ]; then - OS="centos" - OS_VER=`cat /etc/redhat-release | sed 's/Linux\ //g' | cut -d" " -f3 | cut -d. -f1` - - elif [ -f /etc/lsb-release ]; then - . /etc/lsb-release - OS=$DISTRIB_ID - OS_VER=$DISTRIB_CODENAME - - elif [ -f /etc/debian_version ]; then - . /etc/os-release - OS="debian" # XXX or Ubuntu?? - OS_VER=$VERSION_ID - fi - - export OS=$OS - export OS_VER=$OS_VER - export ARCH=$ARCH - export T_ARCH=$T_ARCH - export WK_ARCH=$WK_ARCH - echo Installing for $OS $OS_VER $ARCH - echo "In case you encounter an error, you can post on https://discuss.frappe.io" - echo -} - -run_cmd() { - if $VERBOSE; then - "$@" - else - # $@ - "$@" > /tmp/cmdoutput.txt 2>&1 || (cat /tmp/cmdoutput.txt && exit 1) - fi -} - -## add repos - -add_centos6_mariadb_repo() { - echo " -[mariadb] -name = MariaDB -baseurl = http://yum.mariadb.org/10.0/centos$OS_VER-$ARCH -gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB -gpgcheck=1 -" > /etc/yum.repos.d/mariadb.repo -} - - -add_ubuntu_mariadb_repo() { - run_cmd sudo apt-get update - run_cmd sudo apt-get install -y software-properties-common python-software-properties - run_cmd sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db - run_cmd sudo add-apt-repository "deb http://ams2.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu $OS_VER main" -} - -add_debian_mariadb_repo() { - if [ $OS_VER == "7" ]; then - CODENAME="wheezy" - elif [ $OS_VER == "6" ]; then - CODENAME="squeeze" - elif [ $OS_VER == "8" ]; then - CODENAME="jessie" - else - echo Unsupported Debian Version - exit 1 - fi - run_cmd sudo apt-get update - run_cmd sudo apt-get install -y software-properties-common python-software-properties - run_cmd sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db - $repo_test=$(apt-cache search --names-only 'mariadb-server') - if [ -z "$repo_test" ]; then - run_cmd sudo add-apt-repository "deb http://ams2.mirrors.digitalocean.com/mariadb/repo/10.0/debian $CODENAME main" - fi -} - -add_ius_repo() { - if [ $OS_VER -eq "6" ]; then - wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/$OS_VER/$T_ARCH/epel-release-6-5.noarch.rpm - wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/$OS_VER/$T_ARCH/ius-release-1.0-14.ius.centos6.noarch.rpm - rpm --quiet -q epel-release || rpm -Uvh epel-release-6-5.noarch.rpm - rpm --quiet -q ius-release || rpm -Uvh ius-release-1.0-14.ius.centos6.noarch.rpm - fi -} - -add_epel_centos7() { - yum install -y epel-release -} - -add_maria_db_repo() { - if [ "$OS" == "Ubuntu" ] && [ $OS_VER == "utopic" ]; then - return - elif [ "$OS" == "centos" ]; then - echo Adding centos mariadb repo - add_centos6_mariadb_repo - - elif [ "$OS" == "debian" ]; then - echo Adding debian mariadb repo - add_debian_mariadb_repo - - elif [ "$OS" == "Ubuntu" ]; then - echo Adding ubuntu mariadb repo - add_ubuntu_mariadb_repo - else - echo Unsupported Distribution - exit 1 - fi -} - -## install - -install_packages() { - if [ $OS == "centos" ]; then - run_cmd sudo yum install wget -y - run_cmd sudo yum groupinstall -y "Development tools" - if [ $OS_VER == "6" ]; then - run_cmd add_ius_repo - run_cmd sudo yum install -y git MariaDB-server MariaDB-client MariaDB-compat python-setuptools nginx \ - zlib-devel bzip2-devel openssl-devel postfix python27-devel python27 \ - libxml2 libxml2-devel libxslt libxslt-devel redis MariaDB-devel libXrender libXext \ - python27-setuptools cronie sudo which xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi nodejs npm \ - libtiff-devel libjpeg-devel libzip-devel freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel - elif [ $OS_VER == "7" ]; then - run_cmd add_epel_centos7 - run_cmd sudo yum install -y git mariadb-server mariadb-devel python-setuptools nginx \ - zlib-devel bzip2-devel openssl-devel postfix python-devel \ - libxml2 libxml2-devel libxslt libxslt-devel redis libXrender libXext \ - supervisor cronie sudo which xorg-x11-fonts-75dpi xorg-x11-fonts-Type1 nodejs npm \ - libtiff-devel libjpeg-devel libzip-devel freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel - fi - - echo "Installing wkhtmltopdf" - install_wkhtmltopdf_centos - run_cmd easy_install-2.7 -U pip - - - elif [ $OS == "debian" ] || [ $OS == "Ubuntu" ]; then - export DEBIAN_FRONTEND=noninteractive - setup_debconf - run_cmd bash -c "curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -" - run_cmd sudo apt-get update - run_cmd sudo apt-get install -y python-dev python-setuptools build-essential python-mysqldb git \ - ntp vim screen htop mariadb-server mariadb-common libmariadbclient-dev \ - libxslt1.1 libxslt1-dev redis-server libssl-dev libcrypto++-dev postfix nginx \ - supervisor python-pip fontconfig libxrender1 libxext6 xfonts-75dpi xfonts-base nodejs - - if [ $OS_VER == "precise" ]; then - run_cmd sudo apt-get install -y libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev \ - liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk - elif [ $OS_VER == "8" ]; then - run_cmd sudo apt-get install -y libtiff5-dev libjpeg62-turbo-dev zlib1g-dev libfreetype6-dev \ - liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk npm - else - run_cmd sudo apt-get install -y libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev \ - liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk - fi - - echo "Installing wkhtmltopdf" - install_wkhtmltopdf_deb - - else - echo Unsupported Distribution - exit 1 - fi -} - -install_wkhtmltopdf_centos () { - - if [[ $OS == "centos" && $OS_VER == "7" && $T_ARCH == "i386" ]]; then - echo "Cannot install wkhtmltodpdf. Skipping..." - return 0 - fi - RPM="wkhtmltox-0.12.2.1_linux-$OS$OS_VER-$WK_ARCH.rpm" - run_cmd wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/$RPM - rpm --quiet -q wkhtmltox || run_cmd rpm -Uvh $RPM -} - -install_wkhtmltopdf_deb () { - WK_VER=$OS_VER - - if [[ $OS_VER == "utopic" || $OS_VER == "vivid" || $OS_VER == "wily" ]]; then - echo "Installing wkhtmltox package for trusty (Ubuntu 14.4) even if you are using $OS_VER." - WK_VER="trusty" - fi - if [[ $OS == "debian" && $OS_VER == "7" ]]; then - WK_VER="wheezy" - elif [[ $OS == "debian" && $OS_VER == "8" ]]; then - WK_VER="jessie" - fi - - run_cmd wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-$WK_VER-$WK_ARCH.deb - run_cmd dpkg -i wkhtmltox-0.12.2.1_linux-$WK_VER-$WK_ARCH.deb -} - - -install_supervisor_centos6() { - run_cmd easy_install supervisor - curl -Ss https://raw.githubusercontent.com/pdvyas/supervisor-initscripts/master/redhat-init-jkoppe > /etc/init.d/supervisord - curl -Ss https://raw.githubusercontent.com/pdvyas/supervisor-initscripts/master/redhat-sysconfig-jkoppe > /etc/sysconfig/supervisord - curl -Ss https://raw.githubusercontent.com/pdvyas/supervisor-initscripts/master/supervisord.conf > /etc/supervisord.conf - run_cmd mkdir /etc/supervisor.d - run_cmd chmod +x /etc/init.d/supervisord - bash -c "service supervisord start || true" -} - -### config - -get_mariadb_password() { - get_password "MariaDB root" MSQ_PASS -} - -get_site_admin_password() { - get_password "Admin password" ADMIN_PASS -} - -get_password() { - if [ -z "$2" ]; then - read -t 1 -n 10000 discard || true - echo - read -p "Enter $1 password to set:" -s TMP_PASS1 - echo - read -p "Re enter $1 password to set:" -s TMP_PASS2 - echo - if [ $TMP_PASS1 == $TMP_PASS2 ]; then - export $2=$TMP_PASS1 - else - echo Passwords do not match - get_password $1 $2 - fi - fi -} - -configure_mariadb_centos() { - # Required only for CentOS, Ubuntu and Debian will show dpkg configure screen to set the password - if [ $OS == "centos" ]; then - mysqladmin -u root password $MSQ_PASS - fi -} - -start_services_centos6() { - run_cmd service nginx start - run_cmd service mysql start - run_cmd service redis start -} - -configure_services_centos6() { - run_cmd chkconfig --add supervisord - run_cmd chkconfig redis on - run_cmd chkconfig mysql on - run_cmd chkconfig nginx on - run_cmd chkconfig supervisord on -} - -configure_services_centos7() { - run_cmd systemctl enable nginx - run_cmd systemctl enable mysql - run_cmd systemctl enable redis - run_cmd systemctl enable supervisord -} - -start_services_centos7() { - run_cmd systemctl start nginx - run_cmd systemctl start mysql - run_cmd systemctl start redis - run_cmd systemctl start supervisord -} - -configure_mariadb() { - config=" -[mysqld] -innodb-file-format=barracuda -innodb-file-per-table=1 -innodb-large-prefix=1 -character-set-client-handshake = FALSE -character-set-server = utf8mb4 -collation-server = utf8mb4_unicode_ci - -[mysql] -default-character-set = utf8mb4 - " - deb_cnf_path="/etc/mysql/conf.d/barracuda.cnf" - centos_cnf_path="/etc/my.cnf.d/barracuda.cnf" - - if [ $OS == "centos" ]; then - - echo "$config" > $centos_cnf_path - if [ $OS_VER == "6" ]; then - run_cmd sudo service mysql restart - elif [ $OS_VER == "7" ]; then - run_cmd sudo systemctl restart mysql - fi - - elif [ $OS == "debian" ] || [ $OS == "Ubuntu" ]; then - echo "$config" > $deb_cnf_path - sudo service mysql restart - fi -} - -setup_debconf() { - debconf-set-selections <<< "postfix postfix/mailname string `hostname`" - debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'" - debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password password $MSQ_PASS" - debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password_again password $MSQ_PASS" -} - -install_bench() { - run_cmd sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER && git clone https://github.com/frappe/bench --branch $BENCH_BRANCH bench-repo" - if hash pip-2.7 &> /dev/null; then - PIP="pip-2.7" - elif hash pip2.7 &> /dev/null; then - PIP="pip2.7" - elif hash pip2 &> /dev/null; then - PIP="pip2" - elif hash pip &> /dev/null; then - PIP="pip" - else - echo PIP not installed - exit 1 - fi - - run_cmd sudo $PIP install --upgrade pip - run_cmd sudo $PIP install -e /home/$FRAPPE_USER/bench-repo -} - -setup_bench() { - echo Installing frappe-bench - FRAPPE_BRANCH="develop" - ERPNEXT_APPS_JSON="https://raw.githubusercontent.com/frappe/bench/master/install_scripts/erpnext-apps.json" - if $SETUP_PROD; then - FRAPPE_BRANCH="master" - ERPNEXT_APPS_JSON="https://raw.githubusercontent.com/frappe/bench/master/install_scripts/erpnext-apps-master.json" - fi - - run_cmd sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER && bench init frappe-bench --frappe-branch $FRAPPE_BRANCH --apps_path $ERPNEXT_APPS_JSON" - echo Setting up first site - echo /home/$FRAPPE_USER/frappe-bench > /etc/frappe_bench_dir - run_cmd sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER/frappe-bench && bench new-site site1.local --mariadb-root-password $MSQ_PASS --admin-password $ADMIN_PASS" - run_cmd sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER/frappe-bench && bench install-app erpnext" - run_cmd bash -c "cd /home/$FRAPPE_USER/frappe-bench && bench setup sudoers $FRAPPE_USER" - if $SETUP_PROD; then - run_cmd bash -c "cd /home/$FRAPPE_USER/frappe-bench && bench setup production $FRAPPE_USER" - fi - chown $FRAPPE_USER /home/$FRAPPE_USER/frappe-bench/logs/* -} - -add_user() { -# Check if script is running as root and is not running as sudo. We want to skip -# this step if the user is already running this script with sudo as a non root -# user - if [ "$FRAPPE_USER" == "false" ]; then - if [[ $SUDO_UID -eq 0 ]] && [[ $EUID -eq 0 ]]; then - export FRAPPE_USER="frappe" - else - export FRAPPE_USER="$SUDO_USER" - fi - fi - - USER_EXISTS=`bash -c "id $FRAPPE_USER > /dev/null 2>&1 && echo true || (echo false && exit 0)"` - - if [ $USER_EXISTS == "false" ]; then - useradd -m -d /home/$FRAPPE_USER -s $SHELL $FRAPPE_USER - echo $FRAPPE_USER:$FRAPPE_USER_PASS | chpasswd - chmod o+x /home/$FRAPPE_USER - chmod o+r /home/$FRAPPE_USER - fi -} - -main() { - set_opts $@ - get_distro - add_maria_db_repo - echo Installing packages for $OS\. This might take time... - install_packages - if [ $OS == "centos" ]; then - if [ $OS_VER == "6" ]; then - echo "Installing supervisor" - install_supervisor_centos6 - echo "Configuring CentOS services" - configure_services_centos6 - echo "Starting services" - start_services_centos6 - elif [ $OS_VER == "7" ]; then - echo "Configuring CentOS services" - configure_services_centos7 - echo "Starting services" - start_services_centos7 - fi - configure_mariadb_centos - fi - configure_mariadb - echo "Adding frappe user" - add_user - - if $INSTALL_BENCH; then - install_bench - if $SETUP_BENCH; then - setup_bench - fi - fi - - echo - RUNNING="" - if $SETUP_PROD; then - RUNNING=" and is running on port 80" - fi - echo "Frappe/ERPNext is installed successfully$RUNNING." - print_msg > ~/frappe_passwords.txt - print_msg - echo - echo "The passwords are also stored at ~/frappe_passwords.txt" - echo "You can remove this file after making a note of the passwords." -} - -main $@ From bebcd5300ec8b23128827438cc4c12c50950b1cb Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Mon, 9 Apr 2018 12:34:39 +0530 Subject: [PATCH 06/16] install prereqs before setup production - removed locked down version of ansible, downloads latest now - install ansible and other prereqs before bench setup production --- bench/commands/setup.py | 4 ++++ playbooks/install.py | 2 +- playbooks/site.yml | 32 ++++++++++++++++---------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 622c6f74..13517442 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -1,3 +1,4 @@ +from bench.utils import exec_cmd import click, sys, json @click.group() @@ -51,6 +52,9 @@ def setup_fonts(): def setup_production(user, yes=False): "setup bench for production" from bench.config.production_setup import setup_production + # Install prereqs for production + exec_cmd("sudo pip install ansible") + run_playbook('site.yml', tag='production') setup_production(user=user, yes=yes) diff --git a/playbooks/install.py b/playbooks/install.py index 8abec392..cd7026eb 100644 --- a/playbooks/install.py +++ b/playbooks/install.py @@ -59,7 +59,7 @@ def install_bench(args): }) success = run_os_command({ - 'pip': "sudo pip install ansible==2.5.0" + 'pip': "sudo pip install ansible" }) if not success: diff --git a/playbooks/site.yml b/playbooks/site.yml index f3f4d7cf..87986ada 100644 --- a/playbooks/site.yml +++ b/playbooks/site.yml @@ -5,22 +5,22 @@ become: yes become_user: root roles: - - { role: common, tags: "common" } - - { role: locale, tags: "locale" } - - { role: swap, tags: "swap", when: production } - - { role: logwatch, tags: "logwatch", when: production } - - { role: bash_screen_wall, tags: "bash_screen_wall", when: production } - - { role: frappe_selinux, tags: "frappe_selinux", when: production } - - { role: dns_caching, tags: "dns_caching", when: production } - - { role: ntpd, tags: "ntpd", when: production } - - { role: mariadb, tags: "mariadb" } - - { role: wkhtmltopdf, tags: "wkhtmltopdf" } - - { role: nodejs, tags: "nodejs" } - - { role: psutil, tags: "psutil" } - - { role: redis, tags: "redis" } - - { role: supervisor, tags: "supervisor", when: production } - - { role: nginx, tags: "nginx", when: production } - - { role: fail2ban, tags: "fail2ban", when: production } + - { role: common, tags: "common" } + - { role: locale, tags: "locale" } + - { role: swap, tags: "swap", "production" when: production } + - { role: logwatch, tags: "logwatch", "production" when: production } + - { role: bash_screen_wall, tags: "bash_screen_wall", "production" when: production } + - { role: frappe_selinux, tags: "frappe_selinux", "production" when: production } + - { role: dns_caching, tags: "dns_caching", "production" when: production } + - { role: ntpd, tags: "ntpd", "production" when: production } + - { role: mariadb, tags: "mariadb" } + - { role: wkhtmltopdf, tags: "wkhtmltopdf" } + - { role: nodejs, tags: "nodejs" } + - { role: psutil, tags: "psutil" } + - { role: redis, tags: "redis" } + - { role: supervisor, tags: "supervisor", "production" when: production } + - { role: nginx, tags: "nginx", "production" when: production } + - { role: fail2ban, tags: "fail2ban", "production" when: production } tasks: - name: Set hostname hostname: name='{{ hostname }}' From 99cf7610c0f5e1102fb331396ec1776b7331974f Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Mon, 9 Apr 2018 15:11:55 +0530 Subject: [PATCH 07/16] increased default max_packet_size to 256M Increased the max_packet_size for both mysqld and mysqldump to 256M. Change was made to prevent backup/restore failure due to large packet size, which used to showup as tabSingles not found --- playbooks/roles/mariadb/files/debian_mariadb_config.cnf | 5 ++++- playbooks/roles/mariadb/files/mariadb_config.cnf | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/playbooks/roles/mariadb/files/debian_mariadb_config.cnf b/playbooks/roles/mariadb/files/debian_mariadb_config.cnf index 2e0c0d60..f2ac13f3 100644 --- a/playbooks/roles/mariadb/files/debian_mariadb_config.cnf +++ b/playbooks/roles/mariadb/files/debian_mariadb_config.cnf @@ -5,7 +5,10 @@ innodb-large-prefix=1 character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci -max_allowed_packet=64M +max_allowed_packet=256M [mysql] default-character-set = utf8mb4 + +[mysqldump] +max_allowed_packet=256M diff --git a/playbooks/roles/mariadb/files/mariadb_config.cnf b/playbooks/roles/mariadb/files/mariadb_config.cnf index b6512a22..19443454 100644 --- a/playbooks/roles/mariadb/files/mariadb_config.cnf +++ b/playbooks/roles/mariadb/files/mariadb_config.cnf @@ -11,7 +11,7 @@ key-buffer-size = 32M myisam-recover = FORCE,BACKUP # SAFETY # -max-allowed-packet = 64M +max-allowed-packet = 256M max-connect-errors = 1000000 innodb = FORCE @@ -49,7 +49,7 @@ innodb-large-prefix = 1 collation-server = utf8mb4_unicode_ci character-set-server = utf8mb4 character-set-client-handshake = FALSE -max_allowed_packet = 64M +max_allowed_packet = 256M # LOGGING # log-error = /var/lib/mysql/mysql-error.log @@ -59,3 +59,6 @@ slow-query-log-file = /var/lib/mysql/mysql-slow.log [mysql] default-character-set = utf8mb4 + +[mysqldump] +max_allowed_packet=256M \ No newline at end of file From e82e57b35a573f594ee3700a5f4e432764a8ec00 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 9 Apr 2018 15:47:38 +0530 Subject: [PATCH 08/16] added quiet to bench workers --- bench/config/templates/Procfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bench/config/templates/Procfile b/bench/config/templates/Procfile index c465bbac..b9c81118 100644 --- a/bench/config/templates/Procfile +++ b/bench/config/templates/Procfile @@ -9,9 +9,9 @@ watch: bench watch {% endif %} {% if use_rq -%} schedule: bench schedule -worker_short: bench worker --queue short -worker_long: bench worker --queue long -worker_default: bench worker --queue default +worker_short: bench worker --queue short --quiet +worker_long: bench worker --queue long --quiet +worker_default: bench worker --queue default --quiet {% else %} workerbeat: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app beat -s scheduler.schedule' worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n jobs@%h -Ofair --soft-time-limit 360 --time-limit 390' From 12f93976d0c08c234f6a873ca7d4caa320126f03 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Mon, 9 Apr 2018 15:41:01 +0530 Subject: [PATCH 09/16] Blank password not accepted Stopped accepting blank passwords for MySQL password and Administrator password in the install script --- playbooks/install.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/playbooks/install.py b/playbooks/install.py index cd7026eb..150abba9 100644 --- a/playbooks/install.py +++ b/playbooks/install.py @@ -271,7 +271,7 @@ def get_passwords(args): mysql_root_password = getpass.unix_getpass(prompt='Please enter mysql root password: ') conf_mysql_passwd = getpass.unix_getpass(prompt='Re-enter mysql root password: ') - if mysql_root_password != conf_mysql_passwd: + if mysql_root_password != conf_mysql_passwd or mysql_root_password == '': mysql_root_password = '' continue @@ -280,7 +280,7 @@ def get_passwords(args): admin_password = getpass.unix_getpass(prompt='Please enter the default Administrator user password: ') conf_admin_passswd = getpass.unix_getpass(prompt='Re-enter Administrator password: ') - if admin_password != conf_admin_passswd: + if admin_password != conf_admin_passswd or admin_password == '': admin_password = '' continue From 348e38f37a4ad56e7389a99f42c8769395d175d9 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Thu, 22 Mar 2018 18:19:51 +0530 Subject: [PATCH 10/16] changed node version install from 6 to 8 - broken down the node install into multiple parts based on OS - change the default node version to be installed from 6 to 8 --- .../roles/nodejs/tasks/debian_family.yml | 23 ++++++++++ playbooks/roles/nodejs/tasks/main.yml | 44 +++---------------- .../roles/nodejs/tasks/redhat_family.yml | 18 ++++++++ 3 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 playbooks/roles/nodejs/tasks/debian_family.yml create mode 100644 playbooks/roles/nodejs/tasks/redhat_family.yml diff --git a/playbooks/roles/nodejs/tasks/debian_family.yml b/playbooks/roles/nodejs/tasks/debian_family.yml new file mode 100644 index 00000000..cef47710 --- /dev/null +++ b/playbooks/roles/nodejs/tasks/debian_family.yml @@ -0,0 +1,23 @@ +--- +- name: Add apt key for node repo + apt_key: + url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280 + id: "68576280" + state: present + when: ansible_os_family == 'Debian' + +- name: Add repo + apt_repository: + repo: "deb [arch=amd64,i386] https://deb.nodesource.com/node_8.x {{ ansible_distribution_release }} main" + state: present + register: node_repo + when: ansible_os_family == 'Debian' + +- name: Install nodejs 8.x + apt: + name: nodejs + state: present + update_cache: yes + force: yes + when: ansible_os_family == 'Debian' +... \ No newline at end of file diff --git a/playbooks/roles/nodejs/tasks/main.yml b/playbooks/roles/nodejs/tasks/main.yml index e521c27d..85379727 100644 --- a/playbooks/roles/nodejs/tasks/main.yml +++ b/playbooks/roles/nodejs/tasks/main.yml @@ -1,44 +1,14 @@ --- -- name: Import Node source RPM key - rpm_key: - key: https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL - state: present - when: ansible_os_family == 'RedHat' +# Install's prerequisites, like fonts, image libraries, vim, screen, python-dev and gcc -- name: Add Node Repo for RedHat - yum: - name: 'https://rpm.nodesource.com/pub_6.x/el/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-el{{ ansible_distribution_major_version }}-1.noarch.rpm' - state: present - update_cache: yes - when: ansible_os_family == 'RedHat' +- include_tasks: debian_family.yml + when: ansible_os_family == 'Debian' -- name: Install node v6 - yum: name=nodejs state=present - when: ansible_os_family == 'RedHat' - -- name: Add apt key for node repo - apt_key: - url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280 - id: "68576280" - state: present - when: ansible_os_family == 'Debian' or ansible_distribution == 'Ubuntu' - -- name: Add repo - apt_repository: - repo: "deb [arch=amd64,i386] https://deb.nodesource.com/node_6.x {{ ansible_distribution_release }} main" - state: present - register: node_repo - when: ansible_os_family == 'Debian' or ansible_distribution == 'Ubuntu' - -- name: Install nodejs 6.x - apt: - name: nodejs - state: present - update_cache: yes - force: yes - when: ansible_os_family == 'Debian' or ansible_distribution == 'Ubuntu' +- include_tasks: redhat_family.yml + when: ansible_os_family == "RedHat" - name: Install yarn command: npm install -g yarn become: yes - become_user: root \ No newline at end of file + become_user: root +... \ No newline at end of file diff --git a/playbooks/roles/nodejs/tasks/redhat_family.yml b/playbooks/roles/nodejs/tasks/redhat_family.yml new file mode 100644 index 00000000..15af3846 --- /dev/null +++ b/playbooks/roles/nodejs/tasks/redhat_family.yml @@ -0,0 +1,18 @@ +--- +- name: Import Node source RPM key + rpm_key: + key: https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL + state: present + when: ansible_os_family == 'RedHat' + +- name: Add Node Repo for RedHat + yum: + name: 'https://rpm.nodesource.com/pub_8.x/el/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-el{{ ansible_distribution_major_version }}-1.noarch.rpm' + state: present + update_cache: yes + when: ansible_os_family == 'RedHat' + +- name: Install node v8 + yum: name=nodejs state=present + when: ansible_os_family == 'RedHat' +... \ No newline at end of file From 8a82f98eac0448b0abf37b52a61cb0e543f6aa75 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Mon, 9 Apr 2018 16:54:53 +0530 Subject: [PATCH 11/16] minor fixes --- README.md | 4 +-- bench/commands/setup.py | 5 ++- playbooks/install.py | 2 +- .../roles/nodejs/tasks/debian_family.yml | 3 -- playbooks/site.yml | 32 +++++++++---------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 517a0fc1..6a429557 100755 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Build Status](https://travis-ci.org/frappe/bench.svg?branch=master)](https://travis-ci.org/frappe/bench) -The bench is a command-line utility that helps you to install apps, manage multiple sites and update Frappe / ERPNext apps on */nix (CentOS 6, Debian 7, Ubuntu, etc) for development and production. Bench will also create nginx and supervisor config files, setup backups and much more. +The bench is a command-line utility that helps you to install apps, manage multiple sites and update Frappe / ERPNext apps on */nix (CentOS, Debian, Ubuntu, etc) for development and production. Bench will also create nginx and supervisor config files, setup backups and much more. If you are using on a VPS make sure it has >= 1Gb of RAM or has swap setup properly. @@ -83,7 +83,7 @@ Note: Please do not remove the bench directory the above commands will create ## Easy Install - This is an opinionated setup so it is best to setup on a blank server. -- Works on Ubuntu 14.04 to 16.04, CentOS 7+, Debian 7 to 8 and MacOS X. +- Works on Ubuntu 16.04, CentOS 7+, Debian 8+ - You may have to install Python 2.7 (eg on Ubuntu 16.04+) by running `apt-get install python-minimal` - You may also have to install build-essential and python-setuptools by running `apt-get install build-essential python-setuptools` - This script will install the pre-requisites, install bench and setup an ERPNext site diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 13517442..c7a8d12d 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -52,9 +52,12 @@ def setup_fonts(): def setup_production(user, yes=False): "setup bench for production" from bench.config.production_setup import setup_production + from bench.utils import run_playbook # Install prereqs for production exec_cmd("sudo pip install ansible") - run_playbook('site.yml', tag='production') + exec_cmd("bench setup role fail2ban") + exec_cmd("bench setup role nginx") + exec_cmd("bench setup role supervisor") setup_production(user=user, yes=yes) diff --git a/playbooks/install.py b/playbooks/install.py index 150abba9..4020a850 100644 --- a/playbooks/install.py +++ b/playbooks/install.py @@ -124,7 +124,7 @@ def install_bench(args): shutil.rmtree(tmp_bench_repo) def check_distribution_compatibility(): - supported_dists = {'ubuntu': [14, 15, 16], 'debian': [7, 8, 9], + supported_dists = {'ubuntu': [15, 16], 'debian': [8, 9], 'centos': [7], 'macos': [10.9, 10.10, 10.11, 10.12]} dist_name, dist_version = get_distribution_info() diff --git a/playbooks/roles/nodejs/tasks/debian_family.yml b/playbooks/roles/nodejs/tasks/debian_family.yml index cef47710..c64bac55 100644 --- a/playbooks/roles/nodejs/tasks/debian_family.yml +++ b/playbooks/roles/nodejs/tasks/debian_family.yml @@ -4,14 +4,12 @@ url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280 id: "68576280" state: present - when: ansible_os_family == 'Debian' - name: Add repo apt_repository: repo: "deb [arch=amd64,i386] https://deb.nodesource.com/node_8.x {{ ansible_distribution_release }} main" state: present register: node_repo - when: ansible_os_family == 'Debian' - name: Install nodejs 8.x apt: @@ -19,5 +17,4 @@ state: present update_cache: yes force: yes - when: ansible_os_family == 'Debian' ... \ No newline at end of file diff --git a/playbooks/site.yml b/playbooks/site.yml index 87986ada..839620ee 100644 --- a/playbooks/site.yml +++ b/playbooks/site.yml @@ -5,22 +5,22 @@ become: yes become_user: root roles: - - { role: common, tags: "common" } - - { role: locale, tags: "locale" } - - { role: swap, tags: "swap", "production" when: production } - - { role: logwatch, tags: "logwatch", "production" when: production } - - { role: bash_screen_wall, tags: "bash_screen_wall", "production" when: production } - - { role: frappe_selinux, tags: "frappe_selinux", "production" when: production } - - { role: dns_caching, tags: "dns_caching", "production" when: production } - - { role: ntpd, tags: "ntpd", "production" when: production } - - { role: mariadb, tags: "mariadb" } - - { role: wkhtmltopdf, tags: "wkhtmltopdf" } - - { role: nodejs, tags: "nodejs" } - - { role: psutil, tags: "psutil" } - - { role: redis, tags: "redis" } - - { role: supervisor, tags: "supervisor", "production" when: production } - - { role: nginx, tags: "nginx", "production" when: production } - - { role: fail2ban, tags: "fail2ban", "production" when: production } + - { role: common, tags: common } + - { role: locale, tags: locale } + - { role: swap, tags: swap, when: production } + - { role: logwatch, tags: logwatch, when: production } + - { role: bash_screen_wall, tags: bash_screen_wall, when: production } + - { role: frappe_selinux, tags: frappe_selinux, when: production } + - { role: dns_caching, tags: dns_caching, when: production } + - { role: ntpd, tags: ntpd, when: production } + - { role: mariadb, tags: mariadb } + - { role: wkhtmltopdf, tags: wkhtmltopdf } + - { role: nodejs, tags: nodejs } + - { role: psutil, tags: psutil } + - { role: redis, tags: redis } + - { role: supervisor, tags: supervisor, when: production } + - { role: nginx, tags: nginx, when: production } + - { role: fail2ban, tags: fail2ban, when: production } tasks: - name: Set hostname hostname: name='{{ hostname }}' From c8c9104ff9cd89480a8eef39dbb41577b799624c Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Tue, 10 Apr 2018 18:41:30 +0530 Subject: [PATCH 12/16] minor --- playbooks/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playbooks/install.py b/playbooks/install.py index 4020a850..fb478ddf 100644 --- a/playbooks/install.py +++ b/playbooks/install.py @@ -124,7 +124,7 @@ def install_bench(args): shutil.rmtree(tmp_bench_repo) def check_distribution_compatibility(): - supported_dists = {'ubuntu': [15, 16], 'debian': [8, 9], + supported_dists = {'ubuntu': [14, 15, 16], 'debian': [8, 9], 'centos': [7], 'macos': [10.9, 10.10, 10.11, 10.12]} dist_name, dist_version = get_distribution_info() From d3cd3abf90f386a701c2bd845e322ad58c72945d Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Wed, 11 Apr 2018 10:40:06 +0530 Subject: [PATCH 13/16] updated readme --- README.md | 33 +++++++++++++++++++-------------- playbooks/README.md | 10 ---------- vm/Readme.md | 26 ++++++++++---------------- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 6a429557..9cfff9e4 100755 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +

Frappe Bench

@@ -15,19 +16,33 @@ If you have questions, please ask them on the [forum](https://discuss.erpnext.co ## Installation -## Manual Install +### Installation Requirements -To manually install frappe/erpnext here are the steps +You will need a computer/server. Options include: + +- A Normal Computer/VPS/Baremetal Server: This is strongly recommended. Frappe/ERPNext installs properly and works well on these +- A Raspberry Pi, SAN Appliance, Network Router, Gaming Console, etc.: Although you may be able to install Frappe/ERPNext on specialized hardware, it is unlikely to work well and will be difficult for us to support. Strongly consider using a normal computer/VPS/baremetal server instead. **We do not support specialized hardware**. +- A Toaster, Car, Firearm, Thermostat, etc.: Yes, many modern devices now have embedded computing capability. We live in interesting times. However, you should not install Frappe/ERPNext on these devices. Instead, install it on a normal computer/VPS/baremetal server. **We do not support installing on noncomputing devices**. + +To install the Frappe/ERPNext server software, you will need an operating system on your normal computer which is not Windows. Note that the command line interface does work on Windows, and you can use Frappe/ERPNext from any operating system with a web browser. However, the server software does not run on Windows. It does run on other operating systems, so choose one of these instead: + +- Linux: Debian, Ubuntu, CentOS are the preferred distros and are well tested. [Arch Linux](https://github.com/frappe/bench/wiki/Install-ERPNext-on-ArchLinux) can also be used +- Mac OS X + +### Manual Install + +To manually install frappe/erpnext, you can follow this [this wiki](https://github.com/frappe/frappe/wiki/The-Hitchhiker's-Guide-to-Installing-Frapp%C3%A9-on-Linux-OS) for Linux and [this wiki](https://github.com/frappe/frappe/wiki/The-Hitchhiker's-Guide-to-Installing-Frapp%C3%A9-on-Mac-OS-X) for MacOS. It gives an excellent explanation about the stack. You can also follow the steps mentioned below: #### 1. Install Pre-requisites -- Python 2.7 +- Python 2.7 [Python3.5+ also supported, but not recommended for production] - MariaDB 10+ - Nginx (for production) - Nodejs +- yarn - Redis - cron (crontab is required) -- wkhtmltopdf with patched Qt (for pdf generation) +- wkhtmltopdf with patched Qt (version 0.12.3) (for pdf generation) #### 2. Install Bench @@ -100,16 +115,6 @@ For Linux: wget https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py -For Mac OSX: - -Install X Code (from App store) and HomeBrew (http://brew.sh/) first - - brew install python - brew install git - -Download the Script - - curl "https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py" -o install.py #### 2. Run the install script diff --git a/playbooks/README.md b/playbooks/README.md index d47a31b9..4c524ff1 100644 --- a/playbooks/README.md +++ b/playbooks/README.md @@ -5,16 +5,6 @@ - Ubuntu 14.04, 16.04 - CentOS 7 -## Directory Structure - TODO - ## Notes for maintainers - For MariaDB playbooks refer https://github.com/PCextreme/ansible-role-mariadb - Any changes made in relation to a role should be dont inside the role and not outside it - -# TODO: -1. Planned Platform - - Arch Linux - - Fedora - - RedHat -2. Consider reffering to https://github.com/geerlingguy/ansible-role-mysql.git for MariaDB playbook \ No newline at end of file diff --git a/vm/Readme.md b/vm/Readme.md index 7b4c3152..316b3c33 100644 --- a/vm/Readme.md +++ b/vm/Readme.md @@ -1,18 +1,18 @@ -### ERPNext VM Builder +## ERPNext VM Builder -#### Steps to build a VM Image +### Steps to build a VM Image -* `python build.py` builds a new VM +* `python build.py` builds a new Production VM, a Dev VM and a Dev Vagrant Box -#### Requirements +### Requirements -* Bench should be installed. +* Bench should be installed * Ansible should be installed -#### How it works +### How it works Apart from the above the rest is handled by bench: @@ -21,23 +21,17 @@ Apart from the above the rest is handled by bench: - packer * Cleanup - Clean the required directories -* Generate the erpnext_develop.json and the erpnext_production.json - - Figure out the latest ubuntu iso available, get it's link and the checksum and generate the json files * Build the VM using packer - Packer downloads the mentioned Ubuntu iso, boots a virtual machine and preceeds the preseed.cfg file into it in order to setup a clean Ubuntu OS - Then packer uses ssh to enter the virtual machine to execute the required commands - `scripts/debian_family/install_ansible.sh` sets up ansible on the vm. - - Depending on the VM being built, the `install_erpnext_develop.sh` or the `install_erpnext_production.sh` is executed + - Depending on the VM being built, the `vm-develop.json` or the `vm-production.json` is used - `scripts/set_message.sh` sets welcome message (with update instructions) in the vm. - - `scripts/cleanup.sh` writes zero to all the free space in the disk, it shrinks the disk image + - `scripts/cleanup.sh` writes zeros to all the free space in the disk, it shrinks the disk image * Set the correct permissions for the built Vagrant and Virtual Appliance Images * Cleanup - Delete the generated files from the required directories -* restart nginx - -The requirements for this to run are Packer and Virtualbox. imports the base image in a virtual machine and boots it. It runs the following +* Restart nginx -#### For a build server - -Running the `build.py` script builds a vm and puts it in `~/public`. It also writes a `latest.json` file in `~/public` with filename of the latest build and its md5sum. +Running the `build.py` script builds the VMs and puts them in `~/Public`. It also creates the md5 hashes for the same, and puts them in the same folder. From d020bb528a4ad2ecd6d85d9337fb6fd6b0f80f9b Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Wed, 11 Apr 2018 15:09:59 +0530 Subject: [PATCH 14/16] Update setup.py --- bench/commands/setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 379a8b8c..e02e91b1 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -47,7 +47,6 @@ def setup_fonts(): setup_fonts() @click.command('production') -@click.option('--yes', is_flag=True, default=False, help='Dont prompt for confirmation') @click.argument('user') @click.option('--yes', help='Yes to regeneration config', is_flag=True, default=False) def setup_production(user, yes=False): @@ -255,4 +254,4 @@ setup.add_command(sync_domains) setup.add_command(setup_firewall) setup.add_command(set_ssh_port) setup.add_command(setup_roles) -setup.add_command(setup_nginx_proxy_jail) \ No newline at end of file +setup.add_command(setup_nginx_proxy_jail) From f45862a3ca7238dbb39661bbf673b07068f2ab91 Mon Sep 17 00:00:00 2001 From: vishalseshagiri Date: Mon, 11 Sep 2017 16:52:00 +0530 Subject: [PATCH 15/16] resolved conflicts --- bench/commands/setup.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index c7a8d12d..f2ce6d12 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -1,5 +1,6 @@ from bench.utils import exec_cmd import click, sys, json +import os @click.group() def setup(): @@ -153,6 +154,27 @@ def setup_node_requirements(): from bench.utils import update_node_packages update_node_packages() + +@click.command('manager') +def setup_manager(): + "Setup bench-manager.local site with the bench_manager app installed on it" + from six.moves import input + create_new_site = True + if 'bench-manager.local' in os.listdir('sites'): + ans = input('Site aleady exists. Overwrite existing new site? [Y/n]: ') + while ans.lower() not in ['y', 'n', '']: + ans = input('Please type "y" or "n". Site aleady exists. Overwrite existing new site? [Y/n]: ') + if ans=='n': create_new_site = False + if create_new_site: exec_cmd("bench new-site --force bench-manager.local") + + if 'bench_manager' in os.listdir('apps'): + print('App aleady exists. Skipping downloading the app') + else: + exec_cmd("bench get-app bench_manager") + + exec_cmd("bench --site bench-manager.local install-app bench_manager") + + @click.command('config') def setup_config(): "overwrite or make config.json" @@ -246,6 +268,7 @@ setup.add_command(setup_env) setup.add_command(setup_procfile) setup.add_command(setup_socketio) setup.add_command(setup_requirements) +setup.add_command(setup_manager) setup.add_command(setup_config) setup.add_command(setup_fonts) setup.add_command(add_domain) From 43815279df208d64fcddf3b8e9e312753dffb338 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Wed, 11 Apr 2018 16:29:42 +0530 Subject: [PATCH 16/16] Update app.py --- bench/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/app.py b/bench/app.py index 24f0d214..443156f3 100755 --- a/bench/app.py +++ b/bench/app.py @@ -85,7 +85,7 @@ def get_app(git_url, branch=None, bench_path='.', build_asset_files=True, verbos #Gets repo name from URL repo_name = git_url.rsplit('/', 1)[1].rsplit('.', 1)[0] logger.info('getting app {}'.format(repo_name)) - shallow_clone = '--depth 1 --no-single-branch' if check_git_for_shallow_clone() else '' + shallow_clone = '--depth 1' if check_git_for_shallow_clone() else '' branch = '--branch {branch}'.format(branch=branch) if branch else '' exec_cmd("git clone {git_url} {branch} {shallow_clone} --origin upstream".format(