def edit(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)) if os.path.isfile('/etc/nginx/sites-available/{0}' .format(ee_domain)): try: EEShellExec.invoke_editor(self, '/etc/nginx/sites-available/' '{0}'.format(ee_domain)) except CommandExecutionError as e: Log.error(self, "Failed invoke editor") if (EEGit.checkfilestatus(self, "/etc/nginx", '/etc/nginx/sites-available/{0}'.format(ee_domain))): EEGit.add(self, ["/etc/nginx"], msg="Edit website: {0}" .format(ee_domain)) # Reload NGINX EEService.reload_service(self, 'nginx') else: Log.error(self, "nginx configuration file does not exists" .format(ee_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 restart(self): """Restart services""" services = [] if self.app.pargs.nginx: Log.debug(self, "nginx service restart") services = services + ['nginx'] if self.app.pargs.php: Log.debug(self, "php5-fpm service restart") services = services + ['php5-fpm'] if self.app.pargs.mysql: if EEVariables.ee_mysql_host is "localhost": Log.debug(self, "mysql service restart") services = services + ['mysql'] else: Log.warn(self, "Remote MySQL found, " "unable to restart MySQL service") if self.app.pargs.postfix: Log.debug(self, "postfix service restart") services = services + ['postfix'] if self.app.pargs.memcache: Log.debug(self, "memcached service restart") services = services + ['memcached'] if self.app.pargs.dovecot: Log.debug(self, "dovecot service restart") services = services + ['dovecot'] if not services and EEVariables.ee_mysql_host is "localhost": services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] Log.debug(self, "nginx,php5-fpm,mysql,postfix services restart") elif not services: services = services + ['nginx', 'php5-fpm', 'postfix'] Log.debug(self, "nginx,php5-fpm,postfix services restart") for service in services: EEService.restart_service(self, service)
def secure_port(self): """This function Secures port""" if self.app.pargs.user_input: while not self.app.pargs.user_input.isdigit(): Log.info(self, "Please Enter valid port number ") self.app.pargs.user_input = input("EasyEngine " "admin port [22222]:") if not self.app.pargs.user_input: port = input("EasyEngine admin port [22222]:") if port == "": self.app.pargs.user_input = 22222 while not port.isdigit() and port != "": Log.info(self, "Please Enter valid port number :") port = input("EasyEngine admin port [22222]:") self.app.pargs.user_input = port if EEVariables.ee_platform_distro == 'Ubuntu': EEShellExec.cmd_exec( self, "sed -i \"s/listen.*/listen " "{port} default_server ssl spdy;/\" " "/etc/nginx/sites-available/22222".format( port=self.app.pargs.user_input)) if EEVariables.ee_platform_distro == 'debian': EEShellExec.cmd_exec( self, "sed -i \"s/listen.*/listen " "{port} default_server ssl;/\" " "/etc/nginx/sites-available/22222".format( port=self.app.pargs.user_input)) EEGit.add(self, ["/etc/nginx"], msg="Adding changed secure port into Git") EEService.reload_service(self, 'nginx') Log.info( self, "Successfully port changed {port}".format( port=self.app.pargs.user_input))
def signal_handler(self, signal, frame): """Handle Ctrl+c hevent for -i option of debug""" self.start = False if self.app.pargs.nginx: self.debug_nginx() if self.app.pargs.php: self.debug_php() if self.app.pargs.fpm: self.debug_fpm() if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if EEVariables.ee_mysql_host is "localhost": self.debug_mysql() else: Log.warn(self, "Remote MySQL found, EasyEngine will not " "enable remote debug") if self.app.pargs.wp: self.debug_wp() if self.app.pargs.rewrite: self.debug_rewrite() # Reload Nginx if self.trigger_nginx: EEService.reload_service(self, 'nginx') # Reload PHP if self.trigger_php: EEService.reload_service(self, 'php5-fpm') self.app.close(0)
def secure_port(self): """This function Secures port""" if self.app.pargs.user_input: while not self.app.pargs.user_input.isdigit(): Log.info(self, "Please Enter valid port number ") self.app.pargs.user_input = input("EasyEngine " "admin port [22222]:") if not self.app.pargs.user_input: port = input("EasyEngine admin port [22222]:") if port == "": self.app.pargs.user_input = 22222 while not port.isdigit() and port != "": Log.info(self, "Please Enter valid port number :") port = input("EasyEngine admin port [22222]:") self.app.pargs.user_input = port if EEVariables.ee_platform_distro == 'Ubuntu': EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen " "{port} default_server ssl spdy;/\" " "/etc/nginx/sites-available/22222" .format(port=self.app.pargs.user_input)) if EEVariables.ee_platform_distro == 'debian': EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen " "{port} default_server ssl;/\" " "/etc/nginx/sites-available/22222" .format(port=self.app.pargs.user_input)) EEGit.add(self, ["/etc/nginx"], msg="Adding changed secure port into Git") EEService.reload_service(self, 'nginx') Log.info(self, "Successfully port changed {port}" .format(port=self.app.pargs.user_input))
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 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 clean_memcache(self): """This function Clears memcache """ try: if(EEAptGet.is_installed(self, "memcached")): EEService.restart_service(self, "memcached") Log.info(self, "Cleaning MemCache") else: Log.info(self, "Memcache not installed") except Exception as e: Log.debug(self, "{0}".format(e)) Log.error(self, "Unable to restart Memcached", False)
def secure_port(self): """This function Secures port""" if self.app.pargs.user_input: while not self.app.pargs.user_input.isdigit(): Log.info(self, "Please Enter valid port number ") self.app.pargs.user_input = input("EasyEngine " "admin port [22222]:") if not self.app.pargs.user_input: port = input("EasyEngine admin port [22222]:") if port == "": self.app.pargs.user_input = 22222 while not port.isdigit() and port != "": Log.info(self, "Please Enter valid port number :") port = input("EasyEngine admin port [22222]:") self.app.pargs.user_input = port if EEVariables.ee_platform_distro == 'ubuntu': EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen " "{port} default_server ssl {http2};/\" " "/etc/nginx/sites-available/22222" .format(port=self.app.pargs.user_input,http2=("http2" if EEAptGet.is_installed(self,'nginx-mainline') else "spdy"))) if EEVariables.ee_platform_distro == 'debian': EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen " "{port} default_server ssl {http2};/\" " "/etc/nginx/sites-available/22222" .format(port=self.app.pargs.user_input,http2=("http2" if EEAptGet.is_installed(self,'nginx-mainline') else "spdy"))) EEGit.add(self, ["/etc/nginx"], msg="Adding changed secure port into Git") if not EEService.reload_service(self, 'nginx'): Log.error(self, "service nginx reload failed. " "check issues with `nginx -t` command") Log.info(self, "Successfully port changed {port}" .format(port=self.app.pargs.user_input))
def status(self): """Status of services""" services = [] if self.app.pargs.nginx: Log.debug(self, "nginx service status") services = services + ['nginx'] if self.app.pargs.php: Log.debug(self, "php5-fpm service status") services = services + ['php5-fpm'] if self.app.pargs.mysql: if EEVariables.ee_mysql_host is "localhost": Log.debug(self, "mysql service status") services = services + ['mysql'] else: Log.warn(self, "Remote MySQL found, " "unable to get MySQL service status") if self.app.pargs.postfix: services = services + ['postfix'] Log.debug(self, "postfix service status") if self.app.pargs.memcache: Log.debug(self, "memcached service status") services = services + ['memcached'] if self.app.pargs.dovecot: Log.debug(self, "dovecot service status") services = services + ['dovecot'] if not services and EEVariables.ee_mysql_host is "localhost": services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] Log.debug(self, "nginx,php5-fpm,mysql,postfix services status") elif not services: services = services + ['nginx', 'php5-fpm', 'postfix'] Log.debug(self, "nginx,php5-fpm,postfix services status") for service in services: if EEService.get_service_status(self, service): Log.info(self, "{0:10}: {1}".format(service, "Running"))
def signal_handler(self, signal, frame): """Handle Ctrl+c hevent for -i option of debug""" self.start = False if self.app.pargs.nginx: self.app.pargs.nginx = 'off' self.debug_nginx() if self.app.pargs.php: self.app.pargs.php = 'off' self.debug_php() if self.app.pargs.php7: self.app.pargs.php7 = 'off' self.debug_php7() if self.app.pargs.fpm: self.app.pargs.fpm = 'off' self.debug_fpm() if self.app.pargs.fpm7: self.app.pargs.fpm7 = 'off' self.debug_fpm7() if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if EEVariables.ee_mysql_host is "localhost": self.app.pargs.mysql = 'off' self.debug_mysql() else: Log.warn(self, "Remote MySQL found, EasyEngine will not " "enable remote debug") if self.app.pargs.wp: self.app.pargs.wp = 'off' self.debug_wp() if self.app.pargs.rewrite: self.app.pargs.rewrite = 'off' self.debug_rewrite() # Reload Nginx if self.trigger_nginx: EEService.reload_service(self, 'nginx') # Reload PHP if self.trigger_php: if EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial': if EEAptGet.is_installed(self,'php5.6-fpm'): EEService.reload_service(self, 'php5.6-fpm') if EEAptGet.is_installed(self,'php7.0-fpm'): EEService.reload_service(self, 'php7.0-fpm') else: EEService.reload_service(self, 'php5-fpm') self.app.close(0)
def default(self): hhvm = None pagespeed = None data = dict() try: stype, cache = detSitePar(vars(self.app.pargs)) except RuntimeError as e: Log.debug(self, str(e)) Log.error(self, "Please provide valid options combination for" " site update") 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 input site name, 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) ee_site_webroot = EEVariables.ee_webroot + ee_domain check_site = getSiteInfo(self, ee_domain) if check_site is None: Log.error(self, " Site {0} does not exist.".format(ee_domain)) else: oldsitetype = check_site.site_type oldcachetype = check_site.cache_type old_hhvm = check_site.is_hhvm old_pagespeed = check_site.is_pagespeed if (self.app.pargs.password and not (self.app.pargs.html or self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or self.app.pargs.wpsc or self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)): try: updatewpuserpassword(self, ee_domain, ee_site_webroot) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Password Unchanged.") self.app.close(0) if ((stype == 'php' and oldsitetype != 'html') or (stype == 'mysql' and oldsitetype not in ['html', 'php']) or (stype == 'wp' and oldsitetype not in ['html', 'php', 'mysql', 'wp']) or (stype == 'wpsubdir' and oldsitetype in ['wpsubdomain']) or (stype == 'wpsubdomain' and oldsitetype in ['wpsubdir']) or (stype == oldsitetype and cache == oldcachetype)): Log.error(self, "can not update {0} {1} to {2} {3}". format(oldsitetype, oldcachetype, stype, cache)) if stype == 'php': data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=True, wp=False, w3tc=False, wpfc=False, wpsc=False, multisite=False, wpsubdir=False, webroot=ee_site_webroot, currsitetype=oldsitetype, currcachetype=oldcachetype) elif stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=True, wp=False, w3tc=False, wpfc=False, wpsc=False, multisite=False, wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) if stype in ['wp', 'wpsubdir', 'wpsubdomain']: data['wp'] = True data['basic'] = False data[cache] = True if stype in ['wpsubdir', 'wpsubdomain']: data['multisite'] = True if stype == 'wpsubdir': data['wpsubdir'] = True if self.app.pargs.pagespeed or self.app.pargs.hhvm: if not data: data = dict(site_name=ee_domain, www_domain=ee_www_domain, currsitetype=oldsitetype, currcachetype=oldcachetype, webroot=ee_site_webroot) stype = oldsitetype cache = oldcachetype if oldsitetype == 'html': data['static'] = True data['wp'] = False data['multisite'] = False data['wpsubdir'] = False elif oldsitetype == 'php' or oldsitetype == 'mysql': data['static'] = False data['wp'] = False data['multisite'] = False data['wpsubdir'] = False elif oldsitetype == 'wp': data['static'] = False data['wp'] = True data['multisite'] = False data['wpsubdir'] = False elif oldsitetype == 'wpsubdir': data['static'] = False data['wp'] = True data['multisite'] = True data['wpsubdir'] = True elif oldsitetype == 'wpsubdomain': data['static'] = False data['wp'] = True data['multisite'] = True data['wpsubdir'] = False if oldcachetype == 'basic': data['basic'] = True data['w3tc'] = False data['wpfc'] = False data['wpsc'] = False elif oldcachetype == 'w3tc': data['basic'] = False data['w3tc'] = True data['wpfc'] = False data['wpsc'] = False elif oldcachetype == 'wpfc': data['basic'] = False data['w3tc'] = False data['wpfc'] = True data['wpsc'] = False elif oldcachetype == 'wpsc': data['basic'] = False data['w3tc'] = False data['wpfc'] = False data['wpsc'] = True if self.app.pargs.hhvm != 'off': data['hhvm'] = True hhvm = True elif self.app.pargs.hhvm == 'off': data['hhvm'] = False hhvm = False if self.app.pargs.pagespeed != 'off': data['pagespeed'] = True pagespeed = True elif self.app.pargs.pagespeed == 'off': data['pagespeed'] = False pagespeed = False if self.app.pargs.pagespeed: if pagespeed is old_pagespeed: if pagespeed is False: Log.info(self, "Pagespeed is allready disabled for given " "site") elif pagespeed is True: Log.info(self, "Pagespeed is allready enabled for given " "site") if self.app.pargs.hhvm: if hhvm is old_hhvm: if hhvm is False: Log.info(self, "HHVM is allready disabled for given " "site") elif hhvm is True: Log.info(self, "HHVM is allready enabled for given " "site") if self.app.pargs.pagespeed and self.app.pargs.hhvm: if ((hhvm is old_hhvm) and (pagespeed is old_pagespeed) and (stype == oldsitetype and cache == oldcachetype)): self.app.close(0) if data and (not self.app.pargs.hhvm): if old_hhvm is True: data['hhvm'] = True hhvm = True else: data['hhvm'] = False hhvm = False if data and (not self.app.pargs.pagespeed): if old_pagespeed is True: data['pagespeed'] = True pagespeed = True else: data['pagespeed'] = False pagespeed = False if not data: Log.error(self, " Cannot update {0}, Invalid Options" .format(ee_domain)) ee_auth = site_package_check(self, stype) data['ee_db_name'] = check_site.db_name data['ee_db_user'] = check_site.db_user data['ee_db_pass'] = check_site.db_password data['ee_db_host'] = check_site.db_host try: sitebackup(self, data) except Exception as e: Log.debug(self, str(e)) Log.error(self, "Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") # setup NGINX configuration, and webroot try: setupdomain(self, data) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Update site failed. Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") # Update pagespeed config if self.app.pargs.pagespeed: operateOnPagespeed(self, data) if stype == oldsitetype and cache == oldcachetype: # Service Nginx Reload EEService.reload_service(self, 'nginx') updateSiteInfo(self, ee_domain, stype=stype, cache=cache, hhvm=hhvm, pagespeed=pagespeed) Log.info(self, "Successfully updated site" " http://{0}".format(ee_domain)) self.app.close(0) if 'ee_db_name' in data.keys() and not data['wp']: try: data = setupdatabase(self, data) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Update site failed. Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") try: eedbconfig = open("{0}/ee-config.php".format(ee_site_webroot), encoding='utf-8', mode='w') eedbconfig.write("<?php \ndefine('DB_NAME', '{0}');" "\ndefine('DB_USER', '{1}'); " "\ndefine('DB_PASSWORD', '{2}');" "\ndefine('DB_HOST', '{3}');\n?>" .format(data['ee_db_name'], data['ee_db_user'], data['ee_db_pass'], data['ee_db_host'])) eedbconfig.close() except IOError as e: Log.debug(self, str(e)) Log.debug(self, "creating ee-config.php failed.") Log.error(self, "Update site failed. Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") # if oldsitetype == 'mysql': # # config_file = (ee_site_webroot + '/backup/{0}/ee-config.php' # # .format(EEVariables.ee_date)) # # data['ee_db_name'] = (EEFileUtils.grep(self, config_file, # # 'DB_NAME') # # .split(',')[1] # # .split(')')[0].strip()) # # data['ee_db_user'] = (EEFileUtils.grep(self, config_file, # # 'DB_USER') # # .split(',')[1] # # .split(')')[0].strip()) # # data['ee_db_pass'] = (EEFileUtils.grep(self, config_file, # # 'DB_PASSWORD') # # .split(',')[1] # # .split(')')[0].strip()) # # data['ee_db_host'] = (EEFileUtils.grep(self, config_file, # # 'DB_HOST') # # .split(',')[1] # # .split(')')[0].strip()) # Setup WordPress if old sites are html/php/mysql sites if data['wp'] and oldsitetype in ['html', 'php', 'mysql']: try: ee_wp_creds = setupwordpress(self, data) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Update site failed. Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") # Uninstall unnecessary plugins if oldsitetype in ['wp', 'wpsubdir', 'wpsubdomain']: # Setup WordPress Network if update option is multisite # and oldsite is WordPress single site if data['multisite'] and oldsitetype == 'wp': try: setupwordpressnetwork(self, data) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Update site failed. Check logs for reason" " `tail /var/log/ee/ee.log` & Try Again!!!") if (oldcachetype == 'w3tc' or oldcachetype == 'wpfc' and not (data['w3tc'] or data['wpfc'])): try: uninstallwp_plugin(self, 'w3-total-cache', data) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Update site failed. Check logs for reason" " `tail /var/log/ee/ee.log` & Try Again!!!") if oldcachetype == 'wpsc' and not data['wpsc']: try: uninstallwp_plugin(self, 'wp-super-cache', data) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Update site failed. Check logs for reason" " `tail /var/log/ee/ee.log` & Try Again!!!") if (oldcachetype != 'w3tc' or oldcachetype != 'wpfc') and (data['w3tc'] or data['wpfc']): try: installwp_plugin(self, 'w3-total-cache', data) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Update site failed. Check logs for reason" " `tail /var/log/ee/ee.log` & Try Again!!!") if oldcachetype != 'wpsc' and data['wpsc']: try: installwp_plugin(self, 'wp-super-cache', data) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Update site failed. Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") # Service Nginx Reload EEService.reload_service(self, 'nginx') EEGit.add(self, ["/etc/nginx"], msg="{0} updated with {1} {2}" .format(ee_www_domain, stype, cache)) # Setup Permissions for webroot try: setwebrootpermissions(self, data['webroot']) except SiteError as e: Log.debug(self, str(e)) Log.error(self, "Update site failed. Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") if ee_auth and len(ee_auth): for msg in ee_auth: Log.info(self, Log.ENDC + msg) display_cache_settings(self, data) if data['wp'] and oldsitetype in ['html', 'php', 'mysql']: Log.info(self, "\n\n" + Log.ENDC + "WordPress admin user :"******" {0}".format(ee_wp_creds['wp_user'])) Log.info(self, Log.ENDC + "WordPress admin password : {0}" .format(ee_wp_creds['wp_pass']) + "\n\n") if oldsitetype in ['html', 'php'] and stype != 'php': updateSiteInfo(self, ee_domain, stype=stype, cache=cache, db_name=data['ee_db_name'], db_user=data['ee_db_user'], db_password=data['ee_db_pass'], db_host=data['ee_db_host'], hhvm=hhvm, pagespeed=pagespeed) else: updateSiteInfo(self, ee_domain, stype=stype, cache=cache, hhvm=hhvm, pagespeed=pagespeed) Log.info(self, "Successfully updated site" " http://{0}".format(ee_domain))
def status(self): """Status of services""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php7 or self.app.pargs.mysql or self.app.pargs.postfix or self.app.pargs.hhvm or self.app.pargs.memcache or self.app.pargs.dovecot or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.postfix = True self.app.pargs.hhvm = True if self.app.pargs.nginx: if EEAptGet.is_installed(self, 'nginx-custom') or EEAptGet.is_installed( self, 'nginx-mainline'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if EEVariables.ee_platform_codename != 'trusty': if EEAptGet.is_installed(self, 'php5-fpm'): services = services + ['php5-fpm'] else: Log.info(self, "PHP5-FPM is not installed") else: if EEAptGet.is_installed(self, 'php5.6-fpm'): services = services + ['php5.6-fpm'] else: Log.info(self, "PHP5.6-FPM is not installed") if EEAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") if self.app.pargs.php7: if EEVariables.ee_platform_codename == 'trusty': if EEAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") else: Log.info(self, "Your platform does not support PHP 7") if self.app.pargs.mysql: if ((EEVariables.ee_mysql_host is "localhost") or (EEVariables.ee_mysql_host is "127.0.0.1")): if (EEAptGet.is_installed(self, 'mysql-server') or EEAptGet.is_installed(self, 'percona-server-server-5.6') or EEAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn( self, "Remote MySQL found, " "Unable to check MySQL service status") if self.app.pargs.postfix: if EEAptGet.is_installed(self, 'postfix'): services = services + ['postfix'] else: Log.info(self, "Postfix is not installed") if self.app.pargs.hhvm: if EEAptGet.is_installed(self, 'hhvm'): services = services + ['hhvm'] else: Log.info(self, "HHVM is not installed") if self.app.pargs.memcache: if EEAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcache is not installed") if self.app.pargs.dovecot: if EEAptGet.is_installed(self, 'dovecot-core'): services = services + ['dovecot'] else: Log.info(self, "Mail server is not installed") if self.app.pargs.redis: if EEAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") for service in services: if EEService.get_service_status(self, service): Log.info(self, "{0:10}: {1}".format(service, "Running"))
def default(self): """Default function of debug""" # self.start = True self.interactive = False self.msg = [] self.trigger_nginx = False self.trigger_php = False if ((not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and (not self.app.pargs.all) and (not self.app.pargs.site_name)): if self.app.pargs.stop or self.app.pargs.start: print("--start/stop option is deprecated since ee3.0.5") self.app.args.print_help() else: self.app.args.print_help() if self.app.pargs.all == 'on': if self.app.pargs.site_name: self.app.pargs.wp = 'on' self.app.pargs.nginx = 'on' self.app.pargs.php = 'on' self.app.pargs.fpm = 'on' self.app.pargs.mysql = 'on' self.app.pargs.rewrite = 'on' if self.app.pargs.all == 'off': if self.app.pargs.site_name: self.app.pargs.wp = 'off' self.app.pargs.nginx = 'off' self.app.pargs.php = 'off' self.app.pargs.fpm = 'off' self.app.pargs.mysql = 'off' self.app.pargs.rewrite = 'off' if ((not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and self.app.pargs.site_name): self.app.args.print_help() # self.app.pargs.nginx = 'on' # self.app.pargs.wp = 'on' # self.app.pargs.rewrite = 'on' if self.app.pargs.nginx: self.debug_nginx() if self.app.pargs.php: self.debug_php() if self.app.pargs.fpm: self.debug_fpm() if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if EEVariables.ee_mysql_host is "localhost": self.debug_mysql() else: Log.warn(self, "Remote MySQL found, EasyEngine will not " "enable remote debug") if self.app.pargs.wp: self.debug_wp() if self.app.pargs.rewrite: self.debug_rewrite() if self.app.pargs.interactive: self.interactive = True # Reload Nginx if self.trigger_nginx: EEService.reload_service(self, 'nginx') # Reload PHP if self.trigger_php: EEService.restart_service(self, 'php5-fpm') if len(self.msg) > 0: if not self.app.pargs.interactive: disp_msg = ' '.join(self.msg) Log.info(self, "Use following command to check debug logs:\n" + Log.ENDC + "tail -f {0}".format(disp_msg)) else: signal.signal(signal.SIGINT, self.signal_handler) watch_list = [] for w_list in self.msg: watch_list = watch_list + glob.glob(w_list) logwatch(self, watch_list)
def reload(self): """Reload service""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php7 or self.app.pargs.mysql or self.app.pargs.postfix or self.app.pargs.hhvm or self.app.pargs.memcache or self.app.pargs.dovecot or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.postfix = True if self.app.pargs.nginx: if EEAptGet.is_installed(self, 'nginx-custom') or EEAptGet.is_installed(self,'nginx-mainline'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if EEVariables.ee_platform_codename != 'trusty': if EEAptGet.is_installed(self, 'php5-fpm'): services = services + ['php5-fpm'] else: Log.info(self, "PHP5-FPM is not installed") else: if EEAptGet.is_installed(self, 'php5.6-fpm'): services = services + ['php5.6-fpm'] else: Log.info(self, "PHP5.6-FPM is not installed") if EEAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") if self.app.pargs.php7: if EEVariables.ee_platform_codename == 'trusty': if EEAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") else: Log.info(self, "Your platform does not support PHP 7") if self.app.pargs.mysql: if ((EEVariables.ee_mysql_host is "localhost") or (EEVariables.ee_mysql_host is "127.0.0.1")): if (EEAptGet.is_installed(self, 'mysql-server') or EEAptGet.is_installed(self, 'percona-server-server-5.6') or EEAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn(self, "Remote MySQL found, " "Unable to check MySQL service status") if self.app.pargs.postfix: if EEAptGet.is_installed(self, 'postfix'): services = services + ['postfix'] else: Log.info(self, "Postfix is not installed") if self.app.pargs.hhvm: Log.info(self, "HHVM does not support to reload") if self.app.pargs.memcache: if EEAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcache is not installed") if self.app.pargs.dovecot: if EEAptGet.is_installed(self, 'dovecot-core'): services = services + ['dovecot'] else: Log.info(self, "Mail server is not installed") if self.app.pargs.redis: if EEAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") for service in services: Log.debug(self, "Reloading service: {0}".format(service)) EEService.reload_service(self, service)
def default(self): # All package update if ((not self.app.pargs.php56)): 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") 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)): 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: self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.postfix = True self.app.pargs.hhvm = True if self.app.pargs.mail: self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = 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 is not already installed") if self.app.pargs.php: if EEAptGet.is_installed(self, 'php5-fpm'): apt_packages = apt_packages + EEVariables.ee_php else: Log.info(self, "PHP 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.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(apt_packages): # apt-get update EEAptGet.update(self) # Update packages Log.info(self, "Updating packages, please wait...") EEAptGet.install(self, apt_packages) Log.info(self, "Successfully updated packages") # Post Actions after package updates if set(EEVariables.ee_nginx).issubset(set(apt_packages)): EEService.restart_service(self, 'nginx') if set(EEVariables.ee_php).issubset(set(apt_packages)): EEService.restart_service(self, 'php5-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, 'hhvm') if set(EEVariables.ee_mail).issubset(set(apt_packages)): EEService.restart_service(self, 'dovecot') # PHP 5.6 to 5.6 elif (self.app.pargs.php56): self.upgrade_php56() else: self.app.args.print_help()
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_distro == 'debian' or EEVariables.ee_platform_codename == 'precise'): 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))): EEService.restart_service(self, 'nginx') if (EEVariables.ee_platform_distro == 'debian' or EEVariables.ee_platform_codename == 'precise'): 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 status(self): """Status of services""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php7 or self.app.pargs.mysql or self.app.pargs.postfix or self.app.pargs.hhvm or self.app.pargs.memcache or self.app.pargs.dovecot or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.postfix = True self.app.pargs.hhvm = True if self.app.pargs.nginx: if EEAptGet.is_installed(self, 'nginx-custom') or EEAptGet.is_installed(self,'nginx-mainline'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if (EEVariables.ee_platform_distro == 'debian' or EEVariables.ee_platform_codename == 'precise'): if EEAptGet.is_installed(self, 'php5-fpm'): services = services + ['php5-fpm'] else: Log.info(self, "PHP5-FPM is not installed") else: if EEAptGet.is_installed(self, 'php5.6-fpm'): services = services + ['php5.6-fpm'] else: Log.info(self, "PHP5.6-FPM is not installed") if EEAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") if self.app.pargs.php7: if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial'): if EEAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") else: Log.info(self, "Your platform does not support PHP 7") if self.app.pargs.mysql: if ((EEVariables.ee_mysql_host is "localhost") or (EEVariables.ee_mysql_host is "127.0.0.1")): if (EEAptGet.is_installed(self, 'mysql-server') or EEAptGet.is_installed(self, 'percona-server-server-5.6') or EEAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn(self, "Remote MySQL found, " "Unable to check MySQL service status") if self.app.pargs.postfix: if EEAptGet.is_installed(self, 'postfix'): services = services + ['postfix'] else: Log.info(self, "Postfix is not installed") if self.app.pargs.hhvm: if EEAptGet.is_installed(self, 'hhvm'): services = services + ['hhvm'] else: Log.info(self, "HHVM is not installed") if self.app.pargs.memcache: if EEAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcache is not installed") if self.app.pargs.dovecot: if EEAptGet.is_installed(self, 'dovecot-core'): services = services + ['dovecot'] else: Log.info(self, "Mail server is not installed") if self.app.pargs.redis: if EEAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") for service in services: if EEService.get_service_status(self, service): Log.info(self, "{0:10}: {1}".format(service, "Running"))
def reload(self): """Reload service""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php7 or self.app.pargs.mysql or self.app.pargs.postfix or self.app.pargs.hhvm or self.app.pargs.memcache or self.app.pargs.dovecot or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.postfix = True if self.app.pargs.nginx: if EEAptGet.is_installed(self, 'nginx-custom') or EEAptGet.is_installed( self, 'nginx-mainline'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if (EEVariables.ee_platform_distro == 'debian' or EEVariables.ee_platform_codename == 'precise'): if EEAptGet.is_installed(self, 'php5-fpm'): services = services + ['php5-fpm'] else: Log.info(self, "PHP5-FPM is not installed") else: if EEAptGet.is_installed(self, 'php5.6-fpm'): services = services + ['php5.6-fpm'] else: Log.info(self, "PHP5.6-FPM is not installed") if EEAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") if self.app.pargs.php7: if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial' or EEVariables.ee_platform_codename == 'bionic'): if EEAptGet.is_installed(self, 'php7.0-fpm'): services = services + ['php7.0-fpm'] else: Log.info(self, "PHP7.0-FPM is not installed") else: Log.info(self, "Your platform does not support PHP 7") if self.app.pargs.mysql: if ((EEVariables.ee_mysql_host is "localhost") or (EEVariables.ee_mysql_host is "127.0.0.1")): if (EEAptGet.is_installed(self, 'mysql-server') or EEAptGet.is_installed(self, 'percona-server-server-5.6') or EEAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn( self, "Remote MySQL found, " "Unable to check MySQL service status") if self.app.pargs.postfix: if EEAptGet.is_installed(self, 'postfix'): services = services + ['postfix'] else: Log.info(self, "Postfix is not installed") if self.app.pargs.hhvm: Log.info(self, "HHVM does not support to reload") if self.app.pargs.memcache: if EEAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcache is not installed") if self.app.pargs.dovecot: if EEAptGet.is_installed(self, 'dovecot-core'): services = services + ['dovecot'] else: Log.info(self, "Mail server is not installed") if self.app.pargs.redis: if EEAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") for service in services: Log.debug(self, "Reloading service: {0}".format(service)) EEService.reload_service(self, service)
def default(self): """Default function of debug""" self.start = True self.interactive = False self.msg = [] self.trigger_nginx = False self.trigger_php = False if self.app.pargs.stop: self.start = False if ( (not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and (not self.app.pargs.site_name) ): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.fpm = True self.app.pargs.mysql = True self.app.pargs.rewrite = True if ( (not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and self.app.pargs.site_name ): self.app.pargs.nginx = True self.app.pargs.wp = True self.app.pargs.rewrite = True if self.app.pargs.nginx: self.debug_nginx() if self.app.pargs.php: self.debug_php() if self.app.pargs.fpm: self.debug_fpm() if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if EEVariables.ee_mysql_host is "localhost": self.debug_mysql() else: Log.warn(self, "Remote MySQL found, EasyEngine will not " "enable remote debug") if self.app.pargs.wp: self.debug_wp() if self.app.pargs.rewrite: self.debug_rewrite() if self.app.pargs.interactive: self.interactive = True # Reload Nginx if self.trigger_nginx: EEService.reload_service(self, "nginx") # Reload PHP if self.trigger_php: EEService.reload_service(self, "php5-fpm") if len(self.msg) > 0: if not self.app.pargs.interactive: disp_msg = " ".join(self.msg) Log.info( self, "Use following command to check debug logs:\n" + Log.ENDC + "tail -f {0}".format(disp_msg) ) else: signal.signal(signal.SIGINT, self.signal_handler) watch_list = [] for w_list in self.msg: watch_list = watch_list + glob.glob(w_list) logwatch(self, watch_list)
def stop(self): """Stop services""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.postfix or self.app.pargs.hhvm or self.app.pargs.memcache or self.app.pargs.dovecot or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.postfix = True if self.app.pargs.nginx: if EEAptGet.is_installed(self, 'nginx-custom') or EEAptGet.is_installed( self, 'nginx-mainline'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if EEAptGet.is_installed(self, 'php5-fpm'): services = services + ['php5-fpm'] else: Log.info(self, "PHP5-FPM is not installed") if self.app.pargs.mysql: if ((EEVariables.ee_mysql_host is "localhost") or (EEVariables.ee_mysql_host is "127.0.0.1")): if (EEAptGet.is_installed(self, 'mysql-server') or EEAptGet.is_installed(self, 'percona-server-server-5.6') or EEAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn( self, "Remote MySQL found, " "Unable to check MySQL service status") if self.app.pargs.postfix: if EEAptGet.is_installed(self, 'postfix'): services = services + ['postfix'] else: Log.info(self, "Postfix is not installed") if self.app.pargs.hhvm: if EEAptGet.is_installed(self, 'hhvm'): services = services + ['hhvm'] else: Log.info(self, "HHVM is not installed") if self.app.pargs.memcache: if EEAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcache is not installed") if self.app.pargs.dovecot: if EEAptGet.is_installed(self, 'dovecot-core'): services = services + ['dovecot'] else: Log.info(self, "Mail server is not installed") if self.app.pargs.redis: if EEAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") for service in services: Log.debug(self, "Stopping service: {0}".format(service)) EEService.stop_service(self, service)
def default(self): # self.app.render((data), 'default.mustache') # Check domain name validation data = dict() try: stype, cache = detSitePar(vars(self.app.pargs)) except RuntimeError as e: Log.debug(self, str(e)) Log.error(self, "Please provide valid options to creating site") if not self.app.pargs.site_name: try: while not self.app.pargs.site_name: # preprocessing before finalize site name self.app.pargs.site_name = (input('Enter site name : ') .strip()) except IOError as e: Log.debug(self, str(e)) Log.error(self, "Unable to input site name, 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 ee_domain.strip(): Log.error("Invalid domain name, " "Provide valid domain name") ee_site_webroot = EEVariables.ee_webroot + ee_domain if check_domain_exists(self, ee_domain): Log.error(self, "site {0} already exists".format(ee_domain)) elif os.path.isfile('/etc/nginx/sites-available/{0}' .format(ee_domain)): Log.error(self, "Nginx configuration /etc/nginx/sites-available/" "{0} already exists".format(ee_domain)) if stype in ['html', 'php']: data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=True, basic=False, wp=False, w3tc=False, wpfc=False, wpsc=False, multisite=False, wpsubdir=False, webroot=ee_site_webroot) if stype == 'php': data['static'] = False data['basic'] = True elif stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=True, wp=False, w3tc=False, wpfc=False, wpsc=False, multisite=False, wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') if stype in ['wp', 'wpsubdir', 'wpsubdomain']: data['wp'] = True data['basic'] = False data[cache] = True if stype in ['wpsubdir', 'wpsubdomain']: data['multisite'] = True if stype == 'wpsubdir': data['wpsubdir'] = True if stype == "html" and self.app.pargs.hhvm: Log.error(self, "Can not create HTML site with HHVM") if data and self.app.pargs.hhvm: data['hhvm'] = True hhvm = 1 elif data: data['hhvm'] = False hhvm = 0 if data and self.app.pargs.pagespeed: data['pagespeed'] = True pagespeed = 1 elif data: data['pagespeed'] = False pagespeed = 0 if not data: self.app.args.print_help() self.app.close(1) # Check rerequired packages are installed or not ee_auth = site_package_check(self, stype) try: try: # setup NGINX configuration, and webroot setupdomain(self, data) except SiteError as e: # call cleanup actions on failure Log.info(self, Log.FAIL + "Oops Something went wrong !!") Log.info(self, Log.FAIL + "Calling cleanup actions ...") doCleanupAction(self, domain=ee_domain, webroot=data['webroot']) Log.debug(self, str(e)) Log.error(self, "Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") # Update pagespeed config if self.app.pargs.pagespeed: operateOnPagespeed(self, data) addNewSite(self, ee_domain, stype, cache, ee_site_webroot, hhvm=hhvm, pagespeed=pagespeed) # Setup database for MySQL site if 'ee_db_name' in data.keys() and not data['wp']: try: data = setupdatabase(self, data) # Add database information for site into database updateSiteInfo(self, ee_domain, db_name=data['ee_db_name'], db_user=data['ee_db_user'], db_password=data['ee_db_pass'], db_host=data['ee_db_host']) except SiteError as e: # call cleanup actions on failure Log.debug(self, str(e)) Log.info(self, Log.FAIL + "Oops Something went wrong !!") Log.info(self, Log.FAIL + "Calling cleanup actions ...") doCleanupAction(self, domain=ee_domain, webroot=data['webroot'], dbname=data['ee_db_name'], dbuser=data['ee_db_user'], dbhost=data['ee_db_host']) deleteSiteInfo(self, ee_domain) Log.error(self, "Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") try: eedbconfig = open("{0}/ee-config.php" .format(ee_site_webroot), encoding='utf-8', mode='w') eedbconfig.write("<?php \ndefine('DB_NAME', '{0}');" "\ndefine('DB_USER', '{1}'); " "\ndefine('DB_PASSWORD', '{2}');" "\ndefine('DB_HOST', '{3}');\n?>" .format(data['ee_db_name'], data['ee_db_user'], data['ee_db_pass'], data['ee_db_host'])) eedbconfig.close() stype = 'mysql' except IOError as e: Log.debug(self, str(e)) Log.debug(self, "Error occured while generating " "ee-config.php") Log.info(self, Log.FAIL + "Oops Something went wrong !!") Log.info(self, Log.FAIL + "Calling cleanup actions ...") doCleanupAction(self, domain=ee_domain, webroot=data['webroot'], dbname=data['ee_db_name'], dbuser=data['ee_db_user'], dbhost=data['ee_db_host']) deleteSiteInfo(self, ee_domain) Log.error(self, "Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") # Setup WordPress if Wordpress site if data['wp']: try: ee_wp_creds = setupwordpress(self, data) # Add database information for site into database updateSiteInfo(self, ee_domain, db_name=data['ee_db_name'], db_user=data['ee_db_user'], db_password=data['ee_db_pass'], db_host=data['ee_db_host']) except SiteError as e: # call cleanup actions on failure Log.debug(self, str(e)) Log.info(self, Log.FAIL + "Oops Something went wrong !!") Log.info(self, Log.FAIL + "Calling cleanup actions ...") doCleanupAction(self, domain=ee_domain, webroot=data['webroot'], dbname=data['ee_db_name'], dbuser=data['ee_db_user'], dbhost=data['ee_db_host']) deleteSiteInfo(self, ee_domain) Log.error(self, "Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") # Service Nginx Reload EEService.reload_service(self, 'nginx') EEGit.add(self, ["/etc/nginx"], msg="{0} created with {1} {2}" .format(ee_www_domain, stype, cache)) # Setup Permissions for webroot try: setwebrootpermissions(self, data['webroot']) except SiteError as e: Log.debug(self, str(e)) Log.info(self, Log.FAIL + "Oops Something went wrong !!") Log.info(self, Log.FAIL + "Calling cleanup actions ...") doCleanupAction(self, domain=ee_domain, webroot=data['webroot'], dbname=data['ee_db_name'], dbuser=data['ee_db_user'], dbhost=data['ee_db_host']) deleteSiteInfo(self, ee_domain) Log.error(self, "Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!") if ee_auth and len(ee_auth): for msg in ee_auth: Log.info(self, Log.ENDC + msg, log=False) if data['wp']: Log.info(self, Log.ENDC + "WordPress admin user :"******" {0}".format(ee_wp_creds['wp_user']), log=False) Log.info(self, Log.ENDC + "WordPress admin user password : {0}" .format(ee_wp_creds['wp_pass']), log=False) display_cache_settings(self, data) Log.info(self, "Successfully created site" " http://{0}".format(ee_domain)) except SiteError as e: Log.error(self, "Check logs for reason " "`tail /var/log/ee/ee.log` & Try Again!!!")
def default(self): """Default function of debug""" # self.start = True self.interactive = False self.msg = [] self.trigger_nginx = False self.trigger_php = False if ((not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.php7) and (not self.app.pargs.fpm) and (not self.app.pargs.fpm7) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and (not self.app.pargs.all) and (not self.app.pargs.site_name) and (not self.app.pargs.import_slow_log) and (not self.app.pargs.interval)): if self.app.pargs.stop or self.app.pargs.start: print("--start/stop option is deprecated since ee3.0.5") self.app.args.print_help() else: self.app.args.print_help() if self.app.pargs.import_slow_log: self.import_slow_log() if self.app.pargs.interval: try: cron_time = int(self.app.pargs.interval) except Exception as e: cron_time = 5 try: if not EEShellExec.cmd_exec(self, "crontab -l | grep " "'ee debug --import-slow-log'"): if not cron_time == 0: Log.info(self, "setting up crontab entry," " please wait...") EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l " "2> /dev/null | {{ cat; echo -e" " \\\"#EasyEngine start MySQL " "slow log \\n*/{0} * * * * " "/usr/local/bin/ee debug" " --import-slow-log\\n" "#EasyEngine end MySQL slow log" "\\\"; }} | crontab -\"" .format(cron_time)) else: if not cron_time == 0: Log.info(self, "updating crontab entry," " please wait...") if not EEShellExec.cmd_exec(self, "/bin/bash -c " "\"crontab " "-l | sed '/EasyEngine " "start MySQL slow " "log/!b;n;c\*\/{0} " "\* \* \* " "\* \/usr" "\/local\/bin\/ee debug " "--import\-slow\-log' " "| crontab -\"" .format(cron_time)): Log.error(self, "failed to update crontab entry") else: Log.info(self, "removing crontab entry," " please wait...") if not EEShellExec.cmd_exec(self, "/bin/bash -c " "\"crontab " "-l | sed '/EasyEngine " "start MySQL slow " "log/,+2d'" "| crontab -\"" .format(cron_time)): Log.error(self, "failed to remove crontab entry") except CommandExecutionError as e: Log.debug(self, str(e)) if self.app.pargs.all == 'on': if self.app.pargs.site_name: self.app.pargs.wp = 'on' self.app.pargs.nginx = 'on' self.app.pargs.php = 'on' self.app.pargs.fpm = 'on' if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial') and EEAptGet.is_installed(self,'php7.0-fpm'): self.app.pargs.php7 = 'on' self.app.pargs.fpm7 = 'on' self.app.pargs.mysql = 'on' self.app.pargs.rewrite = 'on' if self.app.pargs.all == 'off': if self.app.pargs.site_name: self.app.pargs.wp = 'off' self.app.pargs.nginx = 'off' self.app.pargs.php = 'off' self.app.pargs.fpm = 'off' if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial') and EEAptGet.is_installed(self,'php7.0-fpm'): self.app.pargs.php7 = 'off' self.app.pargs.fpm7 = 'off' self.app.pargs.mysql = 'off' self.app.pargs.rewrite = 'off' if ((not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.php7) and (not self.app.pargs.fpm) and (not self.app.pargs.fpm7) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and self.app.pargs.site_name): self.app.args.print_help() # self.app.pargs.nginx = 'on' # self.app.pargs.wp = 'on' # self.app.pargs.rewrite = 'on' if self.app.pargs.nginx: self.debug_nginx() if self.app.pargs.php: self.debug_php() if self.app.pargs.fpm: self.debug_fpm() if self.app.pargs.php7: self.debug_php7() if self.app.pargs.fpm7: self.debug_fpm7() if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if EEVariables.ee_mysql_host is "localhost": self.debug_mysql() else: Log.warn(self, "Remote MySQL found, EasyEngine will not " "enable remote debug") if self.app.pargs.wp: self.debug_wp() if self.app.pargs.rewrite: self.debug_rewrite() if self.app.pargs.interactive: self.interactive = True # Reload Nginx if self.trigger_nginx: EEService.reload_service(self, 'nginx') # Reload PHP if self.trigger_php: if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial'): if EEAptGet.is_installed(self,'php5.6-fpm'): EEService.restart_service(self, 'php5.6-fpm') if EEAptGet.is_installed(self,'php7.0-fpm'): EEService.restart_service(self, 'php7.0-fpm') else: EEService.restart_service(self, 'php5-fpm') if len(self.msg) > 0: if not self.app.pargs.interactive: disp_msg = ' '.join(self.msg) Log.info(self, "Use following command to check debug logs:\n" + Log.ENDC + "tail -f {0}".format(disp_msg)) else: signal.signal(signal.SIGINT, self.signal_handler) watch_list = [] for w_list in self.msg: watch_list = watch_list + glob.glob(w_list) logwatch(self, watch_list)
def migrate_mariadb(self): # Backup all database EEMysql.backupAll(self) # Add MariaDB repo Log.info(self, "Adding repository for MariaDB, please wait ...") mysql_pref = ("Package: *\nPin: origin mirror.aarnet.edu.au" "\nPin-Priority: 1000\n") with open('/etc/apt/preferences.d/' 'MariaDB.pref', 'w') as mysql_pref_file: mysql_pref_file.write(mysql_pref) EERepo.add(self, repo_url=EEVariables.ee_mysql_repo) Log.debug(self, 'Adding key for {0}' .format(EEVariables.ee_mysql_repo)) EERepo.add_key(self, '0xcbcb082a1bb943db', keyserver="keyserver.ubuntu.com") config = configparser.ConfigParser() config.read(os.path.expanduser("~")+'/.my.cnf') try: chars = config['client']['password'] except Exception as e: Log.error(self, "Error: process exited with error %s" % e) Log.debug(self, "Pre-seeding MariaDB") Log.debug(self, "echo \"mariadb-server-10.0 " "mysql-server/root_password " "password \" | " "debconf-set-selections") EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 " "mysql-server/root_password " "password {chars}\" | " "debconf-set-selections" .format(chars=chars), log=False) Log.debug(self, "echo \"mariadb-server-10.0 " "mysql-server/root_password_again " "password \" | " "debconf-set-selections") EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 " "mysql-server/root_password_again " "password {chars}\" | " "debconf-set-selections" .format(chars=chars), log=False) # Install MariaDB apt_packages = EEVariables.ee_mysql # If PHP is installed then install php5-mysql if EEAptGet.is_installed(self, "php5-fpm"): apt_packages = apt_packages + ["php5-mysql"] # If mail server is installed then install dovecot-sql and postfix-sql if EEAptGet.is_installed(self, "dovecot-core"): apt_packages = apt_packages + ["dovecot-mysql", "postfix-mysql", "libclass-dbi-mysql-perl"] Log.info(self, "Updating apt-cache, please wait ...") EEAptGet.update(self) Log.info(self, "Installing MariaDB, please wait ...") EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"]) EEAptGet.auto_remove(self) EEAptGet.install(self, apt_packages) # Restart dovecot and postfix if installed if EEAptGet.is_installed(self, "dovecot-core"): EEService.restart_service(self, 'dovecot') EEService.restart_service(self, 'postfix')
def stop(self): """Stop services""" services = [] if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.postfix or self.app.pargs.hhvm or self.app.pargs.memcache or self.app.pargs.dovecot or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True self.app.pargs.postfix = True if self.app.pargs.nginx: if EEAptGet.is_installed(self, 'nginx-custom') or EEAptGet.is_installed(self,'nginx-mainline'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if EEAptGet.is_installed(self, 'php5-fpm'): services = services + ['php5-fpm'] else: Log.info(self, "PHP5-FPM is not installed") if self.app.pargs.mysql: if ((EEVariables.ee_mysql_host is "localhost") or (EEVariables.ee_mysql_host is "127.0.0.1")): if (EEAptGet.is_installed(self, 'mysql-server') or EEAptGet.is_installed(self, 'percona-server-server-5.6') or EEAptGet.is_installed(self, 'mariadb-server')): services = services + ['mysql'] else: Log.info(self, "MySQL is not installed") else: Log.warn(self, "Remote MySQL found, " "Unable to check MySQL service status") if self.app.pargs.postfix: if EEAptGet.is_installed(self, 'postfix'): services = services + ['postfix'] else: Log.info(self, "Postfix is not installed") if self.app.pargs.hhvm: if EEAptGet.is_installed(self, 'hhvm'): services = services + ['hhvm'] else: Log.info(self, "HHVM is not installed") if self.app.pargs.memcache: if EEAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcache is not installed") if self.app.pargs.dovecot: if EEAptGet.is_installed(self, 'dovecot-core'): services = services + ['dovecot'] else: Log.info(self, "Mail server is not installed") if self.app.pargs.redis: if EEAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") for service in services: Log.debug(self, "Stopping service: {0}".format(service)) EEService.stop_service(self, service)