def enable(self): pargs = self.app.pargs if not pargs.site_name: try: while not pargs.site_name: pargs.site_name = (input('Enter site name : ').strip()) except IOError as e: Log.debug(self, str(e)) Log.error(self, 'could not input site name') pargs.site_name = pargs.site_name.strip() # validate domain name wo_domain = WODomain.validate(self, pargs.site_name) # check if site exists if not check_domain_exists(self, wo_domain): Log.error(self, "site {0} does not exist".format(wo_domain)) if os.path.isfile('/etc/nginx/sites-available/{0}'.format(wo_domain)): Log.info(self, "Enable domain {0:10} \t".format(wo_domain), end='') WOFileUtils.create_symlink(self, [ '/etc/nginx/sites-available/{0}'.format(wo_domain), '/etc/nginx/sites-enabled/{0}'.format(wo_domain) ]) WOGit.add(self, ["/etc/nginx"], msg="Enabled {0} ".format(wo_domain)) updateSiteInfo(self, wo_domain, enabled=True) Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]") if not WOService.reload_service(self, 'nginx'): Log.error( self, "service nginx reload failed. " "check issues with `nginx -t` command") else: Log.error(self, 'nginx configuration file does not exist')
def migrate_mariadb(self, ci=False): # Backup all database WOMysql.backupAll(self, fulldump=True) # Remove previous MariaDB repository wo_mysql_old_repo = ("deb [arch=amd64,ppc64el] " "http://mariadb.mirrors.ovh.net/MariaDB/repo/" "10.3/{distro} {codename} main".format( distro=WOVar.wo_distro, codename=WOVar.wo_platform_codename)) if WOFileUtils.grepcheck(self, '/etc/apt/sources.list.d/wo-repo.list', wo_mysql_old_repo): WORepo.remove(self, repo_url=wo_mysql_old_repo) # Add MariaDB repo pre_pref(self, WOVar.wo_mysql) # Install MariaDB Log.wait(self, "Updating apt-cache ") WOAptGet.update(self) Log.valide(self, "Updating apt-cache ") Log.wait(self, "Upgrading MariaDB ") WOAptGet.remove(self, ["mariadb-server"]) WOAptGet.auto_remove(self) WOAptGet.install(self, WOVar.wo_mysql) if not ci: WOAptGet.dist_upgrade(self) WOAptGet.auto_remove(self) Log.valide(self, "Upgrading MariaDB ") WOFileUtils.mvfile(self, '/etc/mysql/my.cnf', '/etc/mysql/my.cnf.old') WOFileUtils.create_symlink( self, ['/etc/mysql/mariadb.cnf', '/etc/mysql/my.cnf']) WOShellExec.cmd_exec(self, 'systemctl daemon-reload') WOShellExec.cmd_exec(self, 'systemctl enable mariadb') post_pref(self, WOVar.wo_mysql, [])
def upgrade_php56(self): if WOVariables.wo_platform_distro == "ubuntu": if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}." "list".format(WOVariables.wo_platform_codename)): Log.error(self, "Unable to find PHP 5.5") else: if not(os.path.isfile(WOVariables.wo_repo_file_path) and WOFileUtils.grep(self, WOVariables.wo_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 WOVariables.wo_platform_distro == "ubuntu": WORepo.remove(self, ppa="ppa:ondrej/php5") WORepo.add(self, ppa=WOVariables.wo_php_repo) else: WOAptGet.remove(self, ["php5-xdebug"]) WOFileUtils.searchreplace(self, WOVariables.wo_repo_file_path, "php55", "php56") Log.info(self, "Updating apt-cache, please wait...") WOAptGet.update(self) Log.info(self, "Installing packages, please wait ...") if (WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic'): WOAptGet.install(self, WOVariables.wo_php5_6 + WOVariables.wo_php_extra) else: WOAptGet.install(self, WOVariables.wo_php) if WOVariables.wo_platform_distro == "debian": WOShellExec.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") WOFileUtils.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 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/php/7.2/slow.log', 'a').close() open('/var/log/php7.2-fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log' ] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if WOVar.wo_mysql_host == "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, WordOps does not support" "remote MySQL servers or log files") if self.app.pargs.site_name: webroot = "{0}{1}".format(WOVar.wo_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(WOVar.wo_webroot, self.app.pargs.site_name) ] if self.app.pargs.nginx: self.msg = self.msg + [ "{0}/{1}/logs/error.log".format(WOVar.wo_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() WOShellExec.cmd_exec( self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, WOVar.wo_php_user)) # create symbolic link for debug log WOFileUtils.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( WOVar.wo_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)
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/php/7.2/slow.log', 'a').close() open('/var/log/php7.2-fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log' ] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if WOVar.wo_mysql_host == "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, WordOps does not support" "remote MySQL servers or log files") if self.app.pargs.site_name: webroot = "{0}{1}".format(WOVar.wo_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(WOVar.wo_webroot, self.app.pargs.site_name) ] if self.app.pargs.nginx: self.msg = self.msg + [ "{0}/{1}/logs/error.log".format(WOVar.wo_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() WOShellExec.cmd_exec( self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, WOVar.wo_php_user)) # create symbolic link for debug log WOFileUtils.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( WOVar.wo_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])) WOSendMail("wordops", tomail[0], "{0} Log Files".format(WOVar.wo_fqdn), "Hi,\n The requested logfiles are attached." "\n\nBest regards,\nYour WordOps worker", files=mail_list, port=25, isTls=False)
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") WOMysql.execute( self, "TRUNCATE TABLE " "slow_query_log.global_query_review_history") WOMysql.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/php/7.2/slow.log', 'a').close() open('/var/log/php7.2-fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log' ] if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if WOVar.wo_mysql_host == "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, WordOps does not support" "remote MySQL servers or log files") if self.app.pargs.site_name: webroot = "{0}{1}".format(WOVar.wo_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(WOVar.wo_webroot, self.app.pargs.site_name) ] if self.app.pargs.nginx: self.msg = self.msg + [ "{0}/{1}/logs/error.log".format(WOVar.wo_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() WOShellExec.cmd_exec( self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, WOVar.wo_php_user)) # create symbolic link for debug log WOFileUtils.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( WOVar.wo_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): """Default function of log GZip""" 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 WOVariables.wo_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, WordOps does not support" "remote MySQL servers or log files") if self.app.pargs.site_name: webroot = "{0}{1}".format(WOVariables.wo_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(WOVariables.wo_webroot, self.app.pargs.site_name)] if self.app.pargs.nginx: self.msg = self.msg + ["{0}/{1}/logs/error.log" .format(WOVariables.wo_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() WOShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/" "wp-content/debug.log" "".format(webroot, WOVariables .wo_php_user) ) # create symbolic link for debug log WOFileUtils.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(WOVariables.wo_webroot, self.app.pargs.site_name)] else: Log.info(self, "Site is not WordPress site, skipping " "WordPress logs") gzip_list = [] for g_list in self.msg: gzip_list = gzip_list + glob.glob(g_list) # Gzip content of file for g_list in gzip_list: Log.info(self, "Gzipping file {file}".format(file=g_list)) in_file = g_list in_data = open(in_file, "rb").read() out_gz = g_list + ".gz" gzf = gzip.open(out_gz, "wb") gzf.write(in_data) gzf.close()