Start ERPNext with Debian

So does it work fine when you run bench start?
if erpnext is running fine then its ok just add these to a bash and make it run on every boot.

I did following trying to make erp start with Debian:

  1. I created a script called erpstart.sh in /etc/init.d directory with this code:

#!/bin/sh

cd /home/bench/erpnext
screen bench start

  1. I made sure that the file has executable wright by this command:

chmod 755 /etc/init.d/erpstart.sh

  1. Run: sudo update-rc.d /etc/init.d/erpstart.sh defaults

Am i missing something?

When discussing startup, I think about ERPNext using 2 different “configurations”: Development or Production.

Development Configuration
You install a fresh ERPNext, and run bench start. What happens? The answer is inside a file named “Procfile” in your bench. This Procfile contains a list of instructions. Usually 4 things happen:

  1. Redis databases start
  2. Nodejs Socket.io starts
  3. Frappe event schedulers start
  4. ERPNext web server starts (specifically a WSGI web server from the Werkzeug library).

Note that Nginx is not involved. There is no Nginx when you bench start. ERPNext only starts the Werkzeug web server, with a default port of 8000.

Can I make Linux startup using ERPNext this way?
Sure. There are several ways. A lot depends on your Linux’ init system. Most Linux today are using an init system named “systemd”. It’s a complicated topic. But you can read about creating systemd Service Files. These files are automatically processed by Linux after boot. You can write your own systemd service file, and launch anything you want. Even ‘bench start’, I suppose.

I am glossing over some complexity. But hopefully this helps you get started. But before you do that…

Production Configuration
When you want to run ERPNext in a “production configuration” you execute another command in the terminal:

bench setup production

When you do this, many special functions are called:

  1. ERPNext creates an nginx.conf file.
  2. ERPNext installs a new program on your Linux named Supervisor
  3. ERPNext creates a “supervisor.conf” configuration file.
  4. ERPNext stops using Werkzeug WSGI web server. And starts using Gunicorn web server.

For this thread, the most-interesting piece is Supervisor. It’s a Python program whose purpose is…to start other programs.

  • Supervisor starts automatically when you boot Linux. (because of its own systemd service file)
  • Supervisor launches all the programs named in “supervisor.conf”.

How does this work with ERPNext? Supervisor acts as a sort of “middleware”. When you boot Linux, your init system launches Supervisor. And then Supervisor launches ERPNext. Why? Because its configuration file “supervisor.conf” tells it to launch ERPNext.

But importantly, Supervisor doesn’t run ERPNext the same way as bench start. There are differences. ERPNext is now “hidden” behind an Nginx Reverse Proxy. You can access in your browser on port 80/443, instead of port 8000. And as mentioned, the web server is now Gunicorn.

Summary
Can you write your own scripts to auto-start ERPNext? Definitely.
But first, do some reading and research:

  • Understand that ERPNext can run on 2 different web servers (Werkzeug or Gunicorn). Probably others too, if you knew about how to use them.
  • Understand that ERPNext does not use Nginx by default. You must either bench setup production, or manually configure your own Nginx.
  • ERPNext does not startup by default. Because Supervisor is not configured by default. You must either bench setup production. Manually configure Supervisor yourself. Or design your own way of starting ERPNext at boot.

*Disclaimer : I don’t really like bench setup production, because it automatically does many things, without explaining or asking permission. I consider it very risky, if you’re working in a Production environment. Read about this command, and try it in a TEST environment first, to understand how it changes your server.

6 Likes

My guess is its the Development version which is installed as this needs a manual bench start.

Bench setup production is the right way to setup.
Bench start run the development web server (Werkzeug).
For security you could run your production in a single server.

Wow… thank you a lot foe this answer! The problem was indeed that i was using dev version. I switched to production but not with bench setup production ; i switched manualy by installing supervisor, creating config file and reload it, and doing same thing with nginx.

After that ERP is stating at Debian boot. Thanks a lot!

2 Likes

Hi,

(1) Can you share your setup and config as a guide {meaning remove personal info} ?
(2) Can you update you version of ERPNext & Frappe ?
(3) Can you update from Debian 9 to Debian 10, and ERPNext still works?

Please & Thanks.

ref;

1 Like