Centos 7 ERPNext Easy Install fix

From vpsget wiki
Revision as of 23:56, 4 December 2020 by Ndi (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to install ERPNext on Centos 7

Definitely we will show how to install erpnext on Centos 7 on a VPS.

This should be really easy as per git info :https://github.com/frappe/bench#easy-install-script But for sure you may face many issues so we will show how to handle them easily.

Update OS

yum update

Create user frappe and add to a wheel group first. If you on Centos mininal you'll require packages that may be already installed on non-mininal setup.

yum install sudo which nano

reLogin under user frappe and act via sudo.

su - frappe

Edit env:

nano /etc/environment
LANG=en_US.utf-8
LC_ALL=en_US.utf-8

Edit locale:

nano /etc/locale.conf
LC_ALL=en_US.utf-8
LC_CTYPE=en_US.utf-8
LANG=en_US.utf-8
LC_COLLATE="C"
#LANG=C

Relogin!

exit
su - frappe

NOTE: you should not ignore any encoding or colation errors! if you got them - check the files /etc/environment and /etc/locale.conf once again ; relogin.

Install depencies:

sudo yum groupinstall "Development Tools"
sudo yum install  python3  python3-devel python3-wheel ansible

Install nodejs:

sudo curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
sudo yum install nodejs
#check:
node -v 
 v10.21.0

Get bench repo :

git clone https://github.com/frappe/bench  bench-repo

Get setup script from official repo:

wget https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py 

Run EasySetup sctipt. Please note during easy setup script you may also face issues. Using --verbose will show you more details - you'll be able to view in details which exactly ansible playbook caused an issue and fix/edit or remove part of playbook in order to skip error and handle it manually.

sudo python3 install.py --production --site erp.domain.com --user frappe  --verbose --container
# or
# sudo python3 install.py --production --site erp.domain.com --user frappe  --verbose --container --bench frappe-bench

I'll provide issues and troubleshoot experience/example:

First I've got ansible related error:

Traceback (most recent call last):
 File "install.py", line 438, in <module>
   install_bench(args)
 File "install.py", line 212, in install_bench
   run_playbook('create_user.yml', extra_vars=extra_vars)
 File "install.py", line 363, in run_playbook
   success = subprocess.check_call(args, cwd=os.path.join(cwd, 'playbooks'), stdout=log_stream, stderr=sys.stderr)
 File "/usr/lib64/python3.6/subprocess.py", line 306, in check_call
   retcode = call(*popenargs, **kwargs)
 File "/usr/lib64/python3.6/subprocess.py", line 287, in call
   with Popen(*popenargs, **kwargs) as p:
 File "/usr/lib64/python3.6/subprocess.py", line 729, in __init__
   restore_signals, start_new_session)
 File "/usr/lib64/python3.6/subprocess.py", line 1364, in _execute_child
   raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ansible-playbook': 'ansible-playbook'

Ok you may modify the lines in install.py specified in error in order to get more info: as from error  :

nano  +363 install.py

Add more outputs before "succees = ":

       print (tmp_bench_repo)
       print (playbook_name)
       print (args)
       print (os.path.join(cwd, 'playbooks'))
       success = subprocess.check_call(args, cwd=os.path.join(cwd, 'playbooks'), stdout=log_stream, stderr=sys.stderr)

Run install again; you'll see more details now like command what failed:

/tmp/.bench
/tmp/.bench
create_user.yml
['ansible-playbook', '-c', 'local', 'create_user.yml', '-vvvv', '-e', '@/tmp/extra_vars.json']
/tmp/.bench/playbooks

So script try to run command equal to

ansible-playbook -c  local create_user.yml -vvvv -e @/tmp/extra_vars.json #run in /tmp/.bench/playbooks 

You may test it from /tmp/.bench/playbooks and it should be succeed.

NORMAL FIX: install ansible once again. yes it's weird:

sudo yum install ansible

Rerun install script

ALTER FIX: Find where is your ansible and note with

whereis ansible 

Go into install.py ~ line 360 and change the next line (under def run_playbook(playbook_name, sudo=False, extra_vars=None):):

        args = ['ansible-playbook', '-c', 'local',  playbook_name , '-vvvv']   
  #To
        args = ['/usr/local/bin/ansible-playbook', '-c', 'local',  playbook_name , '-vvvv']    

