def removeNginxConf(self, domain): if os.path.isfile("/etc/nginx/sites-available/{0}".format(domain)): Log.debug(self, "Removing Nginx configuration") EEFileUtils.rm(self, "/etc/nginx/sites-enabled/{0}".format(domain)) EEFileUtils.rm(self, "/etc/nginx/sites-available/{0}".format(domain)) EEService.reload_service(self, "nginx") EEGit.add(self, ["/etc/nginx"], msg="Deleted {0} ".format(domain))
def removeNginxConf(self, domain): if os.path.isfile('/etc/nginx/sites-available/{0}'.format(domain)): Log.debug(self, "Removing Nginx configuration") EEFileUtils.rm(self, '/etc/nginx/sites-enabled/{0}'.format(domain)) EEFileUtils.rm(self, '/etc/nginx/sites-available/{0}'.format(domain)) EEService.reload_service(self, 'nginx') EEGit.add(self, ["/etc/nginx"], msg="Deleted {0} ".format(domain))
def setwebrootpermissions(self, webroot): Log.debug(self, "Setting up permissions") EEFileUtils.chown(self, webroot, EEVariables.ee_php_user, EEVariables.ee_php_user, recursive=True)
def enable(self): if not self.app.pargs.site_name: try: while not self.app.pargs.site_name: self.app.pargs.site_name = (input('Enter site name : ') .strip()) except IOError as e: Log.error(self, 'could not input site name') self.app.pargs.site_name = self.app.pargs.site_name.strip() # validate domain name (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) # check if site exists if not check_domain_exists(self, ee_domain): Log.error(self, "site {0} does not exist".format(ee_domain)) if os.path.isfile('/etc/nginx/sites-available/{0}' .format(ee_domain)): Log.info(self, "Enable domain {0:10} \t".format(ee_domain), end='') EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available/{0}' .format(ee_domain), '/etc/nginx/sites-enabled/{0}' .format(ee_domain)]) EEGit.add(self, ["/etc/nginx"], msg="Enabled {0} " .format(ee_domain)) updateSiteInfo(self, ee_domain, enabled=True) Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]") EEService.reload_service(self, 'nginx') else: Log.error(self, "nginx configuration file does not exist" .format(ee_domain))
def operateOnPagespeed(self, data): ee_domain_name = data['site_name'] ee_site_webroot = data['webroot'] if data['pagespeed'] is True: if not os.path.isfile("{0}/conf/nginx/pagespeed.conf.disabled" .format(ee_site_webroot)): Log.debug(self, 'Writting the Pagespeed common ' 'configuration to file {0}/conf/nginx/pagespeed.conf' 'pagespeed.conf'.format(ee_site_webroot)) ee_nginx = open('{0}/conf/nginx/pagespeed.conf' .format(ee_site_webroot), encoding='utf-8', mode='w') self.app.render((data), 'pagespeed-common.mustache', out=ee_nginx) ee_nginx.close() else: EEFileUtils.mvfile(self, "{0}/conf/nginx/pagespeed.conf.disabled" .format(ee_site_webroot), '{0}/conf/nginx/pagespeed.conf' .format(ee_site_webroot)) elif data['pagespeed'] is False: if os.path.isfile("{0}/conf/nginx/pagespeed.conf" .format(ee_site_webroot)): EEFileUtils.mvfile(self, "{0}/conf/nginx/pagespeed.conf" .format(ee_site_webroot), '{0}/conf/nginx/pagespeed.conf.disabled' .format(ee_site_webroot)) # Add nginx conf folder into GIT EEGit.add(self, ["{0}/conf/nginx".format(ee_site_webroot)], msg="Adding Pagespeed config of site: {0}" .format(ee_domain_name))
def setwebrootpermissions(self, webroot): Log.debug(self, "Setting up permissions") try: EEFileUtils.chown(self, webroot, EEVariables.ee_php_user, EEVariables.ee_php_user, recursive=True) except Exception as e: Log.debug(self, str(e)) raise SiteError("problem occured while settingup webroot permissions")
def hashbucket(self): # Check Nginx Hashbucket error sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) output, error_output = sub.communicate() if 'server_names_hash_bucket_size' not in str(error_output): return True count = 0 # Get the list of sites-availble sites_list = os.listdir("/etc/nginx/sites-enabled/") # Count the number of characters in site names for site in sites_list: count = sum([count, len(site)]) # Calculate Nginx hash bucket size ngx_calc = math.trunc(sum([math.log(count, 2), 2])) ngx_hash = math.trunc(math.pow(2, ngx_calc)) # Replace hashbucket in Nginx.conf file if EEFileUtils.grep(self, "/etc/nginx/nginx.conf", "server_names_hash_bucket_size"): for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1): if "server_names_hash_bucket_size" in line: print("\tserver_names_hash_bucket_size {0};".format(ngx_hash)) else: print(line, end='') else: EEFileUtils.searchreplace(self, '/etc/nginx/nginx.conf', "gzip_disable \"msie6\";", "gzip_disable \"msie6\";\n" "\tserver_names_hash_bucket_size {0};\n" .format(ngx_hash))
def updatewpuserpassword(self, ee_domain, ee_site_webroot): ee_wp_user = "" ee_wp_pass = "" EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot)) # Check if ee_domain is wordpress install try: is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core" " version") except CommandExecutionError as e: raise SiteError("is wordpress site? check command failed ") # Exit if ee_domain is not wordpress install if not is_wp: Log.error(self, "{0} does not seem to be a WordPress site".format(ee_domain)) try: ee_wp_user = input("Provide WordPress user name [admin]: ") except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nCould not update password") if ee_wp_user == "?": Log.info(self, "Fetching WordPress user list") try: EEShellExec.cmd_exec(self, "wp --allow-root user list " "--fields=user_login | grep -v user_login") except CommandExecutionError as e: raise SiteError("fetch wp userlist command failed") if not ee_wp_user: ee_wp_user = "******" try: is_user_exist = EEShellExec.cmd_exec( self, "wp --allow-root user list " "--fields=user_login | grep {0}$ ".format(ee_wp_user) ) except CommandExecutionError as e: raise SiteError("if wp user exists check command failed") if is_user_exist: try: ee_wp_pass = getpass.getpass(prompt="Provide password for " "{0} user: "******"Provide password for " "{0} user: "******"{0}".format(e)) raise SiteError("failed to read password input ") try: EEShellExec.cmd_exec( self, "wp --allow-root user update {0}" " --user_pass={1}".format(ee_wp_user, ee_wp_pass) ) except CommandExecutionError as e: raise SiteError("wp user password update command failed") Log.info(self, "Password updated successfully") else: Log.error(self, "Invalid WordPress user {0} for {1}.".format(ee_wp_user, ee_domain))
def uninstallwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] Log.debug(self, "Uninstalling plugin {0}".format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root uninstall " "{0}".format(plugin_name), errormsg="Unable to UnInstall plugin {0}" .format(plugin_name))
def setupwordpressnetwork(self, data): ee_site_webroot = data['webroot'] EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) Log.info(self, "Setting up WordPress Network \t", end='') EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert' ' --title=\'{0}\' {subdomains}' .format(data['www_domain'], subdomains='--subdomains' if not data['wpsubdir'] else '')) Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
def uninstallwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] Log.debug(self, "Uninstalling plugin {0}".format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEShellExec.cmd_exec( self, "php /usr/bin/wp plugin --allow-root uninstall " "{0}".format(plugin_name), errormsg="Unable to UnInstall plugin {0}".format(plugin_name))
def updatewpuserpassword(self, ee_domain, ee_site_webroot): ee_wp_user = '' ee_wp_pass = '' EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) # Check if ee_domain is wordpress install is_wp = EEShellExec.cmd_exec( self, "wp --allow-root core" " version", errormsg="{0} : Unable to check if wp install".format(ee_domain)) # Exit if ee_domain is not wordpress install if not is_wp: Log.error(self, "{0} does not seem to be a WordPress site".format(ee_domain)) try: ee_wp_user = input("Provide WordPress user name [admin]: ") except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nCould not update password") if ee_wp_user == "?": Log.info(self, "Fetching WordPress user list") EEShellExec.cmd_exec(self, "wp --allow-root user list " "--fields=user_login | grep -v user_login", errormsg="Unable to Fetch users list") if not ee_wp_user: ee_wp_user = '******' is_user_exist = EEShellExec.cmd_exec( self, "wp --allow-root user list " "--fields=user_login | grep {0}$ ".format(ee_wp_user)) if is_user_exist: try: ee_wp_pass = getpass.getpass(prompt="Provide password for " "{0} user: "******"{0}".format(e)) Log.error(self, "Could not update password") if len(ee_wp_pass) > 8: EEShellExec.cmd_exec( self, "wp --allow-root user update {0}" " --user_pass={1}".format(ee_wp_user, ee_wp_pass)) Log.info(self, "Password updated successfully") else: Log.error( self, "Password Unchanged. Hint : Your password must be " "8 characters long") else: Log.error( self, "Invalid WordPress user {0} for {1}.".format( ee_wp_user, ee_domain))
def upgrade_php56(self): if EEVariables.ee_platform_distro == "ubuntu": if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}." "list".format(EEVariables.ee_platform_codename)): Log.error(self, "Unable to find PHP 5.5") else: if not (os.path.isfile(EEVariables.ee_repo_file_path) and EEFileUtils.grep(self, EEVariables.ee_repo_file_path, "php55")): Log.error(self, "Unable to find PHP 5.5") Log.info( self, "During PHP update process non nginx-cached" " parts of your site may remain down.") # Check prompt if (not self.app.pargs.no_prompt): start_upgrade = input("Do you want to continue:[y/N]") if start_upgrade != "Y" and start_upgrade != "y": Log.error(self, "Not starting PHP package update") if EEVariables.ee_platform_distro == "ubuntu": EERepo.remove(self, ppa="ppa:ondrej/php5") EERepo.add(self, ppa=EEVariables.ee_php_repo) else: EEAptGet.remove(self, ["php5-xdebug"]) EEFileUtils.searchreplace(self, EEVariables.ee_repo_file_path, "php55", "php56") Log.info(self, "Updating apt-cache, please wait...") EEAptGet.update(self) Log.info(self, "Installing packages, please wait ...") if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial' or EEVariables.ee_platform_codename == 'bionic'): EEAptGet.install(self, EEVariables.ee_php5_6 + EEVariables.ee_php_extra) else: EEAptGet.install(self, EEVariables.ee_php) if EEVariables.ee_platform_distro == "debian": EEShellExec.cmd_exec(self, "pecl install xdebug") with open("/etc/php5/mods-available/xdebug.ini", encoding='utf-8', mode='a') as myfile: myfile.write(";zend_extension=/usr/lib/php5/20131226/" "xdebug.so\n") EEFileUtils.create_symlink(self, [ "/etc/php5/mods-available/" "xdebug.ini", "/etc/php5/fpm/conf.d" "/20-xedbug.ini" ]) Log.info(self, "Successfully upgraded from PHP 5.5 to PHP 5.6")
def sync(self): """ 1. reads database information from wp/ee-config.php 2. updates records into ee database accordingly. """ Log.info(self, "Synchronizing ee database, please wait...") sites = getAllsites(self) if not sites: pass for site in sites: if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: ee_site_webroot = site.site_path # Read config files configfiles = glob.glob(ee_site_webroot + '/*-config.php') if configfiles: if EEFileUtils.isexist(self, configfiles[0]): ee_db_name = (EEFileUtils.grep(self, configfiles[0], 'DB_NAME').split(',') [1].split(')')[0].strip().replace( '\'', '')) ee_db_user = (EEFileUtils.grep(self, configfiles[0], 'DB_USER').split(',') [1].split(')')[0].strip().replace( '\'', '')) ee_db_pass = (EEFileUtils.grep( self, configfiles[0], 'DB_PASSWORD').split(',')[1].split(')') [0].strip().replace('\'', '')) ee_db_host = (EEFileUtils.grep(self, configfiles[0], 'DB_HOST').split(',') [1].split(')')[0].strip().replace( '\'', '')) # Check if database really exist try: if not EEMysql.check_db_exists(self, ee_db_name): # Mark it as deleted if not exist ee_db_name = 'deleted' ee_db_user = '******' ee_db_pass = '******' except StatementExcecutionError as e: Log.debug(self, str(e)) except Exception as e: Log.debug(self, str(e)) if site.db_name != ee_db_name: # update records if any mismatch found Log.debug( self, "Updating ee db record for {0}".format( site.sitename)) updateSiteInfo(self, site.sitename, db_name=ee_db_name, db_user=ee_db_user, db_password=ee_db_pass, db_host=ee_db_host)
def updatewpuserpassword(self, ee_domain, ee_site_webroot): ee_wp_user = '' ee_wp_pass = '' EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) # Check if ee_domain is wordpress install is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core" " version", errormsg="{0} : Unable to check if wp install" .format(ee_domain)) # Exit if ee_domain is not wordpress install if not is_wp: Log.error(self, "{0} does not seem to be a WordPress site" .format(ee_domain)) try: ee_wp_user = input("Provide WordPress user name [admin]: ") except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nCould not update password") if ee_wp_user == "?": Log.info(self, "Fetching WordPress user list") EEShellExec.cmd_exec(self, "wp --allow-root user list " "--fields=user_login | grep -v user_login", errormsg="Unable to Fetch users list") if not ee_wp_user: ee_wp_user = '******' is_user_exist = EEShellExec.cmd_exec(self, "wp --allow-root user list " "--fields=user_login | grep {0}$ " .format(ee_wp_user)) if is_user_exist: try: ee_wp_pass = getpass.getpass(prompt="Provide password for " "{0} user: "******"{0}".format(e)) Log.error(self, "Could not update password") if len(ee_wp_pass) > 8: EEShellExec.cmd_exec(self, "wp --allow-root user update {0}" " --user_pass={1}" .format(ee_wp_user, ee_wp_pass)) Log.info(self, "Password updated successfully") else: Log.error(self, "Password Unchanged. Hint : Your password must be " "8 characters long") else: Log.error(self, "Invalid WordPress user {0} for {1}." .format(ee_wp_user, ee_domain))
def setupwordpressnetwork(self, data): ee_site_webroot = data['webroot'] EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) Log.info(self, "Setting up WordPress Network \t", end='') EEShellExec.cmd_exec( self, 'wp --allow-root core multisite-convert' ' --title={0} {subdomains}'.format( data['www_domain'], subdomains='--subdomains' if not data['wpsubdir'] else '')) Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
def uninstallwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] Log.debug(self, "Uninstalling plugin {0}, please wait..." .format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) try: EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin " "--allow-root uninstall " "{0}".format(plugin_name)) except CommandExecutionError as e: raise SiteError("plugin uninstall failed")
def add(self): """Swap addition with EasyEngine""" if EEVariables.ee_ram < 512: if EEVariables.ee_swap < 1000: Log.info(self, "Adding SWAP") EEShellExec.cmd_exec(self, "dd if=/dev/zero of=/ee-swapfile " "bs=1024 count=1048k") EEShellExec.cmd_exec(self, "mkswap /ee-swapfile") EEFileUtils.chown(self, "/ee-swapfile", "root", "root") EEFileUtils.chmod(self, "/ee-swapfile", 0o600) EEShellExec.cmd_exec(self, "swapon /ee-swapfile") with open("/etc/fstab", encoding="utf-8", mode="a") as swap_file: swap_file.write("/ee-swapfile\tnone\tswap\tsw\t0 0")
def uninstallwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] Log.debug(self, "Uninstalling plugin {0}, please wait...".format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) try: EEShellExec.cmd_exec( self, "php /usr/bin/wp plugin " "--allow-root uninstall " "{0}".format(plugin_name)) except CommandExecutionError as e: raise SiteError("plugin uninstall failed")
def debug_php(self): """Start/Stop PHP debug""" # PHP global debug start if (self.app.pargs.php == 'on' and not self.app.pargs.site_name): if not (EEShellExec.cmd_exec(self, "sed -n \"/upstream php" "{/,/}/p \" /etc/nginx/" "conf.d/upstream.conf " "| grep 9001")): Log.info(self, "Enabling PHP debug") data = dict(php="9001", debug="9001", hhvm="9001") Log.debug(self, 'Writting the Nginx debug configration to file' ' /etc/nginx/conf.d/upstream.conf ') ee_nginx = open('/etc/nginx/conf.d/upstream.conf', encoding='utf-8', mode='w') self.app.render((data), 'upstream.mustache', out=ee_nginx) ee_nginx.close() # Enable xdebug EEFileUtils.searchreplace(self, "/etc/php5/mods-available/" "xdebug.ini", ";zend_extension", "zend_extension") self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP debug is already enabled") self.msg = self.msg + ['/var/log/php5/slow.log'] # PHP global debug stop elif (self.app.pargs.php == 'off' and not self.app.pargs.site_name): if EEShellExec.cmd_exec(self, " sed -n \"/upstream php {/,/}/p\" " "/etc/nginx/conf.d/upstream.conf " "| grep 9001"): Log.info(self, "Disabling PHP debug") data = dict(php="9000", debug="9001", hhvm="8000") Log.debug(self, 'Writting the Nginx debug configration to file' ' /etc/nginx/conf.d/upstream.conf ') ee_nginx = open('/etc/nginx/conf.d/upstream.conf', encoding='utf-8', mode='w') self.app.render((data), 'upstream.mustache', out=ee_nginx) ee_nginx.close() # Disable xdebug EEFileUtils.searchreplace(self, "/etc/php5/mods-available/" "xdebug.ini", "zend_extension", ";zend_extension") self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP debug is already disabled")
def add(self): """Swap addition with EasyEngine""" if EEVariables.ee_ram < 512: if EEVariables.ee_swap < 1000: Log.info(self, "Adding SWAP") EEShellExec.cmd_exec(self, "dd if=/dev/zero of=/ee-swapfile " "bs=1024 count=1048k") EEShellExec.cmd_exec(self, "mkswap /ee-swapfile") EEFileUtils.chown(self, "/ee-swapfile", "root", "root") EEFileUtils.chmod(self, "/ee-swapfile", 0o600) EEShellExec.cmd_exec(self, "swapon /ee-swapfile") with open("/etc/fstab", encoding='utf-8', mode='a') as swap_file: swap_file.write("/ee-swapfile\tnone\tswap\tsw\t0 0")
def setupwordpressnetwork(self, data): ee_site_webroot = data['webroot'] EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) Log.info(self, "Setting up WordPress Network \t", end='') try: EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert' ' --title=\'{0}\' {subdomains}' .format(data['www_domain'], subdomains='--subdomains' if not data['wpsubdir'] else '')) except CommandExecutionError as e: Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") raise SiteError("setup wordpress network failed") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
def deleteWebRoot(self, webroot): # do some preprocessing before proceeding webroot = webroot.strip() if webroot == "/var/www/" or webroot == "/var/www" or webroot == "/var/www/.." or webroot == "/var/www/.": Log.debug(self, "Tried to remove {0}, but didn't remove it".format(webroot)) return False if os.path.isdir(webroot): Log.debug(self, "Removing {0}".format(webroot)) EEFileUtils.rm(self, webroot) return True else: Log.debug(self, "{0} does not exist".format(webroot)) return False
def sync(self): """ 1. reads database information from wp/ee-config.php 2. updates records into ee database accordingly. """ Log.info(self, "Synchronizing ee database, please wait...") sites = getAllsites(self) if not sites: pass for site in sites: if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: ee_site_webroot = site.site_path # Read config files configfiles = glob.glob(ee_site_webroot + '/*-config.php') if configfiles: if EEFileUtils.isexist(self, configfiles[0]): ee_db_name = (EEFileUtils.grep(self, configfiles[0], 'DB_NAME').split(',')[1] .split(')')[0].strip().replace('\'', '')) ee_db_user = (EEFileUtils.grep(self, configfiles[0], 'DB_USER').split(',')[1] .split(')')[0].strip().replace('\'', '')) ee_db_pass = (EEFileUtils.grep(self, configfiles[0], 'DB_PASSWORD').split(',')[1] .split(')')[0].strip().replace('\'', '')) ee_db_host = (EEFileUtils.grep(self, configfiles[0], 'DB_HOST').split(',')[1] .split(')')[0].strip().replace('\'', '')) # Check if database really exist try: if not EEMysql.check_db_exists(self, ee_db_name): # Mark it as deleted if not exist ee_db_name = 'deleted' ee_db_user = '******' ee_db_pass = '******' except StatementExcecutionError as e: Log.debug(self, str(e)) except Exception as e: Log.debug(self, str(e)) if site.db_name != ee_db_name: # update records if any mismatch found Log.debug(self, "Updating ee db record for {0}" .format(site.sitename)) updateSiteInfo(self, site.sitename, db_name=ee_db_name, db_user=ee_db_user, db_password=ee_db_pass, db_host=ee_db_host)
def upgrade_php56(self): if EEVariables.ee_platform_distro == "ubuntu": if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}." "list".format(EEVariables.ee_platform_codename)): Log.error(self, "Unable to find PHP 5.5") else: if not(os.path.isfile(EEVariables.ee_repo_file_path) and EEFileUtils.grep(self, EEVariables.ee_repo_file_path, "php55")): Log.error(self, "Unable to find PHP 5.5") Log.info(self, "During PHP update process non nginx-cached" " parts of your site may remain down.") # Check prompt if (not self.app.pargs.no_prompt): start_upgrade = input("Do you want to continue:[y/N]") if start_upgrade != "Y" and start_upgrade != "y": Log.error(self, "Not starting PHP package update") if EEVariables.ee_platform_distro == "ubuntu": EERepo.remove(self, ppa="ppa:ondrej/php5") EERepo.add(self, ppa=EEVariables.ee_php_repo) else: EEAptGet.remove(self, ["php5-xdebug"]) EEFileUtils.searchreplace(self, EEVariables.ee_repo_file_path, "php55", "php56") Log.info(self, "Updating apt-cache, please wait...") EEAptGet.update(self) Log.info(self, "Installing packages, please wait ...") if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial'): EEAptGet.install(self, EEVariables.ee_php5_6 + EEVariables.ee_php_extra) else: EEAptGet.install(self, EEVariables.ee_php) if EEVariables.ee_platform_distro == "debian": EEShellExec.cmd_exec(self, "pecl install xdebug") with open("/etc/php5/mods-available/xdebug.ini", encoding='utf-8', mode='a') as myfile: myfile.write(";zend_extension=/usr/lib/php5/20131226/" "xdebug.so\n") EEFileUtils.create_symlink(self, ["/etc/php5/mods-available/" "xdebug.ini", "/etc/php5/fpm/conf.d" "/20-xedbug.ini"]) Log.info(self, "Successfully upgraded from PHP 5.5 to PHP 5.6")
def installwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] Log.info(self, "Installing plugin {0}".format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root install " "{0}".format(plugin_name), errormsg="Unable to Install plugin {0}" .format(plugin_name)) EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root activate " "{0} {na}" .format(plugin_name, na='--network' if data['multisite'] else ''), errormsg="Unable to Activate plugin {0}" .format(plugin_name))
def deleteWebRoot(self, webroot): # do some preprocessing before proceeding webroot = webroot.strip() if (webroot == "/var/www/" or webroot == "/var/www" or webroot == "/var/www/.." or webroot == "/var/www/."): Log.debug(self, "Tried to remove {0}, but didn't remove it" .format(webroot)) return False if os.path.isdir(webroot): Log.debug(self, "Removing {0}".format(webroot)) EEFileUtils.rm(self, webroot) return True else: Log.debug(self, "{0} does not exist".format(webroot)) return False
def installwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] Log.debug(self, "Installing plugin {0}".format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEShellExec.cmd_exec( self, "php /usr/bin/wp plugin --allow-root install " "{0}".format(plugin_name), errormsg="Unable to Install plugin {0}".format(plugin_name)) EEShellExec.cmd_exec( self, "php /usr/bin/wp plugin --allow-root activate " "{0} {na}".format(plugin_name, na='--network' if data['multisite'] else ''), errormsg="Unable to Activate plugin {0}".format(plugin_name))
def uninstallwp_plugin(self, plugin_name, data): ee_site_webroot = data["webroot"] Log.debug(self, "Uninstalling plugin {0}, please wait...".format(plugin_name)) EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot)) Log.info(self, "Uninstalling plugin {0}, please wait...".format(plugin_name)) try: EEShellExec.cmd_exec( self, "php {0} plugin ".format(EEVariables.ee_wpcli_path) + "--allow-root deactivate " "{0}".format(plugin_name), ) EEShellExec.cmd_exec( self, "php {0} plugin ".format(EEVariables.ee_wpcli_path) + "--allow-root uninstall " "{0}".format(plugin_name), ) except CommandExecutionError as e: raise SiteError("plugin uninstall failed")
def uninstallwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] Log.debug(self, "Uninstalling plugin {0}, please wait..." .format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) Log.info(self, "Uninstalling plugin {0}, please wait..." .format(plugin_name)) try: EEShellExec.cmd_exec(self, "php {0} plugin " .format(EEVariables.ee_wpcli_path) + "--allow-root deactivate " "{0}".format(plugin_name)) EEShellExec.cmd_exec(self, "php {0} plugin " .format(EEVariables.ee_wpcli_path) + "--allow-root uninstall " "{0}".format(plugin_name)) except CommandExecutionError as e: raise SiteError("plugin uninstall failed")
def installwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] Log.info(self, "Installing plugin {0}, please wait...".format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) try: EEShellExec.cmd_exec( self, "php /usr/bin/wp plugin " "--allow-root install " "{0}".format(plugin_name)) except CommandExecutionError as e: raise SiteError("plugin installation failed") try: EEShellExec.cmd_exec( self, "php /usr/bin/wp plugin " "--allow-root activate " "{0} {na}".format(plugin_name, na='--network' if data['multisite'] else '')) except CommandExecutionError as e: raise SiteError("plugin activation failed")
def setupwordpressnetwork(self, data): ee_site_webroot = data["webroot"] EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot)) Log.info(self, "Setting up WordPress Network \t", end="") try: if EEShellExec.cmd_exec( self, "wp --allow-root core multisite-convert" " --title='{0}' {subdomains}".format( data["www_domain"], subdomains="--subdomains" if not data["wpsubdir"] else "" ), ): pass else: Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") raise SiteError("setup wordpress network failed") except CommandExecutionError as e: Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") raise SiteError("setup wordpress network failed") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
def add(self): """Swap addition with EasyEngine""" if EEVariables.ee_ram < 512: if EEVariables.ee_swap < 1000: Log.info(self, "Adding SWAP file, please wait...") # Install dphys-swapfile EEAptGet.update(self) EEAptGet.install(self, ["dphys-swapfile"]) # Stop service EEShellExec.cmd_exec(self, "service dphys-swapfile stop") # Remove Default swap created EEShellExec.cmd_exec(self, "/sbin/dphys-swapfile uninstall") # Modify Swap configuration if os.path.isfile("/etc/dphys-swapfile"): EEFileUtils.searchreplace(self, "/etc/dphys-swapfile", "#CONF_SWAPFILE=/var/swap", "CONF_SWAPFILE=/ee-swapfile") EEFileUtils.searchreplace(self, "/etc/dphys-swapfile", "#CONF_MAXSWAP=2048", "CONF_MAXSWAP=1024") EEFileUtils.searchreplace(self, "/etc/dphys-swapfile", "#CONF_SWAPSIZE=", "CONF_SWAPSIZE=1024") else: with open("/etc/dphys-swapfile", 'w') as conffile: conffile.write("CONF_SWAPFILE=/ee-swapfile\n" "CONF_SWAPSIZE=1024\n" "CONF_MAXSWAP=1024\n") # Create swap file EEShellExec.cmd_exec(self, "service dphys-swapfile start")
def add(self): """Swap addition with EasyEngine""" if EEVariables.ee_ram < 512: if EEVariables.ee_swap < 1000: Log.info(self, "Adding SWAP") # Install dphys-swapfile EEAptGet.update(self) EEAptGet.install(self, ["dphys-swapfile"]) # Stop service EEShellExec.cmd_exec(self, "service dphys-swapfile stop") # Remove Default swap created EEShellExec.cmd_exec(self, "/sbin/dphys-swapfile uninstall") # Modify Swap configuration if os.path.isfile("/etc/dphys-swapfile"): EEFileUtils.searchreplace(self, "/etc/dphys-swapfile", "#CONF_SWAPFILE=/var/swap", "CONF_SWAPFILE=/ee-swapfile") EEFileUtils.searchreplace(self, "/etc/dphys-swapfile", "#CONF_MAXSWAP=2048", "CONF_MAXSWAP=1024") EEFileUtils.searchreplace(self, "/etc/dphys-swapfile", "#CONF_SWAPSIZE=", "CONF_SWAPSIZE=1024") else: with open("/etc/dphys-swapfile", 'w') as conffile: conffile.write("CONF_SWAPFILE=/ee-swapfile\n" "CONF_SWAPSIZE=1024\n" "CONF_MAXSWAP=1024\n") # Create swap file EEShellExec.cmd_exec(self, "service dphys-swapfile start")
def installwp_plugin(self, plugin_name, data): ee_site_webroot = data["webroot"] Log.info(self, "Installing plugin {0}, please wait...".format(plugin_name)) EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot)) try: EEShellExec.cmd_exec( self, "php {0} plugin ".format(EEVariables.ee_wpcli_path) + "--allow-root install " "{0}".format(plugin_name), ) except CommandExecutionError as e: raise SiteError("plugin installation failed") try: EEShellExec.cmd_exec( self, "php {0} plugin ".format(EEVariables.ee_wpcli_path) + "--allow-root activate " "{0} {na}".format(plugin_name, na="--network" if data["multisite"] else ""), ) except CommandExecutionError as e: raise SiteError("plugin activation failed") return 1
def installwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] Log.info(self, "Installing plugin {0}, please wait..." .format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) try: EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin " "--allow-root install " "{0}".format(plugin_name)) except CommandExecutionError as e: raise SiteError("plugin installation failed") try: EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin " "--allow-root activate " "{0} {na}" .format(plugin_name, na='--network' if data['multisite'] else '' )) except CommandExecutionError as e: raise SiteError("plugin activation failed")
def cd(self): if not self.app.pargs.site_name: try: while not self.app.pargs.site_name: self.app.pargs.site_name = (input('Enter site name : ') .strip()) except IOError as e: Log.error(self, 'Unable to read input, please try again') self.app.pargs.site_name = self.app.pargs.site_name.strip() (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) if not check_domain_exists(self, ee_domain): Log.error(self, "site {0} does not exist".format(ee_domain)) ee_site_webroot = getSiteInfo(self, ee_domain).site_path EEFileUtils.chdir(self, ee_site_webroot) try: subprocess.call(['bash']) except OSError as e: Log.debug(self, "{0}{1}".format(e.errno, e.strerror)) Log.error(self, "unable to change directory")
def setupwp_plugin(self, plugin_name, plugin_option, plugin_data, data): ee_site_webroot = data["webroot"] Log.info(self, "Setting plugin {0}, please wait...".format(plugin_name)) EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot)) if not data["multisite"]: try: EEShellExec.cmd_exec( self, "php {0} ".format(EEVariables.ee_wpcli_path) + "--allow-root option update " "{0} '{1}' --format=json".format(plugin_option, plugin_data), ) except CommandExecutionError as e: raise SiteError("plugin setup failed") else: try: EEShellExec.cmd_exec( self, "php {0} ".format(EEVariables.ee_wpcli_path) + "--allow-root network meta update 1 " "{0} '{1}' --format=json".format(plugin_option, plugin_data), ) except CommandExecutionError as e: raise SiteError("plugin setup failed")
def operateOnPagespeed(self, data): ee_domain_name = data["site_name"] ee_site_webroot = data["webroot"] if data["pagespeed"] is True: if not os.path.isfile("{0}/conf/nginx/pagespeed.conf.disabled".format(ee_site_webroot)): Log.debug( self, "Writting the Pagespeed common " "configuration to file {0}/conf/nginx/pagespeed.conf" "pagespeed.conf".format(ee_site_webroot), ) ee_nginx = open("{0}/conf/nginx/pagespeed.conf".format(ee_site_webroot), encoding="utf-8", mode="w") self.app.render((data), "pagespeed-common.mustache", out=ee_nginx) ee_nginx.close() else: EEFileUtils.mvfile( self, "{0}/conf/nginx/pagespeed.conf.disabled".format(ee_site_webroot), "{0}/conf/nginx/pagespeed.conf".format(ee_site_webroot), ) elif data["pagespeed"] is False: if os.path.isfile("{0}/conf/nginx/pagespeed.conf".format(ee_site_webroot)): EEFileUtils.mvfile( self, "{0}/conf/nginx/pagespeed.conf".format(ee_site_webroot), "{0}/conf/nginx/pagespeed.conf.disabled".format(ee_site_webroot), ) # Add nginx conf folder into GIT EEGit.add( self, ["{0}/conf/nginx".format(ee_site_webroot)], msg="Adding Pagespeed config of site: {0}".format(ee_domain_name), )
def setupwp_plugin(self, plugin_name, plugin_option, plugin_data, data): ee_site_webroot = data['webroot'] Log.info(self, "Setting plugin {0}, please wait..." .format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) if not data['multisite']: try: EEShellExec.cmd_exec(self, "php {0} " .format(EEVariables.ee_wpcli_path) + "--allow-root option update " "{0} \'{1}\' --format=json".format(plugin_option, plugin_data)) except CommandExecutionError as e: raise SiteError("plugin setup failed") else: try: EEShellExec.cmd_exec(self, "php {0} " .format(EEVariables.ee_wpcli_path) + "--allow-root network meta update 1 " "{0} \'{1}\' --format=json" .format(plugin_option, plugin_data )) except CommandExecutionError as e: raise SiteError("plugin setup failed")
def hashbucket(self): # Check Nginx Hashbucket error sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) output, error_output = sub.communicate() if 'server_names_hash_bucket_size' not in str(error_output): return True count = 0 # Get the list of sites-availble sites_list = os.listdir("/etc/nginx/sites-enabled/") # Count the number of characters in site names for site in sites_list: count = sum([count, len(site)]) # Calculate Nginx hash bucket size ngx_calc = math.trunc(sum([math.log(count, 2), 2])) ngx_hash = math.trunc(math.pow(2, ngx_calc)) # Replace hashbucket in Nginx.conf file if EEFileUtils.grep(self, "/etc/nginx/nginx.conf", "server_names_hash_bucket_size"): for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1): if "server_names_hash_bucket_size" in line: print("\tserver_names_hash_bucket_size {0};".format(ngx_hash)) else: print(line, end='') else: EEFileUtils.searchreplace( self, '/etc/nginx/nginx.conf', "gzip_disable \"msie6\";", "gzip_disable \"msie6\";\n" "\tserver_names_hash_bucket_size {0};\n".format(ngx_hash))
def setupdomain(self, data): ee_domain_name = data['site_name'] ee_site_webroot = data['webroot'] Log.info(self, "Setting up NGINX configuration \t", end='') # write nginx config for file try: ee_site_nginx_conf = open( '/etc/nginx/sites-available/{0}'.format(ee_domain_name), encoding='utf-8', mode='w') self.app.render((data), 'virtualconf.mustache', out=ee_site_nginx_conf) ee_site_nginx_conf.close() except IOError as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nUnable to create NGINX configuration") except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nUnable to create NGINX configuration") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") # create symbolic link for EEFileUtils.create_symlink(self, [ '/etc/nginx/sites-available/{0}'.format(ee_domain_name), '/etc/nginx/sites-enabled/{0}'.format(ee_domain_name) ]) # Creating htdocs & logs directory Log.info(self, "Setting up webroot \t\t", end='') try: if not os.path.exists('{0}/htdocs'.format(ee_site_webroot)): os.makedirs('{0}/htdocs'.format(ee_site_webroot)) if not os.path.exists('{0}/logs'.format(ee_site_webroot)): os.makedirs('{0}/logs'.format(ee_site_webroot)) except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nUnable to setup webroot") EEFileUtils.create_symlink(self, [ '/var/log/nginx/{0}.access.log'.format(ee_domain_name), '{0}/logs/access.log'.format(ee_site_webroot) ]) EEFileUtils.create_symlink(self, [ '/var/log/nginx/{0}.error.log'.format(ee_domain_name), '{0}/logs/error.log'.format(ee_site_webroot) ]) Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
def setupdomain(self, data): ee_domain_name = data['site_name'] ee_site_webroot = data['webroot'] Log.info(self, "Setting up NGINX configuration \t", end='') # write nginx config for file try: ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}' .format(ee_domain_name), encoding='utf-8', mode='w') self.app.render((data), 'virtualconf.mustache', out=ee_site_nginx_conf) ee_site_nginx_conf.close() except IOError as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nUnable to create NGINX configuration") except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nUnable to create NGINX configuration") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") # create symbolic link for EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available/{0}' .format(ee_domain_name), '/etc/nginx/sites-enabled/{0}' .format(ee_domain_name)]) # Creating htdocs & logs directory Log.info(self, "Setting up webroot \t\t", end='') try: if not os.path.exists('{0}/htdocs'.format(ee_site_webroot)): os.makedirs('{0}/htdocs'.format(ee_site_webroot)) if not os.path.exists('{0}/logs'.format(ee_site_webroot)): os.makedirs('{0}/logs'.format(ee_site_webroot)) except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nUnable to setup webroot") EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log' .format(ee_domain_name), '{0}/logs/access.log' .format(ee_site_webroot)]) EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.error.log' .format(ee_domain_name), '{0}/logs/error.log' .format(ee_site_webroot)]) Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
def debug_php7(self): """Start/Stop PHP debug""" # PHP global debug start if (self.app.pargs.php7 == 'on' and not self.app.pargs.site_name): if (EEVariables.ee_platform_codename == 'wheezy' or EEVariables.ee_platform_codename == 'precise'): Log.error(self,"PHP 7.0 not supported.") if not (EEShellExec.cmd_exec(self, "sed -n \"/upstream php7" "{/,/}/p \" /etc/nginx/" "conf.d/upstream.conf " "| grep 9170")): Log.info(self, "Enabling PHP 7.0 debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([('upstream','php',), 'server'], '127.0.0.1:9170') if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"): nc.set([('upstream','hhvm',), 'server'], '127.0.0.1:9170') nc.savef('/etc/nginx/conf.d/upstream.conf') # Enable xdebug if (EEVariables.ee_platform_codename != 'jessie'): EEFileUtils.searchreplace(self, "/etc/php/7.0/mods-available/" "xdebug.ini", ";zend_extension", "zend_extension") else: EEFileUtils.searchreplace(self, "/etc/php/mods-available/" "xdebug.ini", ";zend_extension", "zend_extension") # Fix slow log is not enabled default in PHP5.6 config = configparser.ConfigParser() config.read('/etc/php/7.0/fpm/pool.d/debug.conf') config['debug']['slowlog'] = '/var/log/php/7.0/slow.log' config['debug']['request_slowlog_timeout'] = '10s' with open('/etc/php/7.0/fpm/pool.d/debug.conf', encoding='utf-8', mode='w') as confifile: Log.debug(self, "Writting debug.conf configuration into " "/etc/php/7.0/fpm/pool.d/debug.conf") config.write(confifile) self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP debug is already enabled") self.msg = self.msg + ['/var/log/php/7.0/slow.log'] # PHP global debug stop elif (self.app.pargs.php7 == 'off' and not self.app.pargs.site_name): if EEShellExec.cmd_exec(self, " sed -n \"/upstream php {/,/}/p\" " "/etc/nginx/conf.d/upstream.conf " "| grep 9170"): Log.info(self, "Disabling PHP 7.0 debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([('upstream','php',), 'server'], '127.0.0.1:9070') if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"): nc.set([('upstream','hhvm',), 'server'], '127.0.0.1:8000') nc.savef('/etc/nginx/conf.d/upstream.conf') # Disable xdebug if (EEVariables.ee_platform_codename != 'jessie'): EEFileUtils.searchreplace(self, "/etc/php/7.0/mods-available/" "xdebug.ini", "zend_extension", ";zend_extension") else: EEFileUtils.searchreplace(self, "/etc/php/mods-available/" "xdebug.ini", "zend_extension", ";zend_extension") self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP 7.0 debug is already disabled")
def updatewpuserpassword(self, ee_domain, ee_site_webroot): ee_wp_user = '' ee_wp_pass = '' EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) # Check if ee_domain is wordpress install try: is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core" " version") except CommandExecutionError as e: raise SiteError("is wordpress site? check command failed ") # Exit if ee_domain is not wordpress install if not is_wp: Log.error(self, "{0} does not seem to be a WordPress site" .format(ee_domain)) try: ee_wp_user = input("Provide WordPress user name [admin]: ") except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "\nCould not update password") if ee_wp_user == "?": Log.info(self, "Fetching WordPress user list") try: EEShellExec.cmd_exec(self, "wp --allow-root user list " "--fields=user_login | grep -v user_login") except CommandExecutionError as e: raise SiteError("fetch wp userlist command failed") if not ee_wp_user: ee_wp_user = '******' try: is_user_exist = EEShellExec.cmd_exec(self, "wp --allow-root user list " "--fields=user_login | grep {0}$ " .format(ee_wp_user)) except CommandExecutionError as e: raise SiteError("if wp user exists check command failed") if is_user_exist: try: ee_wp_pass = getpass.getpass(prompt="Provide password for " "{0} user: "******"{0}".format(e)) raise SiteError("failed to read password input ") try: EEShellExec.cmd_exec(self, "wp --allow-root user update {0}" " --user_pass={1}" .format(ee_wp_user, ee_wp_pass)) except CommandExecutionError as e: raise SiteError("wp user password update command failed") Log.info(self, "Password updated successfully") else: Log.error(self, "Invalid WordPress user {0} for {1}." .format(ee_wp_user, ee_domain))
def site_package_check(self, stype): apt_packages = [] packages = [] stack = EEStackController() stack.app = self.app if stype in ['html', 'proxy', 'php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']: Log.debug(self, "Setting apt_packages variable for Nginx") if not EEAptGet.is_installed(self, 'nginx-custom'): apt_packages = apt_packages + EEVariables.ee_nginx else: # Fix for Nginx white screen death if not EEFileUtils.grep(self, '/etc/nginx/fastcgi_params', 'SCRIPT_FILENAME'): with open('/etc/nginx/fastcgi_params', encoding='utf-8', mode='a') as ee_nginx: ee_nginx.write('fastcgi_param \tSCRIPT_FILENAME ' '\t$request_filename;\n') if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']: Log.debug(self, "Setting apt_packages variable for PHP") if not EEAptGet.is_installed(self, 'php5-fpm'): apt_packages = apt_packages + EEVariables.ee_php if stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: Log.debug(self, "Setting apt_packages variable for MySQL") if not EEShellExec.cmd_exec(self, "mysqladmin ping"): apt_packages = apt_packages + EEVariables.ee_mysql packages = packages + [["https://raw.githubusercontent.com/" "major/MySQLTuner-perl/master/" "mysqltuner.pl", "/usr/bin/mysqltuner", "MySQLTuner"]] if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']: Log.debug(self, "Setting apt_packages variable for Postfix") if not EEAptGet.is_installed(self, 'postfix'): apt_packages = apt_packages + EEVariables.ee_postfix if stype in ['wp', 'wpsubdir', 'wpsubdomain']: Log.debug(self, "Setting packages variable for WP-CLI") if not EEShellExec.cmd_exec(self, "which wp"): packages = packages + [["https://github.com/wp-cli/wp-cli/" "releases/download/v{0}/" "wp-cli-{0}.phar" .format(EEVariables.ee_wp_cli), "/usr/bin/wp", "WP-CLI"]] if self.app.pargs.wpredis: Log.debug(self, "Setting apt_packages variable for redis") if not EEAptGet.is_installed(self, 'redis-server'): apt_packages = apt_packages + EEVariables.ee_redis if os.path.isfile("/etc/nginx/nginx.conf") and (not os.path.isfile("/etc/nginx/common/redis.conf")): data = dict() Log.debug(self, 'Writting the nginx configuration to ' 'file /etc/nginx/common/redis.conf') ee_nginx = open('/etc/nginx/common/redis.conf', encoding='utf-8', mode='w') self.app.render((data), 'redis.mustache', out=ee_nginx) ee_nginx.close() if os.path.isfile("/etc/nginx/nginx.conf") and (not os.path.isfile("/etc/nginx/common/redis-hhvm.conf")): data = dict() Log.debug(self, 'Writting the nginx configuration to ' 'file /etc/nginx/common/redis-hhvm.conf') ee_nginx = open('/etc/nginx/common/redis-hhvm.conf', encoding='utf-8', mode='w') self.app.render((data), 'redis-hhvm.mustache', out=ee_nginx) ee_nginx.close() if os.path.isfile("/etc/nginx/conf.d/upstream.conf"): if not EEFileUtils.grep(self, "/etc/nginx/conf.d/" "upstream.conf", "redis"): with open("/etc/nginx/conf.d/upstream.conf", "a") as redis_file: redis_file.write("upstream redis {\n" " server 127.0.0.1:6379;\n" " keepalive 10;\n}") if os.path.isfile("/etc/nginx/nginx.conf") and (not os.path.isfile("/etc/nginx/conf.d/redis.conf")): with open("/etc/nginx/conf.d/redis.conf", "a") as redis_file: redis_file.write("# Log format Settings\n" "log_format rt_cache_redis '$remote_addr $upstream_response_time $srcache_fetch_status [$time_local] '\n" "'$http_host \"$request\" $status $body_bytes_sent '\n" "'\"$http_referer\" \"$http_user_agent\"';\n") if self.app.pargs.hhvm: if platform.architecture()[0] is '32bit': Log.error(self, "HHVM is not supported by 32bit system") Log.debug(self, "Setting apt_packages variable for HHVM") if not EEAptGet.is_installed(self, 'hhvm'): apt_packages = apt_packages + EEVariables.ee_hhvm if os.path.isdir("/etc/nginx/common") and (not os.path.isfile("/etc/nginx/common/php-hhvm.conf")): data = dict() Log.debug(self, 'Writting the nginx configuration to ' 'file /etc/nginx/common/php-hhvm.conf') ee_nginx = open('/etc/nginx/common/php-hhvm.conf', encoding='utf-8', mode='w') self.app.render((data), 'php-hhvm.mustache', out=ee_nginx) ee_nginx.close() Log.debug(self, 'Writting the nginx configuration to ' 'file /etc/nginx/common/w3tc-hhvm.conf') ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf', encoding='utf-8', mode='w') self.app.render((data), 'w3tc-hhvm.mustache', out=ee_nginx) ee_nginx.close() Log.debug(self, 'Writting the nginx configuration to ' 'file /etc/nginx/common/wpfc-hhvm.conf') ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf', encoding='utf-8', mode='w') self.app.render((data), 'wpfc-hhvm.mustache', out=ee_nginx) ee_nginx.close() Log.debug(self, 'Writting the nginx configuration to ' 'file /etc/nginx/common/wpsc-hhvm.conf') ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf', encoding='utf-8', mode='w') self.app.render((data), 'wpsc-hhvm.mustache', out=ee_nginx) ee_nginx.close() if os.path.isfile("/etc/nginx/conf.d/upstream.conf"): if not EEFileUtils.grep(self, "/etc/nginx/conf.d/upstream.conf", "hhvm"): with open("/etc/nginx/conf.d/upstream.conf", "a") as hhvm_file: hhvm_file.write("upstream hhvm {\nserver 127.0.0.1:8000;\n" "server 127.0.0.1:9000 backup;\n}\n") # Check if Nginx is allready installed and Pagespeed config there or not # If not then copy pagespeed config if self.app.pargs.pagespeed: if (os.path.isfile('/etc/nginx/nginx.conf') and (not os.path.isfile('/etc/nginx/conf.d/pagespeed.conf'))): # Pagespeed configuration data = dict() Log.debug(self, 'Writting the Pagespeed Global ' 'configuration to file /etc/nginx/conf.d/' 'pagespeed.conf') ee_nginx = open('/etc/nginx/conf.d/pagespeed.conf', encoding='utf-8', mode='w') self.app.render((data), 'pagespeed-global.mustache', out=ee_nginx) ee_nginx.close() return(stack.install(apt_packages=apt_packages, packages=packages, disp_msg=False))
def debug_php(self): """Start/Stop PHP debug""" # PHP global debug start if (self.app.pargs.php == 'on' and not self.app.pargs.site_name): if not (EEShellExec.cmd_exec(self, "sed -n \"/upstream php" "{/,/}/p \" /etc/nginx/" "conf.d/upstream.conf " "| grep 9001")): Log.info(self, "Enabling PHP debug") # Check HHVM is installed if not instlled then dont not enable # it in upstream config if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"): hhvmconf=True else: hhvmconf=False data = dict(php="9001", debug="9001", hhvm="9001", hhvmconf=hhvmconf) Log.debug(self, 'Writting the Nginx debug configration to file' ' /etc/nginx/conf.d/upstream.conf ') ee_nginx = open('/etc/nginx/conf.d/upstream.conf', encoding='utf-8', mode='w') self.app.render((data), 'upstream.mustache', out=ee_nginx) ee_nginx.close() # Enable xdebug EEFileUtils.searchreplace(self, "/etc/php5/mods-available/" "xdebug.ini", ";zend_extension", "zend_extension") # Fix slow log is not enabled default in PHP5.6 config = configparser.ConfigParser() config.read('/etc/php5/fpm/pool.d/debug.conf') config['debug']['slowlog'] = '/var/log/php5/slow.log' config['debug']['request_slowlog_timeout'] = '10s' with open('/etc/php5/fpm/pool.d/debug.conf', encoding='utf-8', mode='w') as confifile: Log.debug(self, "Writting debug.conf configuration into " "/etc/php5/fpm/pool.d/debug.conf") config.write(confifile) self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP debug is already enabled") self.msg = self.msg + ['/var/log/php5/slow.log'] # PHP global debug stop elif (self.app.pargs.php == 'off' and not self.app.pargs.site_name): if EEShellExec.cmd_exec(self, " sed -n \"/upstream php {/,/}/p\" " "/etc/nginx/conf.d/upstream.conf " "| grep 9001"): Log.info(self, "Disabling PHP debug") # Check HHVM is installed if not instlled then dont not enable # it in upstream config if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"): hhvmconf=True else: hhvmconf=False data = dict(php="9000", debug="9001", hhvm="8000", hhvmconf=hhvmconf) Log.debug(self, 'Writting the Nginx debug configration to file' ' /etc/nginx/conf.d/upstream.conf ') ee_nginx = open('/etc/nginx/conf.d/upstream.conf', encoding='utf-8', mode='w') self.app.render((data), 'upstream.mustache', out=ee_nginx) ee_nginx.close() # Disable xdebug EEFileUtils.searchreplace(self, "/etc/php5/mods-available/" "xdebug.ini", "zend_extension", ";zend_extension") self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP debug is already disabled")
def default(self): """Default function of log Mail""" self.msg = [] if self.app.pargs.php: self.app.pargs.nginx = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (not self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.fpm = True self.app.pargs.mysql = True self.app.pargs.access = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.wp = True self.app.pargs.access = True self.app.pargs.mysql = True if self.app.pargs.nginx and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*error.log"] if self.app.pargs.access and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*access.log"] if self.app.pargs.fpm: open('/var/log/php5/slow.log', 'a').close() open('/var/log/php5/fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php5/slow.log', '/var/log/php5/fpm.log' ] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if EEVariables.ee_mysql_host is "localhost": if os.path.isfile('/var/log/mysql/mysql-slow.log'): self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] else: Log.info(self, "MySQL slow-log not found, skipped") else: Log.warn( self, "Remote MySQL found, EasyEngine is not able to" "show MySQL log file") if self.app.pargs.site_name: webroot = "{0}{1}".format(EEVariables.ee_webroot, self.app.pargs.site_name) if not os.path.isdir(webroot): Log.error(self, "Site not present, quitting") if self.app.pargs.access: self.msg = self.msg + [ "{0}/{1}/logs/access.log".format(EEVariables.ee_webroot, self.app.pargs.site_name) ] if self.app.pargs.nginx: self.msg = self.msg + [ "{0}/{1}/logs/error.log".format(EEVariables.ee_webroot, self.app.pargs.site_name) ] if self.app.pargs.wp: if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)): if not os.path.isfile( '{0}/logs/debug.log'.format(webroot)): if not os.path.isfile('{0}/htdocs/wp-content/debug.log' .format(webroot)): open("{0}/htdocs/wp-content/debug.log".format( webroot), encoding='utf-8', mode='a').close() EEShellExec.cmd_exec( self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, EEVariables.ee_php_user)) # create symbolic link for debug log EEFileUtils.create_symlink(self, [ "{0}/htdocs/wp-content/" "debug.log".format(webroot), '{0}/logs/debug.log'.format(webroot) ]) self.msg = self.msg + [ "{0}/{1}/logs/debug.log".format( EEVariables.ee_webroot, self.app.pargs.site_name) ] else: Log.info( self, "Site is not WordPress site, skipping " "WordPress logs") mail_list = [] for m_list in self.msg: mail_list = mail_list + glob.glob(m_list) for tomail in self.app.pargs.to: Log.info(self, "Sending mail to {0}".format(tomail[0])) EESendMail("easyengine", tomail[0], "{0} Log Files".format(EEVariables.ee_fqdn), "Hey Hi,\n Please find attached server log files" "\n\n\nYour's faithfully,\nEasyEngine", files=mail_list, port=25, isTls=False)
def setupdomain(self, data): ee_domain_name = data['site_name'] ee_site_webroot = data['webroot'] if 'webroot' in data.keys() else '' # Check if nginx configuration already exists # if os.path.isfile('/etc/nginx/sites-available/{0}' # .format(ee_domain_name)): # raise SiteError("nginx configuration already exists for site") Log.info(self, "Setting up NGINX configuration \t", end='') # write nginx config for file try: ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}' .format(ee_domain_name), encoding='utf-8', mode='w') self.app.render((data), 'virtualconf.mustache', out=ee_site_nginx_conf) ee_site_nginx_conf.close() except IOError as e: Log.debug(self, "{0}".format(e)) raise SiteError("create nginx configuration failed for site") except Exception as e: Log.debug(self, "{0}".format(e)) raise SiteError("create nginx configuration failed for site") finally: # Check nginx -t and return status over it try: Log.debug(self, "Checking generated nginx conf, please wait...") FNULL = open('/dev/null', 'w') ret = subprocess.check_call(["nginx", "-t"], stdout=FNULL, stderr=subprocess.STDOUT) Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") except CalledProcessError as e: Log.debug(self, "{0}".format(str(e))) Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") raise SiteError("created nginx configuration failed for site." " check with `nginx -t`") # create symbolic link for EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available/{0}' .format(ee_domain_name), '/etc/nginx/sites-enabled/{0}' .format(ee_domain_name)]) if 'proxy' in data.keys() and data['proxy']: return # Creating htdocs & logs directory Log.info(self, "Setting up webroot \t\t", end='') try: if not os.path.exists('{0}/htdocs'.format(ee_site_webroot)): os.makedirs('{0}/htdocs'.format(ee_site_webroot)) if not os.path.exists('{0}/logs'.format(ee_site_webroot)): os.makedirs('{0}/logs'.format(ee_site_webroot)) if not os.path.exists('{0}/conf/nginx'.format(ee_site_webroot)): os.makedirs('{0}/conf/nginx'.format(ee_site_webroot)) EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log' .format(ee_domain_name), '{0}/logs/access.log' .format(ee_site_webroot)]) EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.error.log' .format(ee_domain_name), '{0}/logs/error.log' .format(ee_site_webroot)]) except Exception as e: Log.debug(self, "{0}".format(e)) raise SiteError("setup webroot failed for site") finally: # TODO Check if directories are setup if (os.path.exists('{0}/htdocs'.format(ee_site_webroot)) and os.path.exists('{0}/logs'.format(ee_site_webroot))): Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") else: Log.info(self, "[" + Log.ENDC + "Fail" + Log.OKBLUE + "]") raise SiteError("setup webroot failed for site")
def debug_php7(self): """Start/Stop PHP debug""" # PHP global debug start if (self.app.pargs.php7 == 'on' and not self.app.pargs.site_name): if (EEVariables.ee_platform_codename == 'wheezy' or EEVariables.ee_platform_codename == 'precise'): Log.error(self, "PHP 7.2 not supported.") if not (EEShellExec.cmd_exec( self, "sed -n \"/upstream php7" "{/,/}/p \" /etc/nginx/" "conf.d/upstream.conf " "| grep 9170")): Log.info(self, "Enabling PHP 7.2 debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([( 'upstream', 'php7', ), 'server'], '127.0.0.1:9170') if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"): nc.set([( 'upstream', 'hhvm', ), 'server'], '127.0.0.1:9170') nc.savef('/etc/nginx/conf.d/upstream.conf') # Enable xdebug EEFileUtils.searchreplace( self, "/etc/php/7.2/mods-available/" "xdebug.ini", ";zend_extension", "zend_extension") # Fix slow log is not enabled default in PHP5.6 config = configparser.ConfigParser() config.read('/etc/php/7.2/fpm/pool.d/debug.conf') config['debug']['slowlog'] = '/var/log/php/7.2/slow.log' config['debug']['request_slowlog_timeout'] = '10s' with open('/etc/php/7.2/fpm/pool.d/debug.conf', encoding='utf-8', mode='w') as confifile: Log.debug( self, "Writting debug.conf configuration into " "/etc/php/7.2/fpm/pool.d/debug.conf") config.write(confifile) self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP debug is already enabled") self.msg = self.msg + ['/var/log/php/7.2/slow.log'] # PHP global debug stop elif (self.app.pargs.php7 == 'off' and not self.app.pargs.site_name): if EEShellExec.cmd_exec( self, " sed -n \"/upstream php7 {/,/}/p\" " "/etc/nginx/conf.d/upstream.conf " "| grep 9170"): Log.info(self, "Disabling PHP 7.2 debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([( 'upstream', 'php7', ), 'server'], '127.0.0.1:9070') if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"): nc.set([( 'upstream', 'hhvm', ), 'server'], '127.0.0.1:8000') nc.savef('/etc/nginx/conf.d/upstream.conf') # Disable xdebug EEFileUtils.searchreplace( self, "/etc/php/7.2/mods-available/" "xdebug.ini", "zend_extension", ";zend_extension") self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP 7.2 debug is already disabled")
def sitebackup(self, data): ee_site_webroot = data['webroot'] backup_path = ee_site_webroot + '/backup/{0}'.format(EEVariables.ee_date) if not EEFileUtils.isexist(self, backup_path): EEFileUtils.mkdir(self, backup_path) Log.info(self, "Backup location : {0}".format(backup_path)) EEFileUtils.copyfile(self, '/etc/nginx/sites-available/{0}' .format(data['site_name']), backup_path) if data['currsitetype'] in ['html', 'php', 'proxy', 'mysql']: Log.info(self, "Backing up Webroot \t\t", end='') EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path) Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") configfiles = glob.glob(ee_site_webroot + '/*-config.php') # if configfiles and EEFileUtils.isexist(self, configfiles[0]): # ee_db_name = (EEFileUtils.grep(self, configfiles[0], # 'DB_NAME').split(',')[1] # .split(')')[0].strip().replace('\'', '')) if data['ee_db_name']: Log.info(self, 'Backing up database \t\t', end='') try: if not EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql" .format(data['ee_db_name'], backup_path)): Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") raise SiteError("mysqldump failed to backup database") except CommandExecutionError as e: Log.info(self, "[" + Log.ENDC + "Fail" + Log.OKBLUE + "]") raise SiteError("mysqldump failed to backup database") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") # move wp-config.php/ee-config.php to backup if data['currsitetype'] in ['mysql', 'proxy']: EEFileUtils.mvfile(self, configfiles[0], backup_path) else: EEFileUtils.copyfile(self, configfiles[0], backup_path)
def setupwordpress(self, data): ee_domain_name = data['site_name'] ee_site_webroot = data['webroot'] prompt_wpprefix = self.app.config.get('wordpress', 'prefix') ee_wp_user = self.app.config.get('wordpress', 'user') ee_wp_pass = self.app.config.get('wordpress', 'password') ee_wp_email = self.app.config.get('wordpress', 'email') # Random characters ee_random = (''.join(random.sample(string.ascii_uppercase + string.ascii_lowercase + string.digits, 15))) ee_wp_prefix = '' # ee_wp_user = '' # ee_wp_pass = '' if 'wp-user' in data.keys() and data['wp-user']: ee_wp_user = data['wp-user'] if 'wp-email' in data.keys() and data['wp-email']: ee_wp_email = data['wp-email'] if 'wp-pass' in data.keys() and data['wp-pass']: ee_wp_pass = data['wp-pass'] Log.info(self, "Downloading Wordpress \t\t", end='') EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) try: EEShellExec.cmd_exec(self, "wp --allow-root core" " download") except CommandExecutionError as e: Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") raise SiteError(self, "download wordpress core failed") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']): data = setupdatabase(self, data) if prompt_wpprefix == 'True' or prompt_wpprefix == 'true': try: ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ') while not re.match('^[A-Za-z0-9_]*$', ee_wp_prefix): Log.warn(self, "table prefix can only " "contain numbers, letters, and underscores") ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ' ) except EOFError as e: Log.debug(self, "{0}".format(e)) raise SiteError("input table prefix failed") if not ee_wp_prefix: ee_wp_prefix = 'wp_' # Modify wp-config.php & move outside the webroot EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) Log.debug(self, "Setting up wp-config file") if not data['multisite']: Log.debug(self, "Generating wp-config for WordPress Single site") Log.debug(self, "bash -c \"php {0} --allow-root " .format(EEVariables.ee_wpcli_path) + "core config " + "--dbname=\'{0}\' --dbprefix=\'{1}\' --dbuser=\'{2}\' " "--dbhost=\'{3}\' " .format(data['ee_db_name'], ee_wp_prefix, data['ee_db_user'], data['ee_db_host']) + "--dbpass= "******"--extra-php<<PHP \n {1}\nPHP\"" .format(data['ee_db_pass'], "\n\ndefine(\'WP_DEBUG\', false);")) try: EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root" .format(EEVariables.ee_wpcli_path) + " core config " + "--dbname=\'{0}\' --dbprefix=\'{1}\' " "--dbuser=\'{2}\' --dbhost=\'{3}\' " .format(data['ee_db_name'], ee_wp_prefix, data['ee_db_user'], data['ee_db_host'] ) + "--dbpass=\'{0}\' " "--extra-php<<PHP \n {1} {redissalt}\nPHP\"" .format(data['ee_db_pass'], "\n\ndefine(\'WP_DEBUG\', false);", redissalt="\n\ndefine( \'WP_CACHE_KEY_SALT\', \'{0}:\' );" .format(ee_domain_name) if data['wpredis'] else ''), log=False ) except CommandExecutionError as e: raise SiteError("generate wp-config failed for wp single site") else: Log.debug(self, "Generating wp-config for WordPress multisite") Log.debug(self, "bash -c \"php {0} --allow-root " .format(EEVariables.ee_wpcli_path) + "core config " + "--dbname=\'{0}\' --dbprefix=\'{1}\' --dbhost=\'{2}\' " .format(data['ee_db_name'], ee_wp_prefix, data['ee_db_host']) + "--dbuser=\'{0}\' --dbpass= "******"--extra-php<<PHP \n {2} {3} {4}\nPHP\"" .format(data['ee_db_user'], data['ee_db_pass'], "\ndefine(\'WP_ALLOW_MULTISITE\', " "true);", "\ndefine(\'WPMU_ACCEL_REDIRECT\'," " true);", "\n\ndefine(\'WP_DEBUG\', false);")) try: EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root" .format(EEVariables.ee_wpcli_path) + " core config " + "--dbname=\'{0}\' --dbprefix=\'{1}\' " "--dbhost=\'{2}\' " .format(data['ee_db_name'], ee_wp_prefix, data['ee_db_host']) + "--dbuser=\'{0}\' --dbpass=\'{1}\' " "--extra-php<<PHP \n {2} {3} {4} {redissalt}\nPHP\"" .format(data['ee_db_user'], data['ee_db_pass'], "\ndefine(\'WP_ALLOW_MULTISITE\', " "true);", "\ndefine(\'WPMU_ACCEL_REDIRECT\'," " true);", "\n\ndefine(\'WP_DEBUG\', false);", redissalt="\n\ndefine( \'WP_CACHE_KEY_SALT\', \'{0}:\' );" .format(ee_domain_name) if data['wpredis'] else ''), log=False ) except CommandExecutionError as e: raise SiteError("generate wp-config failed for wp multi site") EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php', os.path.abspath(os.path.join(os.getcwd(), os.pardir))) if not ee_wp_user: ee_wp_user = EEVariables.ee_user while not ee_wp_user: Log.warn(self, "Username can have only alphanumeric" "characters, spaces, underscores, hyphens," "periods and the @ symbol.") try: ee_wp_user = input('Enter WordPress username: '******'Enter WordPress email: ') except EOFError as e: Log.debug(self, "{0}".format(e)) raise SiteError("input wordpress username failed") try: while not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", ee_wp_email): Log.info(self, "EMail not Valid in config, " "Please provide valid email id") ee_wp_email = input("Enter your email: ") except EOFError as e: Log.debug(self, "{0}".format(e)) raise SiteError("input WordPress user email failed") Log.debug(self, "Setting up WordPress tables") if not data['multisite']: Log.debug(self, "Creating tables for WordPress Single site") Log.debug(self, "php {0} --allow-root core install " .format(EEVariables.ee_wpcli_path) + "--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' " .format(data['www_domain'], ee_wp_user) + "--admin_password= --admin_email=\'{1}\'" .format(ee_wp_pass, ee_wp_email)) try: EEShellExec.cmd_exec(self, "php {0} --allow-root core " .format(EEVariables.ee_wpcli_path) + "install --url=\'{0}\' --title=\'{0}\' " "--admin_name=\'{1}\' " .format(data['www_domain'], ee_wp_user) + "--admin_password=\'{0}\' " "--admin_email=\'{1}\'" .format(ee_wp_pass, ee_wp_email), log=False) except CommandExceutionError as e: raise SiteError("setup wordpress tables failed for single site") else: Log.debug(self, "Creating tables for WordPress multisite") Log.debug(self, "php {0} --allow-root " .format(EEVariables.ee_wpcli_path) + "core multisite-install " "--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' " .format(data['www_domain'], ee_wp_user) + "--admin_password= --admin_email=\'{1}\' " "{subdomains}" .format(ee_wp_pass, ee_wp_email, subdomains='--subdomains' if not data['wpsubdir'] else '')) try: EEShellExec.cmd_exec(self, "php {0} --allow-root " .format(EEVariables.ee_wpcli_path) + "core multisite-install " "--url=\'{0}\' --title=\'{0}\' " "--admin_name=\'{1}\' " .format(data['www_domain'], ee_wp_user) + "--admin_password=\'{0}\' " "--admin_email=\'{1}\' " "{subdomains}" .format(ee_wp_pass, ee_wp_email, subdomains='--subdomains' if not data['wpsubdir'] else ''), log=False) except CommandExecutionError as e: raise SiteError("setup wordpress tables failed for wp multi site") Log.debug(self, "Updating WordPress permalink") try: EEShellExec.cmd_exec(self, " php {0} --allow-root " .format(EEVariables.ee_wpcli_path) + "rewrite structure " "/%year%/%monthnum%/%day%/%postname%/") except CommandExecutionError as e: raise SiteError("Update wordpress permalinks failed") """Install nginx-helper plugin """ installwp_plugin(self, 'nginx-helper', data) if data['wpfc']: plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_fastcgi","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}' setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data) elif data['wpredis']: plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}' setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data) """Install Wp Super Cache""" if data['wpsc']: installwp_plugin(self, 'wp-super-cache', data) """Install Redis Cache""" if data['wpredis']: installwp_plugin(self, 'redis-cache', data) """Install W3 Total Cache""" if data['w3tc'] or data['wpfc']: installwp_plugin(self, 'w3-total-cache', data) wp_creds = dict(wp_user=ee_wp_user, wp_pass=ee_wp_pass, wp_email=ee_wp_email) return(wp_creds)
def default(self): """Default function of log reset""" self.msg = [] if self.app.pargs.php: self.app.pargs.nginx = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (not self.app.pargs.site_name) and (not self.app.pargs.slow_log_db)): self.app.pargs.nginx = True self.app.pargs.fpm = True self.app.pargs.mysql = True self.app.pargs.access = True self.app.pargs.slow_log_db = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (self.app.pargs.site_name) and (not self.app.pargs.slow - log - db)): self.app.pargs.nginx = True self.app.pargs.wp = True self.app.pargs.access = True self.app.pargs.mysql = True if self.app.pargs.slow_log_db: if os.path.isdir("/var/www/22222/htdocs/db/anemometer"): Log.info(self, "Resetting MySQL slow_query_log database table") EEMysql.execute( self, "TRUNCATE TABLE " "slow_query_log.global_query_review_history") EEMysql.execute( self, "TRUNCATE TABLE " "slow_query_log.global_query_review") if self.app.pargs.nginx and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*error.log"] if self.app.pargs.access and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*access.log"] if self.app.pargs.fpm: open('/var/log/php5/slow.log', 'a').close() open('/var/log/php5/fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php5/slow.log', '/var/log/php5/fpm.log' ] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if EEVariables.ee_mysql_host is "localhost": if os.path.isfile('/var/log/mysql/mysql-slow.log'): self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] else: Log.info(self, "MySQL slow-log not found, skipped") else: Log.warn( self, "Remote MySQL found, EasyEngine is not able to" "show MySQL log file") if self.app.pargs.site_name: webroot = "{0}{1}".format(EEVariables.ee_webroot, self.app.pargs.site_name) if not os.path.isdir(webroot): Log.error(self, "Site not present, quitting") if self.app.pargs.access: self.msg = self.msg + [ "{0}/{1}/logs/access.log".format(EEVariables.ee_webroot, self.app.pargs.site_name) ] if self.app.pargs.nginx: self.msg = self.msg + [ "{0}/{1}/logs/error.log".format(EEVariables.ee_webroot, self.app.pargs.site_name) ] if self.app.pargs.wp: if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)): if not os.path.isfile( '{0}/logs/debug.log'.format(webroot)): if not os.path.isfile('{0}/htdocs/wp-content/debug.log' .format(webroot)): open("{0}/htdocs/wp-content/debug.log".format( webroot), encoding='utf-8', mode='a').close() EEShellExec.cmd_exec( self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, EEVariables.ee_php_user)) # create symbolic link for debug log EEFileUtils.create_symlink(self, [ "{0}/htdocs/wp-content/" "debug.log".format(webroot), '{0}/logs/debug.log'.format(webroot) ]) self.msg = self.msg + [ "{0}/{1}/logs/debug.log".format( EEVariables.ee_webroot, self.app.pargs.site_name) ] else: Log.info( self, "Site is not WordPress site, skipping " "WordPress logs") reset_list = [] for r_list in self.msg: reset_list = reset_list + glob.glob(r_list) # Clearing content of file for r_list in reset_list: Log.info(self, "Resetting file {file}".format(file=r_list)) open(r_list, 'w').close()
def default(self): # All package update if ((not self.app.pargs.php56)): apt_packages = [] packages = [] if ((not self.app.pargs.web) and (not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.mysql) and (not self.app.pargs.postfix) and (not self.app.pargs.hhvm) and (not self.app.pargs.mailscanner) and (not self.app.pargs.all) and (not self.app.pargs.wpcli) and (not self.app.pargs.redis) and (not self.app.pargs.nginxmainline)): self.app.pargs.web = True if self.app.pargs.all: self.app.pargs.web = True self.app.pargs.mail = True if self.app.pargs.web: if EEAptGet.is_installed(self, 'nginx-custom'): self.app.pargs.nginx = True elif EEAptGet.is_installed(self, 'nginx-mainline'): self.app.pargs.nginxmainline = True else: Log.info(self, "Nginx is not already installed") self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.postfix = True self.app.pargs.wpcli = True if self.app.pargs.mail: self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.wpcli = True self.app.pargs.postfix = True if EEAptGet.is_installed(self, 'dovecot-core'): apt_packages = apt_packages + EEVariables.ee_mail self.app.pargs.mailscanner = True else: Log.info(self, "Mail server is not installed") if self.app.pargs.nginx: if EEAptGet.is_installed(self, 'nginx-custom'): apt_packages = apt_packages + EEVariables.ee_nginx else: Log.info(self, "Nginx Stable is not already installed") if self.app.pargs.nginxmainline: if EEAptGet.is_installed(self, 'nginx-mainline'): apt_packages = apt_packages + EEVariables.ee_nginx_dev else: Log.info(self, "Nginx Mainline is not already installed") if self.app.pargs.php: if EEVariables.ee_platform_codename != 'trusty': if EEAptGet.is_installed(self, 'php5-fpm'): apt_packages = apt_packages + EEVariables.ee_php else: Log.info(self, "PHP is not installed") else: if EEAptGet.is_installed(self, 'php5.6-fpm'): apt_packages = apt_packages + EEVariables.ee_php5_6 + EEVariables.ee_php_extra else: Log.info(self, "PHP 5.6 is not installed") if EEAptGet.is_installed(self, 'php7.0-fpm'): apt_packages = apt_packages + EEVariables.ee_php7_0 + EEVariables.ee_php_extra else: Log.info(self, "PHP 7.0 is not installed") if self.app.pargs.hhvm: if EEAptGet.is_installed(self, 'hhvm'): apt_packages = apt_packages + EEVariables.ee_hhvm else: Log.info(self, "HHVM is not installed") if self.app.pargs.mysql: if EEAptGet.is_installed(self, 'mariadb-server'): apt_packages = apt_packages + EEVariables.ee_mysql else: Log.info(self, "MariaDB is not installed") if self.app.pargs.postfix: if EEAptGet.is_installed(self, 'postfix'): apt_packages = apt_packages + EEVariables.ee_postfix else: Log.info(self, "Postfix is not installed") if self.app.pargs.redis: if EEAptGet.is_installed(self, 'redis-server'): apt_packages = apt_packages + EEVariables.ee_redis else: Log.info(self, "Redis is not installed") if self.app.pargs.wpcli: if os.path.isfile('/usr/bin/wp'): packages = packages + [[ "https://github.com/wp-cli/wp-cli/" "releases/download/v{0}/" "wp-cli-{0}.phar" "".format(EEVariables.ee_wp_cli), "/usr/bin/wp", "WP-CLI" ]] else: Log.info(self, "WPCLI is not installed with EasyEngine") if self.app.pargs.mailscanner: if EEAptGet.is_installed(self, 'amavisd-new'): apt_packages = (apt_packages + EEVariables.ee_mailscanner) else: Log.info(self, "MailScanner is not installed") if len(packages) or len(apt_packages): Log.info( self, "During package update process non nginx-cached" " parts of your site may remain down") # Check prompt if (not self.app.pargs.no_prompt): start_upgrade = input("Do you want to continue:[y/N]") if start_upgrade != "Y" and start_upgrade != "y": Log.error(self, "Not starting package update") Log.info(self, "Updating packages, please wait...") if len(apt_packages): # apt-get update EEAptGet.update(self) # Update packages EEAptGet.install(self, apt_packages) # Post Actions after package updates if (set(EEVariables.ee_nginx).issubset(set(apt_packages)) or set(EEVariables.ee_nginx_dev).issubset( set(apt_packages))): EEService.restart_service(self, 'nginx') if EEVariables.ee_platform_codename != 'trusty': if set(EEVariables.ee_php).issubset(set(apt_packages)): EEService.restart_service(self, 'php5-fpm') else: if set(EEVariables.ee_php5_6).issubset( set(apt_packages)): EEService.restart_service(self, 'php5.6-fpm') if set(EEVariables.ee_php7_0).issubset( set(apt_packages)): EEService.restart_service(self, 'php7.0-fpm') if set(EEVariables.ee_hhvm).issubset(set(apt_packages)): EEService.restart_service(self, 'hhvm') if set(EEVariables.ee_postfix).issubset(set(apt_packages)): EEService.restart_service(self, 'postfix') if set(EEVariables.ee_mysql).issubset(set(apt_packages)): EEService.restart_service(self, 'mysql') if set(EEVariables.ee_mail).issubset(set(apt_packages)): EEService.restart_service(self, 'dovecot') if set(EEVariables.ee_redis).issubset(set(apt_packages)): EEService.restart_service(self, 'redis-server') if len(packages): if self.app.pargs.wpcli: EEFileUtils.remove(self, ['/usr/bin/wp']) Log.debug(self, "Downloading following: {0}".format(packages)) EEDownload.download(self, packages) if self.app.pargs.wpcli: EEFileUtils.chmod(self, "/usr/bin/wp", 0o775) Log.info(self, "Successfully updated packages") # PHP 5.6 to 5.6 elif (self.app.pargs.php56): self.upgrade_php56() else: self.app.args.print_help()
def default(self): """Default function of log show""" self.msg = [] if self.app.pargs.php: self.app.pargs.nginx = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (not self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.fpm = True self.app.pargs.mysql = True self.app.pargs.access = True if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.access) and (not self.app.pargs.wp) and (self.app.pargs.site_name)): self.app.pargs.nginx = True self.app.pargs.wp = True self.app.pargs.access = True self.app.pargs.mysql = True if self.app.pargs.nginx and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*error.log"] if self.app.pargs.access and (not self.app.pargs.site_name): self.msg = self.msg + ["/var/log/nginx/*access.log"] if self.app.pargs.fpm: open('/var/log/php5/slow.log', 'a').close() open('/var/log/php5/fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php5/slow.log', '/var/log/php5/fpm.log' ] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if EEVariables.ee_mysql_host is "localhost": if os.path.isfile('/var/log/mysql/mysql-slow.log'): self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] else: Log.info(self, "MySQL slow-log not found, skipped") else: Log.warn( self, "Remote MySQL found, EasyEngine is not able to" "show MySQL log file") if self.app.pargs.site_name: webroot = "{0}{1}".format(EEVariables.ee_webroot, self.app.pargs.site_name) if not os.path.isdir(webroot): Log.error(self, "Site not present, quitting") if self.app.pargs.access: self.msg = self.msg + [ "{0}/{1}/logs/access.log".format(EEVariables.ee_webroot, self.app.pargs.site_name) ] if self.app.pargs.nginx: self.msg = self.msg + [ "{0}/{1}/logs/error.log".format(EEVariables.ee_webroot, self.app.pargs.site_name) ] if self.app.pargs.wp: if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)): if not os.path.isfile( '{0}/logs/debug.log'.format(webroot)): if not os.path.isfile('{0}/htdocs/wp-content/debug.log' .format(webroot)): open("{0}/htdocs/wp-content/debug.log".format( webroot), encoding='utf-8', mode='a').close() EEShellExec.cmd_exec( self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, EEVariables.ee_php_user)) # create symbolic link for debug log EEFileUtils.create_symlink(self, [ "{0}/htdocs/wp-content/" "debug.log".format(webroot), '{0}/logs/debug.log'.format(webroot) ]) self.msg = self.msg + [ "{0}/{1}/logs/debug.log".format( EEVariables.ee_webroot, self.app.pargs.site_name) ] else: Log.info( self, "Site is not WordPress site, skipping " "WordPress logs") watch_list = [] for w_list in self.msg: watch_list = watch_list + glob.glob(w_list) logwatch(self, watch_list)