LetsEncrypt setup on recently fixed Easy Install still gives error

Kudos to the team to fix the 2-week long issue with the Installation issue with redis. With that, I was finally able to get the ERPNext installed on a fresh CentOS VPS on DigitalOcean, with the below commands.

sudo yum groupinstall -y 'Development Tools'
sudo yum install -y ansible python3 python3-devel python3-setuptools python3-pip
wget https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py

sudo python3 install.py --production --site enterprise.mageit.in --user valmiki --bench-name erpnext-prod --verbose

The first time I execute the install.py command with the additional parameters (--site enterprise.mageit.in --user valmiki --bench-name erpnext-prod, which are specific to my requirements), it exited with an error code 2, but running the install.py again immediately right after that was successful.

However, when I tried to install and setup LetsEncrypt service for the site, I got the following error:

bench config dns_multitenant on
sudo -H bench setup lets-encrypt enterprise.mageit.in
Running this will stop the nginx service temporarily causing your sites to go offline
Do you want to continue? [y/N]: y
INFO:bench.utils:sudo systemctl stop nginx
INFO:bench.utils:/opt/certbot-auto  --config /etc/letsencrypt/configs/enterprise.mageit.in.cfg certonly
Bootstrapping dependencies for RedHat-based OSes... (you can skip this with --no-bootstrap)
yum is /bin/yum
yum is hashed (/bin/yum)
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.piconets.webwerks.in
 * epel: repos.del.extreme-ix.org
 * extras: mirrors.piconets.webwerks.in
 * updates: mirrors.piconets.webwerks.in
digitalocean-agent                                       | 3.3 kB     00:00
Package gcc-4.8.5-39.el7.x86_64 already installed and latest version
Package 1:openssl-1.0.2k-19.el7.x86_64 already installed and latest version
Package 1:openssl-devel-1.0.2k-19.el7.x86_64 already installed and latest version
Package libffi-devel-3.0.13-18.el7.x86_64 already installed and latest version
Package redhat-rpm-config-9.1.0-88.el7.centos.noarch already installed and latest version
Package ca-certificates-2018.2.22-70.0.el7_5.noarch already installed and latest version
Package python-devel-2.7.5-86.el7.x86_64 already installed and latest version
Package python2-pip-8.1.2-10.el7.noarch already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package augeas-libs.x86_64 0:1.4.0-9.el7 will be installed
---> Package python-tools.x86_64 0:2.7.5-86.el7 will be installed
--> Processing Dependency: tkinter = 2.7.5-86.el7 for package: python-tools-2.7.5-86.el7.x86_64
---> Package python-virtualenv.noarch 0:15.1.0-2.el7 will be installed
--> Running transaction check
---> Package tkinter.x86_64 0:2.7.5-86.el7 will be installed
--> Processing Dependency: libTix.so()(64bit) for package: tkinter-2.7.5-86.el7.x86_64
--> Running transaction check
---> Package tix.x86_64 1:8.4.3-12.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                  Arch          Version               Repository   Size
================================================================================
Installing:
 augeas-libs              x86_64        1.4.0-9.el7           base        356 k
 python-tools             x86_64        2.7.5-86.el7          base        857 k
 python-virtualenv        noarch        15.1.0-2.el7          base        1.7 M
Installing for dependencies:
 tix                      x86_64        1:8.4.3-12.el7        base        254 k
 tkinter                  x86_64        2.7.5-86.el7          base        327 k

Transaction Summary
================================================================================
Install  3 Packages (+2 Dependent packages)

Total download size: 3.4 M
Installed size: 8.1 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): augeas-libs-1.4.0-9.el7.x86_64.rpm                  | 356 kB   00:00
(2/5): python-tools-2.7.5-86.el7.x86_64.rpm                | 857 kB   00:00
(3/5): tix-8.4.3-12.el7.x86_64.rpm                         | 254 kB   00:00
(4/5): python-virtualenv-15.1.0-2.el7.noarch.rpm           | 1.7 MB   00:00
(5/5): tkinter-2.7.5-86.el7.x86_64.rpm                     | 327 kB   00:00
--------------------------------------------------------------------------------
Total                                              6.0 MB/s | 3.4 MB  00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:tix-8.4.3-12.el7.x86_64                                    1/5
  Installing : tkinter-2.7.5-86.el7.x86_64                                  2/5
  Installing : python-tools-2.7.5-86.el7.x86_64                             3/5
  Installing : python-virtualenv-15.1.0-2.el7.noarch                        4/5
  Installing : augeas-libs-1.4.0-9.el7.x86_64                               5/5
  Verifying  : python-tools-2.7.5-86.el7.x86_64                             1/5
  Verifying  : augeas-libs-1.4.0-9.el7.x86_64                               2/5
  Verifying  : tkinter-2.7.5-86.el7.x86_64                                  3/5
  Verifying  : python-virtualenv-15.1.0-2.el7.noarch                        4/5
  Verifying  : 1:tix-8.4.3-12.el7.x86_64                                    5/5