Re-run Install script; however you may face another issue on few steps later related to playbook python2 and 3 so in this case go back to install.py and revert your changes.

Most likely you've got error about selinux policy even it was disabled on my vps so I've simply edited the corresponding book from the error:

nano /tmp/.bench/playbooks/roles/frappe_selinux/tasks/main.yml  

remove lines regarding selinux policy commands and init so file looks like:

---
- name: Install deps
  yum:
    name:
      - policycoreutils-python
      - selinux-policy-devel
    state: present
  when: ansible_distribution == 'CentOS' 

...

Restart the easyinstall script

You MAY receive the next issue [but in my normal install case there was no such issue]:

TASK [bench : Create a new site] **********************************************************************************************
task path: /tmp/.bench/playbooks/roles/bench/tasks/setup_erpnext.yml:17
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /var/tmp `"&& mkdir /var/tmp/ansible-tmp-1592951572.4-31249-46029726533419 && echo ansible- 
tmp-1592951572.4-31249-46029726533419="` echo /var/tmp/ansible-tmp-1592951572.4-31249-46029726533419 `" ) && sleep 0' 
Using module file /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-27698mrm95R/tmpeU0Goi TO /var/tmp/ansible-tmp-1592951572.4-31249-46029726533419/AnsiballZ_command.py
<127.0.0.1> EXEC /bin/sh -c 'setfacl -m u:frappe:r-x /var/tmp/ansible-tmp-1592951572.4-31249-46029726533419/ /var/tmp/ansible-tmp-1592951572.4-31249- 
46029726533419/AnsiballZ_command.py && sleep 0' 
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S -n  -u frappe /bin/sh -c '"'"'echo BECOME-SUCCESS-csgzmunubmeoqogldsmljkmyudingcit ; /usr/bin/python2 
/var/tmp/ansible-tmp-1592951572.4-31249-46029726533419/AnsiballZ_command.py'"'"' && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /var/tmp/ansible-tmp-1592951572.4-31249-46029726533419/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": true, 
    "cmd": [
        "bench", 
        "new-site", 
        "erp.domain.net", 
        "--admin-password", 
        "PASSWORD", 
        "--mariadb-root-password", 
        "DBPASSWORD"
    ], 
    "delta": "0:00:02.269755", 
    "end": "2020-06-23 18:32:54.889770", 
    "invocation": {
        "module_args": {
            "_raw_params": "bench new-site erp.domain.net --admin-password 'PASSWORD' --mariadb-root-password 'DBPASSWORD'", 
            "_uses_shell": false,   
 </ommited>

Googling the error will point us that most likely there was no bench init issued. manually you can do it with cd /home/frappe/frappe-bench/&&bench init erp.example.net command . But we will add it to playbook.

  • However please note that at this point erpnext is installed you may continue manual action to add site and generate nginx config

So modify corresponding playbook File [from error]: /tmp/.bench/playbooks/roles/bench/tasks/setup_erpnext.yml and add Init Bench step:

  ---
    - name: Check if ERPNext App exists
      stat: path="{{ bench_path }}/apps/erpnext"
      register: app
  
    - name: Get the ERPNext app
      command: bench get-app erpnext {{ erpnext_repo_url }} --branch {{ erpnext_branch }}
      args:
        creates: "{{ bench_path }}/apps/erpnext"
        chdir: "{{ bench_path }}"
      when: not app.stat.exists and not without_erpnext
  
    - name: Check whether the site already exists
      stat: path="{{ bench_path }}/sites/{{ site }}"
      register: site_folder
  
    - name: Init bench
      command: "bench init {{ site }}"                                                                                            
      args:
        chdir: "{{ bench_path }}"
  
    - name: Create a new site
      command: "bench new-site {{ site }} --admin-password '{{ admin_password }}' --mariadb-root-password '{{ mysql_root_passwor$
      args:
        chdir: "{{ bench_path }}"
      when: not site_folder.stat.exists
  
    - name: Install ERPNext to default site
      command: "bench --site {{ site }} install-app erpnext"
      args:
        chdir: "{{ bench_path }}"
      when: not without_erpnext
  ...


OK relogin for any case and restar easyinstall:

 cd /home/<whete install.py exisst>
 sudo python3 install.py --production --site erp.ikrok.net --user frappe  --verbose --container

You MAY got failed on the supervisorctl playbook istall script path:

TASK [Restart the bench] ******************************************************************************************************
task path: /tmp/.bench/playbooks/roles/bench/tasks/setup_bench_production.yml:24
 
    "stderr_lines": [], 
   "stdout": "unix:///var/run/supervisor/supervisor.sock no such file\n\u001b[90m$ sudo supervisorctl restart frappe:\u001b[0m", 
   "stdout_lines": [
       "unix:///var/run/supervisor/supervisor.sock no such file", 
       "\u001b[90m$ sudo supervisorctl restart frappe:\u001b[0m"

Ok. that's simple - just start supervisord service manually :

 sudo systemctl start supervisord
 sudo systemctl status supervisord #should be ok. otherwise go to supervisord logs or check if it's installed and install if missed.

Check supervisord socket for any case:

sudo lsof -c supervisord | egrep 'COMMAND|sock'
  $output:
COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF       NODE NAME
superviso 9874 root  mem    REG         182,492801    83872     524594 /usr/lib64/python2.7/lib-dynload/_socketmodule.so
superviso 9874 root    4u  unix 0xffff881ff9d0a840      0t0 2609143405 /var/run/supervisor/supervisor.sock.9871 
superviso 9874 root   37w   REG         182,492801       21   39588217 /home/frappe/frappe-bench/logs/node-socketio.log
superviso 9874 root   38w   REG         182,492801        0   39588218 /home/frappe/frappe-bench/logs/node-socketio.error.log
superviso 9874 root   52w   REG         182,492801     2162   39588223 /home/frappe/frappe-bench/logs/redis-socketio.log
superviso 9874 root   53w   REG         182,492801        0   39588224 /home/frappe/frappe-bench/logs/redis-socketio.error.log

Ok, Restart EasyInstall once again:

sudo python3 install.py --production --site erp.ikrok.net --user frappe  --verbose --container

Next we can face AGAIN SeLinux policy related error:

 TASK [frappe_selinux : Check enabled SELinux modules] *************************************************************************
 task path: /tmp/.bench/playbooks/roles/frappe_selinux/tasks/main.yml:10

 fatal: [localhost]: FAILED! => {
    "changed": true, 
    "cmd": "semanage module -l", 
    "delta": "0:00:02.268645", 
    "end": "2020-06-23 19:53:43.270595", 
    "invocation": {
        "module_args": {
           "_raw_params": "semanage module -l", 
           "_uses_shell": true, 
           "argv": null, 
           "chdir": null, 
           "creates": null, 
           "executable": null, 
           "removes": null, 
           "stdin": null, 
           "stdin_add_newline": true, 
           "strip_empty_ends": true, 
           "warn": true
       }
   }, 
   "msg": "non-zero return code", 
   "rc": 1, 
   "start": "2020-06-23 19:53:41.001950", 
   "stderr": "ValueError: SELinux policy is not managed or store cannot be accessed.", 
   "stderr_lines": [
       "ValueError: SELinux policy is not managed or store cannot be accessed."

Remove all steps except - name: Install deps from /tmp/.bench/playbooks/roles/frappe_selinux/tasks/main.yml like we did it earlier Start easyinstall once again:

sudo python3 install.py --production --site erp.ikrok.net --user frappe  --verbose --container

#ommited;;long install process..
PLAY RECAP *****************************************************************************************************************************************************************************************
localhost                  : ok=74   changed=30   unreachable=0    failed=0    skipped=61   rescued=0    ignored=0   

Bench + Frappe + ERPNext has been successfully installed!

OK now erpnext in production mode installed using ansible playbooks from easyinstall.py script on Centos 7 .

You may need to start it:

sudo systemctl start supervisord
sudo supervisorctl start all  

And add to autoload the supervisorctl:

sudo systemctl enable supervisord


Check statuses:

sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1204/sshd           
tcp        0      0 127.0.0.1:11000         0.0.0.0:*               LISTEN      9881/redis-server 1 
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      26678/python3.6     
tcp        0      0 127.0.0.1:12000         0.0.0.0:*               LISTEN      9883/redis-server 1 
tcp        0      0 127.0.0.1:13000         0.0.0.0:*               LISTEN      9882/redis-server 1 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      26421/nginx: worker 
tcp6       0      0 :::22                   :::*                    LISTEN      1204/sshd           
tcp6       0      0 :::9000                 :::*                    LISTEN      26679/node          
tcp6       0      0 :::3306                 :::*                    LISTEN      22355/mysqld     

Check supervisorctl status:

sudo supervisorctl

frappe-bench-redis:frappe-bench-redis-cache                 RUNNING   pid 9882, uptime 0:16:44
frappe-bench-redis:frappe-bench-redis-queue                 RUNNING   pid 9881, uptime 0:16:44
frappe-bench-redis:frappe-bench-redis-socketio              RUNNING   pid 9883, uptime 0:16:44
frappe-bench-web:frappe-bench-frappe-web                    RUNNING   pid 26678, uptime 0:03:32
frappe-bench-web:frappe-bench-node-socketio                 RUNNING   pid 26679, uptime 0:03:32
frappe-bench-workers:frappe-bench-frappe-default-worker-0   RUNNING   pid 30103, uptime 0:00:02
frappe-bench-workers:frappe-bench-frappe-long-worker-0      STARTING  
frappe-bench-workers:frappe-bench-frappe-schedule           STARTING  
frappe-bench-workers:frappe-bench-frappe-short-worker-0     STARTING

After that you'll probably note that /assets not loading on your ERPNext website and the site looks broken. You'll probably will require to rebuild bench in order to make /assets work; Here is how can we fix it:

supervisorctl stop all
#go to frappe user
su - frappe
#got to frappe-bench dir
cd frappe-bench
screen
bench build
bench restart

That all: erpnext installed. If you like to reinstall it from scratch with install script add --overwrite arg:

sudo python3 install.py --production --site erp.domain.com --user frappe  --verbose --container --overwrite

Remember to open ports in firewall:

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload


If you go to website and receive the next erorr after login:

Session Start Failed
'ascii' codec can't decode byte 0xd0 in position 1801299: ordinal not in range(128)  

The issues with locale. Brief steps to fix:

localedef -c -f UTF-8 -i en_US en_US.UTF-8
export LC_ALL=en_US.UTF-8

edit /etc/locale.conf and /etc/environment and put utf-8 in CAPS like UTF-8 instead of small characters reboot your server/ VPS check locale again. Should be something like:

locale 
LANG=en_US.utf-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8" 
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8


================================================================================================

In case of any further issues you need to check logs or start bench in debug:

supervisorctl stop all
#go to frappe user
su - frappe
screen  #or screen -R to reattach to existent screen
bench start
#you will se debug output


!!Please be carefull with the update!! -better check and test right after install as there may be differ banch issues or doctypes problems. use for update:

bench update
#or
bench update --reset
#or
bench update --patch 
  • troubleshoot:

Reload doctypes if failed on updates:

bench --force reload-doc core doctype communication_link
bench --force reload-doc core doctype communication


  • reinstall Site

You may reinstall the website if need with bench or with install script. With bench: Make backup of your current config like:

mkdir /home/frappe/backups/
cp -avr /home/frappe/frappe-bench/sites/<your_site> /home/frappe/backups/
bench drop-site <your_site>
bench install 

Install manually from the bench init point. Go to frappe user

su - frappe
#check that you are in home dir : 
pwd
/home/frappe/

Init new bench :

sudo bench init my-bench %% cd my-bench

Add new site:

sudo bench new-site erp.domain.com

Install erp app:

sudo bench get-app erpnext https://github.com/frappe/erpnext
sudo bench --site erp.domain.com install-app erpnext 

Start for check:

sudo bench start

If ok stop and restart via supervisorctl

Setup for production use [assuming you have supervisor installed] :

sudo bench setup production bench
##install supervisor if need: 
#sudo yum -y install supervisor
#sudo systemctl start supervisord
#sudo systemctl enable supervisord

Check:

sudo supervisorctl status all


Enable DNS multy-tenancy in order to use with Let's Encrypt:

bench config dns_multitenant on
sudo bench setup lets-encrypt erp.example.com
bench enable-scheduler