diff --git a/bench/production_setup.py b/bench/production_setup.py index 1b7aa05a..164b649a 100644 --- a/bench/production_setup.py +++ b/bench/production_setup.py @@ -1,6 +1,8 @@ from .utils import get_program, exec_cmd, get_cmd_output from .config import generate_nginx_config, generate_supervisor_config +from jinja2 import Environment, PackageLoader import os +import shutil def restart_service(service): program = get_program(['systemctl', 'service']) @@ -24,12 +26,20 @@ def remove_default_nginx_configs(): if os.path.exists(conf_file): os.unlink(conf_file) + +def is_centos7(): + return os.path.exists('/etc/redhat-release') and get_cmd_output("cat /etc/redhat-release | sed 's/Linux\ //g' | cut -d' ' -f3 | cut -d. -f1").strip() == '7' + + +def copy_default_nginx_config(): + shutil.copy(os.path.join(os.path.dirname(__file__), 'templates', 'nginx_default.conf'), '/etc/nginx/nginx.conf') + def setup_production(bench='.'): generate_supervisor_config(bench=bench) generate_nginx_config(bench=bench) remove_default_nginx_configs() - if os.path.exists('/etc/redhat-release') and get_cmd_output("cat /etc/redhat-release | sed 's/Linux\ //g' | cut -d' ' -f3 | cut -d. -f1").strip() == '7': + if is_centos7(): supervisor_conf_filename = 'frappe.ini' else: supervisor_conf_filename = 'frappe.conf' diff --git a/bench/templates/nginx_default.conf b/bench/templates/nginx_default.conf new file mode 100644 index 00000000..a7604841 --- /dev/null +++ b/bench/templates/nginx_default.conf @@ -0,0 +1,44 @@ +# For more information on configuration, see: +# * Official English Documentation: http://nginx.org/en/docs/ +# * Official Russian Documentation: http://nginx.org/ru/docs/ + +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log; +#error_log /var/log/nginx/error.log notice; +#error_log /var/log/nginx/error.log info; + +pid /run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + + index index.html index.htm; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; +} \ No newline at end of file