Installed:
  augeas-libs.x86_64 0:1.4.0-9.el7          python-tools.x86_64 0:2.7.5-86.el7
  python-virtualenv.noarch 0:15.1.0-2.el7

Dependency Installed:
  tix.x86_64 1:8.4.3-12.el7            tkinter.x86_64 0:2.7.5-86.el7

Complete!
Creating virtual environment...
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 2327, in <module>
    main()
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 712, in main
    symlink=options.symlink)
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 944, in create_environment
    download=download,
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 900, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 796, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /opt/eff.org/certbot/venv/bin/python2.7 - setuptools pip wheel failed with error code 1
Traceback (most recent call last):
  File "<stdin>", line 27, in <module>
  File "<stdin>", line 19, in create_venv
  File "/usr/lib64/python2.7/subprocess.py", line 542, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['virtualenv', '--no-site-packages', '--python', '/bin/python2.7', '/opt/eff.org/certbot/venv']' returned non-zero exit status 1
INFO:bench.utils:sudo systemctl start nginx
There was a problem trying to setup SSL for your site

I tried fixes suggested at How to make HTTPS for my ERPNext? - #8 by Tudtude by @Tudtude, but intentionally omitted the steps for moving/renaming site1.local to my custom domain (which I already specified in my install.py parameters. I also tried to restart nginx as suggested at Let's Encrypt on website setup with easy install script - #7 by vishdha by @vishdha. But no success yet.

Now I’m inclined to believe that there are errorneous hard-coded dependencies that still point towards default Development environment, such as using the frappe user, or using frappe-bench folder, or using site1.local site, or even python2.7.

Is this a correct assumption, or am I doing something wrong with the LetsEncrypt installation?

PS. BTW, even the bench update throws an error

bench update
Traceback (most recent call last):
  File "/usr/bin/bench", line 11, in <module>
    load_entry_point('bench', 'console_scripts', 'bench')()
  File "/home/valmiki/.bench/bench/cli.py", line 40, in cli
    bench_command()
  File "/usr/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/valmiki/.bench/bench/commands/update.py", line 32, in update
    patches.run(bench_path='.')
  File "/home/valmiki/.bench/bench/patches/__init__.py", line 21, in run
    result = execute(bench_path)
  File "/home/valmiki/.bench/bench/patches/v3/celery_to_rq.py", line 7, in execute
    frappe_branch = get_current_branch('frappe', bench_path)
  File "/home/valmiki/.bench/bench/app.py", line 280, in get_current_branch
    return get_cmd_output("basename $(git symbolic-ref -q HEAD)", cwd=repo_dir)
  File "/home/valmiki/.bench/bench/utils.py", line 370, in get_cmd_output
    output = subprocess.check_output(cmd, cwd=cwd, shell=True, stderr=subprocess.PIPE).strip()
  File "/usr/lib64/python2.7/subprocess.py", line 568, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory: './apps/frappe'

Just a hint; not a solid fact…

I am pretty sure I saw that …

subprocess.CalledProcessError: Command '['virtualenv', '--no-site-packages', '--python', '/bin/python2.7', '/opt/eff.org/certbot/venv']' returned non-zero exit status 1

… earlier today.

I have been building and killing virtual machines for two days, trying to get a consistent clean build of ErpNext and my own NodeJS & CouchDb sites.

At one point I ran sudo apt-get -y install python3-virtualenv; prior to running the ErpNext Easy Install script. That’s when I saw the above “CalledProcessError”, I believe.

I removed the python3-virtualenv install line, and the problem went away.

I am now able to execute a single bash script on my development machine that takes raw installed Ubuntu 18.04 on a VPS all the way to presenting the ErpNext startup wizard over https.

Try this…

fix the Ubuntu 18.04 hostname issues by editing the hostname file to be your URL and make sure it is tied to the right ip address in the hosts file. Then in the cloud.cfg file you need to change the “preserve_hostname” from false to true.

For whatever reason, the form editor is kicking me out when I try to add text that has slashes to indicate directories and sub-directories, so I will have to give you the file locations in a creative format until I figure this out.

File locations

(slash)etc(slash)hostname
(slash)etc(slash)hosts
(slash)etc(slash)cloud(slash)cloud.cfg

Now you reboot the server and complete the setup wizard by log into erpnext as Administrator. Complete the wizard and log out.

Then edit the nginx.py file to change the use of “Unicode” to “bytes”

File location

(slash).bench(slash)bench(slash)config(slash)nginx.py

Finally reboot the server agian and you should be able to install the Lets Encrypt certificate.

Hope this helps. Sorry about the funny file name format but th e forum editor is not allowing the use of some characters.

BKM

Because my experimentation with ErpNext requires many reinstalls I made a function in my scripts to do that ‘uncode’ to ‘bytes’ thing.

@rohitbanerjee
The above issue is due to different python libraries.
Try maintaining your env with the same python version

@Onkar_Mirajkar, I tried on a fresh install without different libraries. Still got errors …