def change_apache_port(): dfile = "/etc/cpnginx/data/settings.json" http_port = dataparse.readjsonval(dfile, "APACHE_HTTP_PORT")[0] https_port = dataparse.readjsonval(dfile, "APACHE_HTTPS_PORT")[0] cmdhttp = 'sed -i s/apache_port.*/apache_port=0.0.0.0:' + http_port + '/g /var/cpanel/cpanel.config' cmdhttps = 'sed -i s/apache_ssl_port.*/apache_ssl_port=0.0.0.0:' + https_port + '/g /var/cpanel/cpanel.config' subprocess.call(cmdhttp, shell=True) subprocess.call(cmdhttps, shell=True) subprocess.call(['/usr/local/cpanel/scripts/rebuildhttpdconf'], shell=True) subprocess.call(['/usr/local/cpanel/scripts/restartsrv_httpd'], shell=True)
def install_nginx(version): print "-------------------------------------------------" print shellcolor.blue + "Installing Nginx Web Server version : " + shellcolor.end + shellcolor.green + version + shellcolor.end print "-------------------------------------------------" print "Installing nginx dependencies ..." print shellcolor.bold install_deps() print shellcolor.end source_nginx = conf.SRCDIR + "/nginx-" + version + ".tar.gz" source_nginx_dir = conf.SRCDIR + "/nginx-" + version source_nginx_module = conf.SRCDIR + "/nginx_modules.tar.gz" source_nginx_modulr_dir = conf.SRCDIR + "/nginx_modules" print "Nginx Source File : " + source_nginx print "Nginx build root : " + source_nginx_dir print "Nginx module : " + source_nginx_module print "Nginx module root : " + source_nginx_modulr_dir cleanbuild = "rm -rf " + source_nginx_dir cleadmods = "rm -rf " + source_nginx_modulr_dir subprocess.call(cleanbuild, shell=True) subprocess.call(cleadmods, shell=True) cachedir = "mkdir /var/cache/nginx && chown nobody.nobody /var/cache/nginx" subprocess.call(cachedir, shell=True) if os.path.exists(source_nginx): print "Nginx Source file found .. " + shellcolor.green + "ok" + shellcolor.end else: print "Nginx Source file found .. " + shellcolor.fail + "none" + shellcolor.end download_nginx = conf.wget + " -c " + conf.NGINXDOWNLOAD + "/nginx-" + version + ".tar.gz -O " + source_nginx subprocess.call(download_nginx, shell=True) pagespeed = val = dataparse.readjsonval('/etc/cpnginx/data/settings.json', 'GOOGLE_PAGE_SPEED') configure = "/etc/cpnginx/build/configure.sh" if os.path.exists("/etc/cpnginx/build/custom/configure.sh"): configure = "/etc/cpnginx/build/custom/configure.sh" if pagespeed[0] == "1": if not os.path.exists("/usr/local/nginx/conf/conf.d/pagespeed.conf"): subprocess.call([ 'cp -f /etc/cpnginx/build/templates/conf.d/pagespeed.conf /usr/local/nginx/conf/conf.d/' ], shell=True) if os.path.exists(source_nginx_module): print "Nginx Module Source file found .. " + shellcolor.green + "ok" + shellcolor.end else: print "Nginx Modules Source file found .. " + shellcolor.fail + "none" + shellcolor.end download_nginx_mod = conf.wget + " -c http://files.syslint.com/src/nginx/nginx_modules.tar.gz -O " + source_nginx_module subprocess.call(download_nginx_mod, shell=True) print "Extracting nginx module source files in " + source_nginx_modulr_dir + " please wait ...." extract_nginx_mod = conf.tar + " -xzf " + source_nginx_module + " -C " + conf.SRCDIR subprocess.call(extract_nginx_mod, shell=True) print shellcolor.green + "done" + shellcolor.end time.sleep(3) configure = "/etc/cpnginx/build/configure.pagespeed.sh" if os.path.exists("/etc/cpnginx/build/custom/configure.pagespeed.sh"): configure = "/etc/cpnginx/build/custom/configure.pagespeed.sh" else: if os.path.exists("/usr/local/nginx/conf/conf.d/pagespeed.conf"): os.remove("/usr/local/nginx/conf/conf.d/pagespeed.conf") print "Extracting nginx source files in " + source_nginx_dir extract_nginx = conf.tar + " -xzf " + source_nginx + " -C " + conf.SRCDIR subprocess.call(extract_nginx, shell=True) if os.path.exists(source_nginx_dir): print "Changing builddir to " + source_nginx_dir + " .. " + shellcolor.green + "done" + shellcolor.end os.chdir(source_nginx_dir) subprocess.call("pwd", shell=True) print "Running nginx autoconfigure : " + shellcolor.green + configure + shellcolor.end configure_perm = "chmod 0755 " + configure print configure_perm subprocess.call(configure_perm, shell=True) nginxbuild_cmd = configure + " && make -j" + str( multiprocessing.cpu_count()) + " && make install" print "Executing Nginx Build command .. " + shellcolor.bold + nginxbuild_cmd + shellcolor.end subprocess.call(nginxbuild_cmd, shell=True) else: print "Nginx extraction failed .. unable to install " sys.exist() os.chdir("/usr/local/cpanel/scripts/cpnginx") if not os.path.exists("/usr/local/nginx/sbin/nginx"): print "Nginx installation .. " + shellcolor.fail + "FAILD" + shellcolor.end else: print "Nginx installation .. " + shellcolor.green + "SUCCESS" + shellcolor.end if not os.path.exists("/usr/local/nginx/sbin/nginx"): print shellcolor.fail + " Nginx compile failed . Please contact support" + shellcolor.end sys.exit() setup_nginx_conf() if pagespeed[0] == "0": if os.path.exists("/usr/local/nginx/conf/conf.d/pagespeed.conf"): os.remove("/usr/local/nginx/conf/conf.d/pagespeed.conf") setup_nginx_startup() setup_nginx_chkservd() change_apache_port() rebuild_all_vhost() print shellcolor.yellow subprocess.call(['/usr/local/nginx/sbin/nginx -V'], shell=True) print shellcolor.end restart_nginx()
def get_apache_port_https(): dfile = "/etc/cpnginx/data/settings.json" https_port = dataparse.readjsonval(dfile, "APACHE_HTTPS_PORT")[0] return https_port