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/php/7.2/slow.log', 'a').close() #open('/var/log/php7.2-fpm.log', 'a').close() self.msg = self.msg + [ '/var/log/php/*/slow.log', '/var/log/php*-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/mariadb-slow.log'): self.msg = self.msg + ['/var/log/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") 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()
def install(self, packages=[], apt_packages=[], disp_msg=True): """Start installation of packages""" self.msg = [] empty_packages = [] wo_webroot = "/var/www/" pargs = self.app.pargs try: # Default action for stack installation if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx) and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli) and (not pargs.phpmyadmin) and (not pargs.composer) and (not pargs.netdata) and (not pargs.dashboard) and (not pargs.fail2ban) and (not pargs.security) and (not pargs.mysqlclient) and (not pargs.mysqltuner) and (not pargs.adminer) and (not pargs.utils) and (not pargs.redis) and (not pargs.proftpd) and (not pargs.extplorer) and (not pargs.cheat) and (not pargs.clamav) and (not pargs.phpredisadmin) and (not pargs.php73)): pargs.web = True pargs.admin = True pargs.fail2ban = True if pargs.all: pargs.web = True pargs.admin = True pargs.php73 = True pargs.redis = True pargs.proftpd = True pargs.security = True if pargs.web: pargs.nginx = True pargs.php = True pargs.mysql = True pargs.wpcli = True if pargs.admin: pargs.adminer = True pargs.phpmyadmin = True pargs.composer = True pargs.utils = True pargs.netdata = True pargs.dashboard = True pargs.phpredisadmin = True pargs.extplorer = True pargs.cheat = True if pargs.security: pargs.fail2ban = True pargs.clamav = True # Nginx if pargs.nginx: Log.debug(self, "Setting apt_packages variable for Nginx") if not (WOAptGet.is_installed(self, 'nginx-custom')): if not (WOAptGet.is_installed(self, 'nginx-plus') or WOAptGet.is_installed(self, 'nginx')): apt_packages = apt_packages + WOVariables.wo_nginx else: if WOAptGet.is_installed(self, 'nginx-plus'): Log.info(self, "NGINX PLUS Detected ...") apt = ["nginx-plus"] + WOVariables.wo_nginx self.post_pref(apt, empty_packages) elif WOAptGet.is_installed(self, 'nginx'): Log.info( self, "WordOps detected an already " "installed nginx package." "It may or may not have " "required modules.\n") apt = ["nginx"] + WOVariables.wo_nginx self.post_pref(apt, empty_packages) else: Log.debug(self, "Nginx Stable already installed") # Redis if pargs.redis: if not WOAptGet.is_installed(self, 'redis-server'): apt_packages = apt_packages + WOVariables.wo_redis pargs.php = True else: Log.info(self, "Redis already installed") # PHP 7.2 if pargs.php: Log.debug(self, "Setting apt_packages variable for PHP 7.2") if not (WOAptGet.is_installed(self, 'php7.2-fpm')): if not (WOAptGet.is_installed(self, 'php7.3-fpm')): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php else: Log.debug(self, "PHP 7.2 already installed") Log.info(self, "PHP 7.2 already installed") # PHP 7.3 if pargs.php73: Log.debug(self, "Setting apt_packages variable for PHP 7.3") if not WOAptGet.is_installed(self, 'php7.3-fpm'): if not (WOAptGet.is_installed(self, 'php7.2-fpm')): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php73 + WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php73 else: Log.debug(self, "PHP 7.3 already installed") Log.info(self, "PHP 7.3 already installed") # MariaDB 10.3 if pargs.mysql: pargs.mysqltuner = True Log.debug(self, "Setting apt_packages variable for MySQL") if not WOShellExec.cmd_exec(self, "mysqladmin ping"): apt_packages = apt_packages + WOVariables.wo_mysql else: Log.debug(self, "MySQL already installed and alive") Log.info(self, "MySQL already installed and alive") # mysqlclient if pargs.mysqlclient: Log.debug(self, "Setting apt_packages variable " "for MySQL Client") if not WOShellExec.cmd_exec(self, "mysqladmin ping"): apt_packages = apt_packages + WOVariables.wo_mysql_client else: Log.debug(self, "MySQL already installed and alive") Log.info(self, "MySQL already installed and alive") # WP-CLI if pargs.wpcli: Log.debug(self, "Setting packages variable for WP-CLI") if (not os.path.isfile("/usr/local/bin/wp") and not os.path.isfile("/usr/bin/wp")): packages = packages + [[ "https://github.com/wp-cli/wp-cli/" "releases/download/v{0}/" "wp-cli-{0}.phar" "".format(WOVariables.wo_wp_cli), "/usr/local/bin/wp", "WP-CLI" ]] else: Log.debug(self, "WP-CLI is already installed") Log.info(self, "WP-CLI is already installed") # fail2ban if pargs.fail2ban: Log.debug(self, "Setting apt_packages variable for Fail2ban") if not WOAptGet.is_installed(self, 'fail2ban'): apt_packages = apt_packages + WOVariables.wo_fail2ban else: Log.debug(self, "Fail2ban already installed") Log.info(self, "Fail2ban already installed") # ClamAV if pargs.clamav: Log.debug(self, "Setting apt_packages variable for ClamAV") if not WOAptGet.is_installed(self, 'clamav'): apt_packages = apt_packages + ["clamav"] else: Log.debug(self, "ClamAV already installed") Log.info(self, "ClamAV already installed") # proftpd if pargs.proftpd: Log.debug(self, "Setting apt_packages variable for ProFTPd") if not WOAptGet.is_installed(self, 'proftpd-basic'): apt_packages = apt_packages + ["proftpd-basic"] else: Log.debug(self, "ProFTPd already installed") Log.info(self, "ProFTPd already installed") # PHPMYADMIN if pargs.phpmyadmin: pargs.composer = True if not os.path.isdir('/var/www/22222/htdocs/db/pma'): Log.debug(self, "Setting packages variable " "for phpMyAdmin ") packages = packages + [[ "https://github.com/phpmyadmin/" "phpmyadmin/archive/STABLE.tar.gz", "/var/lib/wo/tmp/pma.tar.gz", "phpMyAdmin" ]] else: Log.debug(self, "phpMyAdmin already installed") Log.info(self, "phpMyAdmin already installed") # PHPREDISADMIN if pargs.phpredisadmin: pargs.composer = True if not os.path.isdir('/var/www/22222/htdocs/' 'cache/redis/phpRedisAdmin'): Log.debug(self, "Setting packages variable for phpRedisAdmin") packages = packages + [[ "https://github.com/" "erikdubbelboer/" "phpRedisAdmin/archive" "/v1.11.3.tar.gz", "/var/lib/wo/tmp/pra.tar.gz", "phpRedisAdmin" ]] else: Log.debug(self, "phpRedisAdmin already installed") Log.info(self, "phpRedisAdmin already installed") # Composer if pargs.composer: if not os.path.isfile('/usr/local/bin/composer'): Log.debug(self, "Setting packages variable for Composer ") packages = packages + [[ "https://getcomposer.org/" "installer", "/var/lib/wo/tmp/composer-install", "Composer" ]] else: Log.debug(self, "Composer already installed") Log.info(self, "Composer already installed") # ADMINER if pargs.adminer: if not os.path.isfile("{0}22222/htdocs/db/" "adminer/index.php".format(wo_webroot)): Log.debug(self, "Setting packages variable for Adminer ") packages = packages + [ [ "https://github.com/vrana/adminer/" "releases/download/v{0}" "/adminer-{0}.php".format(WOVariables.wo_adminer), "{0}22222/" "htdocs/db/adminer/index.php".format( WOVariables.wo_webroot), "Adminer" ], [ "https://raw.githubusercontent.com" "/vrana/adminer/master/designs/" "pepa-linha/adminer.css", "{0}22222/" "htdocs/db/adminer/adminer.css".format( WOVariables.wo_webroot), "Adminer theme" ] ] else: Log.debug(self, "Adminer already installed") Log.info(self, "Adminer already installed") # mysqltuner if pargs.mysqltuner: if not os.path.isfile("/usr/bin/mysqltuner"): Log.debug(self, "Setting packages variable " "for MySQLTuner ") packages = packages + [[ "https://raw." "githubusercontent.com/" "major/MySQLTuner-perl" "/master/mysqltuner.pl", "/usr/bin/mysqltuner", "MySQLTuner" ]] else: Log.debug(self, "MySQLtuner already installed") Log.info(self, "MySQLtuner already installed") # Netdata if pargs.netdata: if (not os.path.isdir('/opt/netdata') and not os.path.isdir("/etc/netdata")): Log.debug(self, "Setting packages variable for Netdata") if WOVariables.wo_distro == 'raspbian': packages = packages + [[ 'https://my-netdata.io/' 'kickstart.sh', '/var/lib/wo/tmp/kickstart.sh', 'Netdata' ]] else: packages = packages + [[ 'https://my-netdata.io/' 'kickstart-static64.sh', '/var/lib/wo/tmp/kickstart.sh', 'Netdata' ]] else: Log.debug(self, "Netdata already installed") Log.info(self, "Netdata already installed") # WordOps Dashboard if pargs.dashboard: if not os.path.isfile('/var/www/22222/htdocs/index.php'): Log.debug(self, "Setting packages variable for WO-Dashboard") packages = \ packages + [["https://github.com/WordOps" "/wordops-dashboard/" "releases/download/v{0}/" "wordops-dashboard.tar.gz" .format(WOVariables.wo_dashboard), "/var/lib/wo/tmp/wo-dashboard.tar.gz", "WordOps Dashboard"]] else: Log.debug(self, "WordOps dashboard already installed") Log.info(self, "WordOps dashboard already installed") # eXtplorer if pargs.explorer: if not os.path.isdir('/var/www/22222/htdocs/files'): Log.debug(self, "Setting packages variable for eXtplorer") packages = packages + \ [["https://github.com/soerennb/" "extplorer/archive/v{0}.tar.gz" .format(WOVariables.wo_extplorer), "/var/lib/wo/tmp/extplorer.tar.gz", "eXtplorer"]] else: Log.debug(self, "eXtplorer is already installed") Log.info(self, "eXtplorer is already installed") # cheat.sh if pargs.cheat: if not os.path.isfile('/usr/local/bin/cht.sh'): Log.debug(self, "Setting packages variable for cht.sh") packages = packages + [[ "https://cht.sh/:cht.sh", "/usr/local/bin/cht.sh", "cheat.sh" ]] else: Log.debug(self, "cheat.sh is already installed") Log.info(self, "cheat.sh is already installed") # UTILS if pargs.utils: Log.debug(self, "Setting packages variable for utils") packages = packages + [ [ "https://raw.githubusercontent.com" "/rtCamp/eeadmin/master/cache/nginx/" "clean.php", "{0}22222/htdocs/cache/" "nginx/clean.php".format(WOVariables.wo_webroot), "clean.php" ], [ "https://raw.github.com/rlerdorf/" "opcache-status/master/opcache.php", "{0}22222/htdocs/cache/" "opcache/opcache.php".format( WOVariables.wo_webroot), "opcache.php" ], [ "https://raw.github.com/amnuts/" "opcache-gui/master/index.php", "{0}22222/htdocs/" "cache/opcache/opgui.php".format( WOVariables.wo_webroot), "Opgui" ], [ "https://raw.githubusercontent.com/" "mlazarov/ocp/master/ocp.php", "{0}22222/htdocs/cache/" "opcache/ocp.php".format(WOVariables.wo_webroot), "OCP.php" ], [ "https://github.com/jokkedk/webgrind/" "archive/master.tar.gz", '/var/lib/wo/tmp/webgrind.tar.gz', 'Webgrind' ], [ "https://www.percona.com/" "get/pt-query-digest", "/usr/bin/pt-query-advisor", "pt-query-advisor" ], [ "https://github.com/box/Anemometer/" "archive/master.tar.gz", '/var/lib/wo/tmp/anemometer.tar.gz', 'Anemometer' ] ] except Exception as e: Log.debug(self, "{0}".format(e)) if (apt_packages) or (packages): if (apt_packages): Log.debug(self, "Calling pre_pref") pre_pref(self, apt_packages) # meminfo = (os.popen('/bin/cat /proc/meminfo ' # '| grep MemTotal').read()).split(":") # memsplit = re.split(" kB", meminfo[1]) # wo_mem = int(memsplit[0]) # if (wo_mem < 4000000): # WOSwap.add(self) Log.info(self, "Updating apt-cache, please wait...") WOAptGet.update(self) Log.info(self, "Installing packages, please wait...") WOAptGet.install(self, apt_packages) post_pref(self, apt_packages, empty_packages) if (packages): Log.debug(self, "Downloading following: {0}".format(packages)) WODownload.download(self, packages) Log.debug(self, "Calling post_pref") post_pref(self, empty_packages, packages) if disp_msg: if (self.msg): for msg in self.msg: Log.info(self, Log.ENDC + msg) Log.info(self, "Successfully installed packages") else: return self.msg
def reload(self): """Reload service""" services = [] pargs = self.app.pargs if not (pargs.nginx or pargs.php or pargs.php73 or pargs.mysql or pargs.netdata or pargs.proftpd or pargs.redis or pargs.fail2ban): pargs.nginx = True pargs.php = True pargs.mysql = True pargs.fail2ban = True if pargs.nginx: if (WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline')): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): services = services + ['php7.2-fpm'] else: Log.info(self, "PHP7.2-FPM is not installed") if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if pargs.php73: if WOAptGet.is_installed(self, 'php7.3-fpm'): services = services + ['php7.3-fpm'] else: Log.info(self, "PHP7.3-FPM is not installed") if pargs.mysql: if ((WOVariables.wo_mysql_host == "localhost") or (WOVariables.wo_mysql_host == "127.0.0.1")): if (WOAptGet.is_installed(self, 'mysql-server') or WOAptGet.is_installed(self, 'percona-server-server-5.6') or WOAptGet.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 pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): services = services + ['redis-server'] else: Log.info(self, "Redis server is not installed") if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): services = services + ['fail2ban'] else: Log.info(self, "fail2ban is not installed") # proftpd if pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): services = services + ['proftpd'] else: Log.info(self, "ProFTPd is not installed") # netdata if pargs.netdata: if (os.path.isdir("/opt/netdata") or os.path.isdir("/etc/netdata")): services = services + ['netdata'] else: Log.info(self, "Netdata is not installed") for service in services: Log.debug(self, "Reloading service: {0}".format(service)) WOService.reload_service(self, service)
def default(self): pargs = self.app.pargs if not pargs.site_name and not pargs.all: 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() wo_domain = WODomain.validate(self, pargs.site_name) wo_db_name = '' wo_prompt = '' wo_nginx_prompt = '' mark_db_delete_prompt = False mark_webroot_delete_prompt = False mark_db_deleted = False mark_webroot_deleted = False if not check_domain_exists(self, wo_domain): Log.error(self, "site {0} does not exist".format(wo_domain)) if ((not pargs.db) and (not pargs.files) and (not pargs.all)): pargs.all = True if pargs.force: pargs.no_prompt = True # Gather information from wo-db for wo_domain check_site = getSiteInfo(self, wo_domain) wo_site_type = check_site.site_type wo_site_webroot = check_site.site_path if wo_site_webroot == 'deleted': mark_webroot_deleted = True if wo_site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: wo_db_name = check_site.db_name wo_db_user = check_site.db_user if self.app.config.has_section('mysql'): wo_mysql_grant_host = self.app.config.get( 'mysql', 'grant-host') else: wo_mysql_grant_host = 'localhost' if wo_db_name == 'deleted': mark_db_deleted = True if pargs.all: pargs.db = True pargs.files = True else: if pargs.all: mark_db_deleted = True pargs.files = True # Delete website database if pargs.db: if wo_db_name != 'deleted' and wo_db_name != '': if not pargs.no_prompt: wo_db_prompt = input('Are you sure, you want to delete' ' database [y/N]: ') else: wo_db_prompt = 'Y' mark_db_delete_prompt = True if wo_db_prompt == 'Y' or wo_db_prompt == 'y': mark_db_delete_prompt = True Log.info(self, "Deleting Database, {0}, user {1}" .format(wo_db_name, wo_db_user)) deleteDB(self, wo_db_name, wo_db_user, wo_mysql_grant_host, False) updateSiteInfo(self, wo_domain, db_name='deleted', db_user='******', db_password='******') mark_db_deleted = True Log.info(self, "Deleted Database successfully.") else: mark_db_deleted = True Log.info(self, "Does not seems to have database for this site." ) # Delete webroot if pargs.files: if wo_site_webroot != 'deleted': if not pargs.no_prompt: wo_web_prompt = input('Are you sure, you want to delete ' 'webroot [y/N]: ') else: wo_web_prompt = 'Y' mark_webroot_delete_prompt = True if wo_web_prompt == 'Y' or wo_web_prompt == 'y': mark_webroot_delete_prompt = True Log.info(self, "Deleting Webroot, {0}" .format(wo_site_webroot)) deleteWebRoot(self, wo_site_webroot) updateSiteInfo(self, wo_domain, webroot='deleted') mark_webroot_deleted = True Log.info(self, "Deleted webroot successfully") else: mark_webroot_deleted = True Log.info(self, "Webroot seems to be already deleted") if not pargs.force: if (mark_webroot_deleted and mark_db_deleted): # TODO Delete nginx conf removeNginxConf(self, wo_domain) deleteSiteInfo(self, wo_domain) Log.info(self, "Deleted site {0}".format(wo_domain)) # else: # Log.error(self, " site {0} does # not exists".format(wo_domain)) else: if (mark_db_delete_prompt or mark_webroot_delete_prompt or (mark_webroot_deleted and mark_db_deleted)): # TODO Delete nginx conf removeNginxConf(self, wo_domain) deleteSiteInfo(self, wo_domain) Log.info(self, "Deleted site {0}".format(wo_domain))
def info_php(self): """Display PHP information""" version = os.popen("/usr/bin/php7.2 -v 2>/dev/null | " "head -n1 | cut -d' ' -f2 |" " cut -d'+' -f1 | tr -d '\n'").read config = configparser.ConfigParser() config.read('/etc/{0}/fpm/php.ini'.format("php/7.2")) expose_php = config['PHP']['expose_php'] memory_limit = config['PHP']['memory_limit'] post_max_size = config['PHP']['post_max_size'] upload_max_filesize = config['PHP']['upload_max_filesize'] max_execution_time = config['PHP']['max_execution_time'] config.read('/etc/{0}/fpm/pool.d/www.conf'.format("php/7.2")) www_listen = config['www']['listen'] www_ping_path = config['www']['ping.path'] www_pm_status_path = config['www']['pm.status_path'] www_pm = config['www']['pm'] www_pm_max_requests = config['www']['pm.max_requests'] www_pm_max_children = config['www']['pm.max_children'] www_pm_start_servers = config['www']['pm.start_servers'] www_pm_min_spare_servers = config['www']['pm.min_spare_servers'] www_pm_max_spare_servers = config['www']['pm.max_spare_servers'] www_request_terminate_time = ( config['www']['request_terminate_timeout']) try: www_xdebug = (config['www']['php_admin_flag[xdebug.profiler_enable' '_trigger]']) except Exception as e: Log.debug(self, "{0}".format(e)) www_xdebug = 'off' config.read('/etc/{0}/fpm/pool.d/debug.conf'.format("php/7.2")) debug_listen = config['debug']['listen'] debug_ping_path = config['debug']['ping.path'] debug_pm_status_path = config['debug']['pm.status_path'] debug_pm = config['debug']['pm'] debug_pm_max_requests = config['debug']['pm.max_requests'] debug_pm_max_children = config['debug']['pm.max_children'] debug_pm_start_servers = config['debug']['pm.start_servers'] debug_pm_min_spare_servers = config['debug']['pm.min_spare_servers'] debug_pm_max_spare_servers = config['debug']['pm.max_spare_servers'] debug_request_terminate = ( config['debug']['request_terminate_timeout']) try: debug_xdebug = (config['debug']['php_admin_flag[xdebug.profiler_' 'enable_trigger]']) except Exception as e: Log.debug(self, "{0}".format(e)) debug_xdebug = 'off' data = dict(version=version, expose_php=expose_php, memory_limit=memory_limit, post_max_size=post_max_size, upload_max_filesize=upload_max_filesize, max_execution_time=max_execution_time, www_listen=www_listen, www_ping_path=www_ping_path, www_pm_status_path=www_pm_status_path, www_pm=www_pm, www_pm_max_requests=www_pm_max_requests, www_pm_max_children=www_pm_max_children, www_pm_start_servers=www_pm_start_servers, www_pm_min_spare_servers=www_pm_min_spare_servers, www_pm_max_spare_servers=www_pm_max_spare_servers, www_request_terminate_timeout=www_request_terminate_time, www_xdebug_profiler_enable_trigger=www_xdebug, debug_listen=debug_listen, debug_ping_path=debug_ping_path, debug_pm_status_path=debug_pm_status_path, debug_pm=debug_pm, debug_pm_max_requests=debug_pm_max_requests, debug_pm_max_children=debug_pm_max_children, debug_pm_start_servers=debug_pm_start_servers, debug_pm_min_spare_servers=debug_pm_min_spare_servers, debug_pm_max_spare_servers=debug_pm_max_spare_servers, debug_request_terminate_timeout=debug_request_terminate, debug_xdebug_profiler_enable_trigger=debug_xdebug) self.app.render((data), 'info_php.mustache')
def setupletsencrypt(self, acme_domains, acmedata): """Issue SSL certificates with acme.sh""" # check acme.sh is installed WOAcme.check_acme(self) # define variables all_domains = '\' -d \''.join(acme_domains) wo_acme_dns = acmedata['acme_dns'] keylenght = acmedata['keylength'] if acmedata['dns'] is True: acme_mode = "--dns {0}".format(wo_acme_dns) validation_mode = "DNS mode with {0}".format(wo_acme_dns) if acmedata['dnsalias'] is True: acme_mode = acme_mode + \ " --challenge-alias {0}".format(acmedata['acme_alias']) else: acme_mode = "-w /var/www/html" validation_mode = "Webroot challenge" Log.debug(self, "Validation : Webroot mode") if not os.path.isdir('/var/www/html/.well-known/acme-challenge'): WOFileUtils.mkdir( self, '/var/www/html/.well-known/acme-challenge') WOFileUtils.chown( self, '/var/www/html/.well-known', 'www-data', 'www-data', recursive=True) WOFileUtils.chmod(self, '/var/www/html/.well-known', 0o750, recursive=True) Log.info(self, "Validation mode : {0}".format(validation_mode)) Log.wait(self, "Issuing SSL cert with acme.sh") if not WOShellExec.cmd_exec( self, "{0} ".format(WOAcme.wo_acme_exec) + "--issue -d '{0}' {1} -k {2} -f" .format(all_domains, acme_mode, keylenght)): Log.failed(self, "Issuing SSL cert with acme.sh") if acmedata['dns'] is True: Log.error( self, "Please make sure your properly " "set your DNS API credentials for acme.sh\n" "If you are using sudo, use \"sudo -E wo\"") return False else: Log.error( self, "Your domain is properly configured " "but acme.sh was unable to issue certificate.\n" "You can find more informations in " "/var/log/wo/wordops.log") return False else: Log.valide(self, "Issuing SSL cert with acme.sh") return True
def show(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') # TODO Write code for wo site edit command here pargs.site_name = pargs.site_name.strip() wo_domain = WODomain.validate(self, pargs.site_name) 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, "Display NGINX configuration for {0}" .format(wo_domain)) f = open('/etc/nginx/sites-available/{0}'.format(wo_domain), encoding='utf-8', mode='r') text = f.read() Log.info(self, Log.ENDC + text) f.close() else: Log.error(self, "nginx configuration file does not exists")
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.php73) and (not self.app.pargs.fpm) and (not self.app.pargs.fpm73) 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 wo v3.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: Log.debug(self, "{0}".format(e)) cron_time = 5 try: if not WOShellExec.cmd_exec(self, "crontab -l | grep " "'wo debug --import-slow-log'"): if not cron_time == 0: Log.info(self, "setting up crontab entry," " please wait...") WOShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l " "2> /dev/null | {{ cat; echo -e" " \\\"#WordOps start MySQL " "slow log \\n*/{0} * * * * " "/usr/local/bin/wo debug" " --import-slow-log\\n" "#WordOps end MySQL slow log" "\\\"; }} | crontab -\"" .format(cron_time)) else: if not cron_time == 0: Log.info(self, "updating crontab entry," " please wait...") if not WOShellExec.cmd_exec(self, "/bin/bash -c " "\"crontab " "-l | sed '/WordOps " "start MySQL slow " "log/!b;n;c\*\/{0} " "\* \* \* " "\* \/usr" "\/local\/bin\/wo 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 WOShellExec.cmd_exec(self, "/bin/bash -c " "\"crontab " "-l | sed '/WordOps " "start MySQL slow " "log/,+2d'" "| crontab -\""): 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 WOAptGet.is_installed(self, 'php7.2-fpm'): self.app.pargs.php73 = 'on' self.app.pargs.fpm73 = '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 WOAptGet.is_installed(self, 'php7.2-fpm'): self.app.pargs.php73 = 'off' self.app.pargs.fpm73 = '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.php73) and (not self.app.pargs.fpm) and (not self.app.pargs.fpm73) 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.php73: self.debug_php73() if self.app.pargs.fpm73: self.debug_fpm73() if self.app.pargs.mysql: # MySQL debug will not work for remote MySQL if WOVar.wo_mysql_host == "localhost": self.debug_mysql() else: Log.warn(self, "Remote MySQL found, WordOps does not support " "debugging remote servers") 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: WOService.reload_service(self, 'nginx') # Reload PHP if self.trigger_php: if WOAptGet.is_installed(self, 'php7.2-fpm'): WOService.restart_service(self, 'php7.2-fpm') if WOAptGet.is_installed(self, 'php7.3-fpm'): WOService.restart_service(self, 'php7.3-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 debug_nginx(self): """Start/Stop Nginx debug""" # start global debug if (self.app.pargs.nginx == 'on' and not self.app.pargs.site_name): try: debug_address = (self.app.config.get('stack', 'ip-address') .split()) except Exception as e: Log.debug(self, "{0}".format(e)) debug_address = ['0.0.0.0/0'] # Check if IP address is 127.0.0.1 then enable debug globally if debug_address == ['127.0.0.1'] or debug_address == []: debug_address = ['0.0.0.0/0'] for ip_addr in debug_address: if not ("debug_connection "+ip_addr in open('/etc/nginx/' 'nginx.conf', encoding='utf-8').read()): Log.info(self, "Setting up Nginx debug connection" " for "+ip_addr) WOShellExec.cmd_exec(self, "sed -i \"/events {{/a\\ \\ \\ " "\\ $(echo debug_connection " "{ip}\;)\" /etc/nginx/" "nginx.conf".format(ip=ip_addr)) self.trigger_nginx = True if not self.trigger_nginx: Log.info(self, "Nginx debug connection already enabled") self.msg = self.msg + ["/var/log/nginx/*.error.log"] # stop global debug elif (self.app.pargs.nginx == 'off' and not self.app.pargs.site_name): if "debug_connection " in open('/etc/nginx/nginx.conf', encoding='utf-8').read(): Log.info(self, "Disabling Nginx debug connections") WOShellExec.cmd_exec(self, "sed -i \"/debug_connection.*/d\"" " /etc/nginx/nginx.conf") self.trigger_nginx = True else: Log.info(self, "Nginx debug connection already disabled") # start site specific debug elif (self.app.pargs.nginx == 'on' and self.app.pargs.site_name): config_path = ("/etc/nginx/sites-available/{0}" .format(self.app.pargs.site_name)) if os.path.isfile(config_path): if not WOShellExec.cmd_exec(self, "grep \"error.log debug\" " "{0}".format(config_path)): Log.info(self, "Starting NGINX debug connection for " "{0}".format(self.app.pargs.site_name)) WOShellExec.cmd_exec(self, "sed -i \"s/error.log;/" "error.log " "debug;/\" {0}".format(config_path)) self.trigger_nginx = True else: Log.info(self, "Nginx debug for site already enabled") self.msg = self.msg + ['{0}{1}/logs/error.log' .format(WOVar.wo_webroot, self.app.pargs.site_name)] else: Log.info(self, "{0} domain not valid" .format(self.app.pargs.site_name)) # stop site specific debug elif (self.app.pargs.nginx == 'off' and self.app.pargs.site_name): config_path = ("/etc/nginx/sites-available/{0}" .format(self.app.pargs.site_name)) if os.path.isfile(config_path): if WOShellExec.cmd_exec(self, "grep \"error.log debug\" {0}" .format(config_path)): Log.info(self, "Stoping NGINX debug connection for {0}" .format(self.app.pargs.site_name)) WOShellExec.cmd_exec(self, "sed -i \"s/error.log debug;/" "error.log;/\" {0}" .format(config_path)) self.trigger_nginx = True else: Log.info(self, "Nginx debug for site already disabled") else: Log.info(self, "{0} domain not valid" .format(self.app.pargs.site_name))
def debug_wp(self): """Start/Stop WordPress debug""" if (self.app.pargs.wp == 'on' and self.app.pargs.site_name): wp_config = ("{0}/{1}/wp-config.php" .format(WOVar.wo_webroot, self.app.pargs.site_name)) webroot = "{0}{1}".format(WOVar.wo_webroot, self.app.pargs.site_name) # Check wp-config.php file into htdocs folder if not os.path.isfile(wp_config): wp_config = ("{0}/{1}/htdocs/wp-config.php" .format(WOVar.wo_webroot, self.app.pargs.site_name)) if os.path.isfile(wp_config): if not WOShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} |" " grep true".format(wp_config)): Log.info(self, "Starting WordPress debug") 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)) WOShellExec.cmd_exec(self, "sed -i \"s/define(\'WP_DEBUG\'" ".*/define(\'WP_DEBUG\', true);\\n" "define(\'WP_DEBUG_DISPLAY\', false);" "\\ndefine(\'WP_DEBUG_LOG\', true);" "\\ndefine(\'SAVEQUERIES\', true);/\"" " {0}".format(wp_config)) WOShellExec.cmd_exec(self, "cd {0}/htdocs/ && wp" " plugin --allow-root install " "developer query-monitor" .format(webroot)) WOShellExec.cmd_exec(self, "chown -R {1}: {0}/htdocs/" "wp-content/plugins" .format(webroot, WOVar.wo_php_user)) self.msg = self.msg + ['{0}{1}/htdocs/wp-content' '/debug.log' .format(WOVar.wo_webroot, self.app.pargs.site_name)] else: Log.info(self, "Unable to find wp-config.php for site: {0}" .format(self.app.pargs.site_name)) elif (self.app.pargs.wp == 'off' and self.app.pargs.site_name): wp_config = ("{0}{1}/wp-config.php" .format(WOVar.wo_webroot, self.app.pargs.site_name)) webroot = "{0}{1}".format(WOVar.wo_webroot, self.app.pargs.site_name) # Check wp-config.php file into htdocs folder if not os.path.isfile(wp_config): wp_config = ("{0}/{1}/htdocs/wp-config.php" .format(WOVar.wo_webroot, self.app.pargs.site_name)) if os.path.isfile(wp_config): if WOShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} | " "grep true".format(wp_config)): Log.info(self, "Disabling WordPress debug") WOShellExec.cmd_exec(self, "sed -i \"s/define(\'WP_DEBUG\'" ", true);/define(\'WP_DEBUG\', " "false);/\" {0}".format(wp_config)) WOShellExec.cmd_exec(self, "sed -i \"/define(\'" "WP_DEBUG_DISPLAY\', false);/d\" {0}" .format(wp_config)) WOShellExec.cmd_exec(self, "sed -i \"/define(\'" "WP_DEBUG_LOG\', true);/d\" {0}" .format(wp_config)) WOShellExec.cmd_exec(self, "sed -i \"/define(\'" "SAVEQUERIES\', " "true);/d\" {0}".format(wp_config)) else: Log.info(self, "WordPress debug all already disabled") else: Log.error(self, "Missing argument site name")
def debug_rewrite(self): """Start/Stop Nginx rewrite rules debug""" # Start Nginx rewrite debug globally if (self.app.pargs.rewrite == 'on' and not self.app.pargs.site_name): if not WOShellExec.cmd_exec(self, "grep \"rewrite_log on;\" " "/etc/nginx/nginx.conf"): Log.info(self, "Setting up Nginx rewrite logs") WOShellExec.cmd_exec(self, "sed -i \'/http {/a \\\\t" "rewrite_log on;\' /etc/nginx/nginx.conf") self.trigger_nginx = True else: Log.info(self, "Nginx rewrite logs already enabled") if '/var/log/nginx/*.error.log' not in self.msg: self.msg = self.msg + ['/var/log/nginx/*.error.log'] # Stop Nginx rewrite debug globally elif (self.app.pargs.rewrite == 'off' and not self.app.pargs.site_name): if WOShellExec.cmd_exec(self, "grep \"rewrite_log on;\" " "/etc/nginx/nginx.conf"): Log.info(self, "Disabling Nginx rewrite logs") WOShellExec.cmd_exec(self, "sed -i \"/rewrite_log.*/d\"" " /etc/nginx/nginx.conf") self.trigger_nginx = True else: Log.info(self, "Nginx rewrite logs already disabled") # Start Nginx rewrite for site elif (self.app.pargs.rewrite == 'on' and self.app.pargs.site_name): config_path = ("/etc/nginx/sites-available/{0}" .format(self.app.pargs.site_name)) if not WOShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" .format(config_path)): Log.info(self, "Setting up Nginx rewrite logs for {0}" .format(self.app.pargs.site_name)) WOShellExec.cmd_exec(self, "sed -i \"/access_log/i \\\\\\t" "rewrite_log on;\" {0}" .format(config_path)) self.trigger_nginx = True else: Log.info(self, "Nginx rewrite logs for {0} already setup" .format(self.app.pargs.site_name)) if ('{0}{1}/logs/error.log'.format(WOVar.wo_webroot, self.app.pargs.site_name) not in self.msg): self.msg = self.msg + ['{0}{1}/logs/error.log' .format(WOVar.wo_webroot, self.app.pargs.site_name)] # Stop Nginx rewrite for site elif (self.app.pargs.rewrite == 'off' and self.app.pargs.site_name): config_path = ("/etc/nginx/sites-available/{0}" .format(self.app.pargs.site_name)) if WOShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" .format(config_path)): Log.info(self, "Disabling Nginx rewrite logs for {0}" .format(self.app.pargs.site_name)) WOShellExec.cmd_exec(self, "sed -i \"/rewrite_log.*/d\" {0}" .format(config_path)) self.trigger_nginx = True else: Log.info(self, "Nginx rewrite logs for {0} already " " disabled".format(self.app.pargs.site_name))
def debug_fpm73(self): """Start/Stop PHP5-FPM debug""" # PHP5-FPM start global debug if (self.app.pargs.fpm73 == 'on' and not self.app.pargs.site_name): if not WOShellExec.cmd_exec(self, "grep \"log_level = debug\" " "/etc/php/7.3/fpm/php-fpm.conf"): Log.info(self, "Setting up PHP7.3-FPM log_level = debug") config = configparser.ConfigParser() config.read('/etc/php/7.3/fpm/php-fpm.conf') config.remove_option('global', 'include') config['global']['log_level'] = 'debug' config['global']['include'] = '/etc/php/7.3/fpm/pool.d/*.conf' with open('/etc/php/7.3/fpm/php-fpm.conf', encoding='utf-8', mode='w') as configfile: Log.debug(self, "Writing the PHP configuration into " "/etc/php/7.3/fpm/php-fpm.conf") config.write(configfile) self.trigger_php = True else: Log.info(self, "PHP7.3-FPM log_level = debug already setup") self.msg = self.msg + ['/var/log/php/7.3/fpm.log'] # PHP5-FPM stop global debug elif (self.app.pargs.fpm73 == 'off' and not self.app.pargs.site_name): if WOShellExec.cmd_exec(self, "grep \"log_level = debug\" " "/etc/php/7.3/fpm/php-fpm.conf"): Log.info(self, "Disabling PHP7.3-FPM log_level = debug") config = configparser.ConfigParser() config.read('/etc/php/7.3/fpm/php-fpm.conf') config.remove_option('global', 'include') config['global']['log_level'] = 'notice' config['global']['include'] = '/etc/php/7.3/fpm/pool.d/*.conf' with open('/etc/php/7.3/fpm/php-fpm.conf', encoding='utf-8', mode='w') as configfile: Log.debug(self, "Writing the php7.3 configuration into " "/etc/php/7.3/fpm/php-fpm.conf") config.write(configfile) self.trigger_php = True else: Log.info(self, "PHP7.3-FPM log_level " "= debug already disabled")
def debug_php73(self): """Start/Stop PHP debug""" # PHP global debug start if (self.app.pargs.php73 == 'on' and not self.app.pargs.site_name): if not (WOShellExec.cmd_exec(self, "sed -n \"/upstream php73" "{/,/}/p \" /etc/nginx/" "conf.d/upstream.conf " "| grep 9173")): Log.info(self, "Enabling PHP 7.3 debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([('upstream', 'php73',), 'server'], '127.0.0.1:9173') nc.savef('/etc/nginx/conf.d/upstream.conf') # Enable xdebug WOFileUtils.searchreplace(self, "/etc/php/7.3/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.3/fpm/pool.d/debug.conf') config['debug']['slowlog'] = '/var/log/php/7.3/slow.log' config['debug']['request_slowlog_timeout'] = '10s' with open('/etc/php/7.3/fpm/pool.d/debug.conf', encoding='utf-8', mode='w') as confifile: Log.debug(self, "Writting debug.conf configuration into " "/etc/php/7.3/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.3/slow.log'] # PHP global debug stop elif (self.app.pargs.php73 == 'off' and not self.app.pargs.site_name): if WOShellExec.cmd_exec(self, " sed -n \"/upstream " "php73 {/,/}/p\" " "/etc/nginx/conf.d/upstream.conf " "| grep 9173"): Log.info(self, "Disabling PHP 7.3 debug") # Change upstream.conf nc = NginxConfig() nc.loadf('/etc/nginx/conf.d/upstream.conf') nc.set([('upstream', 'php73',), 'server'], 'unix:/var/run/php/php73-fpm.sock') nc.savef('/etc/nginx/conf.d/upstream.conf') # Disable xdebug WOFileUtils.searchreplace(self, "/etc/php/7.3/mods-available/" "xdebug.ini", "zend_extension", ";zend_extension") self.trigger_php = True self.trigger_nginx = True else: Log.info(self, "PHP 7.3 debug is already disabled")
def default(self, disp_msg=False): # All package update apt_packages = [] packages = [] self.msg = [] pargs = self.app.pargs wo_phpmyadmin = WODownload.pma_release(self) if not (pargs.web or pargs.nginx or pargs.php or pargs.php72 or pargs.php73 or pargs.php74 or pargs.mysql or pargs.mariadb or pargs.ngxblocker or pargs.all or pargs.netdata or pargs.wpcli or pargs.composer or pargs.phpmyadmin or pargs.adminer or pargs.dashboard or pargs.mysqltuner or pargs.redis or pargs.fail2ban or pargs.security): pargs.web = True pargs.admin = True pargs.security = True if pargs.mariadb: pargs.mysql = True if pargs.php: pargs.php72 = True if pargs.all: pargs.web = True pargs.admin = True pargs.security = True pargs.redis = True if pargs.web: pargs.nginx = True pargs.php72 = True pargs.php73 = True pargs.php74 = True pargs.mysql = True pargs.wpcli = True if pargs.admin: pargs.netdata = True pargs.composer = True pargs.dashboard = True pargs.phpmyadmin = True pargs.wpcli = True pargs.adminer = True pargs.mysqltuner = True if pargs.security: pargs.ngxblocker = True pargs.fail2ban = True # nginx if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): apt_packages = apt_packages + WOVar.wo_nginx else: if os.path.isfile('/usr/sbin/nginx'): Log.info(self, "Updating Nginx templates") post_pref(self, WOVar.wo_nginx, []) else: Log.info(self, "Nginx Stable is not already installed") # php 7.2 if pargs.php72: if WOAptGet.is_installed(self, 'php7.2-fpm'): apt_packages = apt_packages + WOVar.wo_php72 + \ WOVar.wo_php_extra # php 7.3 if pargs.php73: if WOAptGet.is_installed(self, 'php7.3-fpm'): apt_packages = apt_packages + WOVar.wo_php73 + \ WOVar.wo_php_extra # php 7.4 if pargs.php74: if WOAptGet.is_installed(self, 'php7.4-fpm'): apt_packages = apt_packages + WOVar.wo_php74 + \ WOVar.wo_php_extra # mysql if pargs.mysql: if WOShellExec.cmd_exec(self, 'mysqladmin ping'): apt_packages = apt_packages + ['mariadb-server'] # redis if pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): apt_packages = apt_packages + ['redis-server'] # fail2ban if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): apt_packages = apt_packages + ['fail2ban'] # wp-cli if pargs.wpcli: if os.path.isfile('/usr/local/bin/wp'): packages = packages + [[ "https://github.com/wp-cli/wp-cli/" "releases/download/v{0}/" "wp-cli-{0}.phar".format(WOVar.wo_wp_cli), "/usr/local/bin/wp", "WP-CLI" ]] else: Log.info(self, "WPCLI is not installed with WordOps") # netdata if pargs.netdata: # detect static binaries install if os.path.isdir('/opt/netdata'): packages = packages + [[ 'https://my-netdata.io/kickstart-static64.sh', '/var/lib/wo/tmp/kickstart.sh', 'Netdata' ]] # detect install from source elif os.path.isdir('/etc/netdata'): packages = packages + [[ 'https://my-netdata.io/kickstart.sh', '/var/lib/wo/tmp/kickstart.sh', 'Netdata' ]] else: Log.info(self, 'Netdata is not installed') # wordops dashboard if pargs.dashboard: if (os.path.isfile('/var/www/22222/htdocs/index.php') or os.path.isfile('/var/www/22222/htdocs/index.html')): packages = packages + [[ "https://github.com/WordOps/wordops-dashboard/" "releases/download/v{0}/wordops-dashboard.tar.gz".format( WOVar.wo_dashboard), "/var/lib/wo/tmp/wo-dashboard.tar.gz", "WordOps Dashboard" ]] else: Log.info(self, 'WordOps dashboard is not installed') # phpmyadmin if pargs.phpmyadmin: if os.path.isdir('/var/www/22222/htdocs/db/pma'): packages = packages + [[ "https://files.phpmyadmin.net" "/phpMyAdmin/{0}/phpMyAdmin-{0}-" "all-languages.tar.gz".format(wo_phpmyadmin), "/var/lib/wo/tmp/pma.tar.gz", "PHPMyAdmin" ]] else: Log.info(self, "phpMyAdmin isn't installed") # adminer if pargs.adminer: if os.path.isfile("{0}22222/htdocs/db/" "adminer/index.php".format(WOVar.wo_webroot)): Log.debug(self, "Setting packages variable for Adminer ") packages = packages + [ [ "https://www.adminer.org/latest.php", "{0}22222/" "htdocs/db/adminer/index.php".format(WOVar.wo_webroot), "Adminer" ], [ "https://raw.githubusercontent.com" "/vrana/adminer/master/designs/" "pepa-linha/adminer.css", "{0}22222/" "htdocs/db/adminer/adminer.css".format( WOVar.wo_webroot), "Adminer theme" ] ] else: Log.debug(self, "Adminer isn't installed") Log.info(self, "Adminer isn't installed") # composer if pargs.composer: if os.path.isfile('/usr/local/bin/composer'): packages = packages + [[ "https://getcomposer.org/installer", "/var/lib/wo/tmp/composer-install", "Composer" ]] else: Log.info(self, "Composer isn't installed") # mysqltuner if pargs.mysqltuner: if WOAptGet.is_exec(self, 'mysqltuner'): Log.debug(self, "Setting packages variable " "for MySQLTuner ") packages = packages + [[ "https://raw." "githubusercontent.com/" "major/MySQLTuner-perl" "/master/mysqltuner.pl", "/usr/bin/mysqltuner", "MySQLTuner" ]] # ngxblocker if pargs.ngxblocker: if os.path.exists('/usr/local/sbin/install-ngxblocker'): packages = packages + [[ 'https://raw.githubusercontent.com/mitchellkrogza/' 'nginx-ultimate-bad-bot-blocker/master/update-ngxblocker', '/usr/local/sbin/update-ngxblocker', 'ngxblocker' ]] if ((not (apt_packages)) and (not (packages))): self.app.args.print_help() else: pre_stack(self) if (apt_packages): if not ("php7.2-fpm" in apt_packages or "php7.3-fpm" in apt_packages or "php7.4-fpm" in apt_packages or "redis-server" in apt_packages or "nginx-custom" in apt_packages or "mariadb-server" in apt_packages): pass else: Log.warn( self, "Your sites may be down for few seconds if " "you are upgrading Nginx, PHP-FPM, MariaDB or Redis") # Check prompt if not (pargs.no_prompt or pargs.force): 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") # additional pre_pref if "nginx-custom" in apt_packages: pre_pref(self, WOVar.wo_nginx) Log.wait(self, "Updating APT cache") # apt-get update WOAptGet.update(self) Log.valide(self, "Updating APT cache") # check if nginx upgrade is blocked if os.path.isfile('/etc/apt/preferences.d/nginx-block'): post_pref(self, WOVar.wo_nginx, [], True) # redis pre_pref if "redis-server" in apt_packages: pre_pref(self, WOVar.wo_redis) # upgrade packages WOAptGet.install(self, apt_packages) Log.wait(self, "Configuring APT Packages") post_pref(self, apt_packages, [], True) Log.valide(self, "Configuring APT Packages") # Post Actions after package updates if (packages): if WOAptGet.is_selected(self, 'WP-CLI', packages): WOFileUtils.rm(self, '/usr/local/bin/wp') if WOAptGet.is_selected(self, 'Netdata', packages): WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh') if WOAptGet.is_selected(self, 'ngxblocker', packages): WOFileUtils.rm(self, '/usr/local/sbin/update-ngxblocker') if WOAptGet.is_selected(self, 'WordOps Dashboard', packages): if os.path.isfile('/var/www/22222/htdocs/index.php'): WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php') if os.path.isfile('/var/www/22222/htdocs/index.html'): WOFileUtils.rm(self, '/var/www/22222/htdocs/index.html') Log.debug(self, "Downloading following: {0}".format(packages)) WODownload.download(self, packages) if WOAptGet.is_selected(self, 'WP-CLI', packages): WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775) if WOAptGet.is_selected(self, 'ngxblocker', packages): if os.path.exists('/etc/nginx/conf.d/variables-hash.conf'): WOFileUtils.rm( self, '/etc/nginx/conf.d/variables-hash.conf') WOFileUtils.chmod(self, '/usr/local/sbin/update-ngxblocker', 0o775) WOShellExec.cmd_exec( self, '/usr/local/sbin/update-ngxblocker -nq') if WOAptGet.is_selected(self, 'MySQLTuner', packages): WOFileUtils.chmod(self, "/usr/bin/mysqltuner", 0o775) if os.path.exists('/usr/local/bin/mysqltuner'): WOFileUtils.rm(self, '/usr/local/bin/mysqltuner') # Netdata if WOAptGet.is_selected(self, 'Netdata', packages): WOService.stop_service(self, 'netdata') Log.wait(self, "Upgrading Netdata") # detect static binaries install WOShellExec.cmd_exec(self, "bash /var/lib/wo/tmp/kickstart.sh " "--dont-wait --no-updates", errormsg='', log=False) Log.valide(self, "Upgrading Netdata") if WOAptGet.is_selected(self, 'WordOps Dashboard', packages): post_pref(self, [], [[ "https://github.com/WordOps" "/wordops-dashboard/" "releases/download/v{0}/" "wordops-dashboard.tar.gz".format(WOVar.wo_dashboard), "/var/lib/wo/tmp/wo-dashboard.tar.gz", "WordOps Dashboard" ]]) if WOAptGet.is_selected(self, 'Composer', packages): Log.wait(self, "Upgrading Composer") if WOShellExec.cmd_exec(self, '/usr/bin/php -v'): WOShellExec.cmd_exec( self, "php -q /var/lib/wo" "/tmp/composer-install " "--install-dir=/var/lib/wo/tmp/") shutil.copyfile('/var/lib/wo/tmp/composer.phar', '/usr/local/bin/composer') WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775) Log.valide(self, "Upgrading Composer ") if WOAptGet.is_selected(self, 'PHPMyAdmin', packages): Log.wait(self, "Upgrading phpMyAdmin") WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz', '/var/lib/wo/tmp/') shutil.copyfile( ('{0}22222/htdocs/db/pma' '/config.inc.php'.format(WOVar.wo_webroot)), ('/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/config.inc.php'.format(wo_phpmyadmin) )) WOFileUtils.rm( self, '{0}22222/htdocs/db/pma'.format(WOVar.wo_webroot)) shutil.move( '/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/'.format(wo_phpmyadmin), '{0}22222/htdocs/db/pma/'.format(WOVar.wo_webroot)) WOFileUtils.chown(self, "{0}22222/htdocs".format( WOVar.wo_webroot), 'www-data', 'www-data', recursive=True) Log.valide(self, "Upgrading phpMyAdmin") if os.path.exists('{0}22222/htdocs'.format(WOVar.wo_webroot)): WOFileUtils.chown(self, "{0}22222/htdocs".format( WOVar.wo_webroot), 'www-data', 'www-data', recursive=True) Log.info(self, "Successfully updated packages")
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 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") 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 WOMysql.backupAll(self) # Add MariaDB repo Log.info(self, "Adding repository for MariaDB, please wait...") mysql_pref = ("Package: *\nPin: origin sfo1.mirrors.digitalocean.com" "\nPin-Priority: 1000\n") with open('/etc/apt/preferences.d/' 'MariaDB.pref', 'w') as mysql_pref_file: mysql_pref_file.write(mysql_pref) WORepo.add(self, repo_url=WOVariables.wo_mysql_repo) Log.debug(self, 'Adding key for {0}' .format(WOVariables.wo_mysql_repo)) WORepo.add_key(self, '0xcbcb082a1bb943db', keyserver="keyserver.ubuntu.com") config = configparser.ConfigParser() if os.path.exists('/etc/mysql/conf.d/my.cnf'): config.read('/etc/mysql/conf.d/my.cnf') else: 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.3 " "mysql-server/root_password " "password \" | " "debconf-set-selections") WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.3 " "mysql-server/root_password " "password {chars}\" | " "debconf-set-selections" .format(chars=chars), log=False) Log.debug(self, "echo \"mariadb-server-10.3 " "mysql-server/root_password_again " "password \" | " "debconf-set-selections") WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.3 " "mysql-server/root_password_again " "password {chars}\" | " "debconf-set-selections" .format(chars=chars), log=False) # Install MariaDB apt_packages = WOVariables.wo_mysql # If PHP is installed then install php7.2-mysql if WOAptGet.is_installed(self, "php7.2-fpm"): apt_packages = apt_packages + ["php7.2-mysql"] Log.info(self, "Updating apt-cache, hang on...") WOAptGet.update(self) Log.info(self, "Installing MariaDB, hang on...") WOAptGet.remove(self, ["mysql-common", "libmysqlclient18"]) WOAptGet.auto_remove(self) WOAptGet.install(self, apt_packages)
def deploycert(self, wo_domain_name): """Deploy Let's Encrypt certificates with acme.sh""" # check acme.sh is installed WOAcme.check_acme(self) if not os.path.isfile('/etc/letsencrypt/renewal/{0}_ecc/fullchain.cer' .format(wo_domain_name)): Log.error(self, 'Certificate not found. Deployment canceled') Log.debug(self, "Cert deployment for domain: {0}" .format(wo_domain_name)) try: Log.wait(self, "Deploying SSL cert") if WOShellExec.cmd_exec( self, "mkdir -p {0}/{1} && {2} --install-cert -d {1} --ecc " "--cert-file {0}/{1}/cert.pem --key-file {0}/{1}/key.pem " "--fullchain-file {0}/{1}/fullchain.pem " "--ca-file {0}/{1}/ca.pem --reloadcmd \"nginx -t && " "service nginx restart\" " .format(WOVar.wo_ssl_live, wo_domain_name, WOAcme.wo_acme_exec)): Log.valide(self, "Deploying SSL cert") else: Log.failed(self, "Deploying SSL cert") Log.error(self, "Unable to deploy certificate") if os.path.isdir('/var/www/{0}/conf/nginx' .format(wo_domain_name)): sslconf = open("/var/www/{0}/conf/nginx/ssl.conf" .format(wo_domain_name), encoding='utf-8', mode='w') sslconf.write( "listen 443 ssl http2;\n" "listen [::]:443 ssl http2;\n" "ssl_certificate {0}/{1}/fullchain.pem;\n" "ssl_certificate_key {0}/{1}/key.pem;\n" "ssl_trusted_certificate {0}/{1}/ca.pem;\n" "ssl_stapling_verify on;\n" .format(WOVar.wo_ssl_live, wo_domain_name)) sslconf.close() if not WOFileUtils.grep(self, '/var/www/22222/conf/nginx/ssl.conf', '/etc/letsencrypt'): Log.info(self, "Securing WordOps backend with current cert") sslconf = open("/var/www/22222/conf/nginx/ssl.conf", encoding='utf-8', mode='w') sslconf.write("ssl_certificate {0}/{1}/fullchain.pem;\n" "ssl_certificate_key {0}/{1}/key.pem;\n" "ssl_trusted_certificate {0}/{1}/ca.pem;\n" "ssl_stapling_verify on;\n" .format(WOVar.wo_ssl_live, wo_domain_name)) sslconf.close() WOGit.add(self, ["/etc/letsencrypt"], msg="Adding letsencrypt folder") except IOError as e: Log.debug(self, str(e)) Log.debug(self, "Error occured while generating " "ssl.conf") return 0
def backupAll(self): import subprocess try: Log.info(self, "Backing up database at location: " "/var/wo-mysqlbackup") # Setup Nginx common directory if not os.path.exists('/var/wo-mysqlbackup'): Log.debug(self, 'Creating directory' '/var/wo-mysqlbackup') os.makedirs('/var/wo-mysqlbackup') db = subprocess.check_output( ["/usr/bin/mysql " "-Bse \'show databases\'"], universal_newlines=True, shell=True).split('\n') for dbs in db: if dbs == "": continue Log.info(self, "Backing up {0} database".format(dbs)) p1 = subprocess.Popen("/usr/bin/mysqldump {0}" " --max_allowed_packet=1024M" " --single-transaction".format(dbs), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) p2 = subprocess.Popen( "/usr/bin/pigz -c > " "/var/wo-mysqlbackup/{0}{1}.sql.gz".format( dbs, WOVariables.wo_date), stdin=p1.stdout, shell=True) # Allow p1 to receive a SIGPIPE if p2 exits p1.stdout.close() output = p1.stderr.read() p1.wait() if p1.returncode == 0: Log.debug(self, "done") else: Log.error(self, output.decode("utf-8")) except Exception as e: Log.error(self, "Error: process exited with status %s" % e)
def clean_fastcgi(self): if (os.path.isdir("/var/run/nginx-cache")): Log.info(self, "Cleaning NGINX FastCGI cache") WOShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*") else: Log.error(self, "Unable to clean FastCGI cache", False)
def default(self): Log.info( self, "This command is deprecated." " You can use this command instead, " + Log.ENDC + Log.BOLD + "\n`wo debug --import-slow-log`" + Log.ENDC)
def default(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, 'Unable to read input, Please try again') pargs.site_name = pargs.site_name.strip() wo_domain = WODomain.validate(self, pargs.site_name) 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)): try: WOShellExec.invoke_editor(self, '/etc/nginx/sites-availa' 'ble/{0}'.format(wo_domain)) except CommandExecutionError as e: Log.debug(self, str(e)) Log.error(self, "Failed invoke editor") if (WOGit.checkfilestatus(self, "/etc/nginx", '/etc/nginx/sites-available/{0}' .format(wo_domain))): WOGit.add(self, ["/etc/nginx"], msg="Edit website: {0}" .format(wo_domain)) # Reload NGINX 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 exists")
def add(self, paths, msg="Intializating"): """ Initializes Directory as repository if not already git repo. and adds uncommited changes automatically """ for path in paths: global git git = git.bake("--git-dir={0}/.git".format(path), "--work-tree={0}".format(path)) if os.path.isdir(path): if not os.path.isdir(path + "/.git"): try: Log.debug(self, "WOGit: git init at {0}" .format(path)) git.init(path) except ErrorReturnCode as e: Log.debug(self, "{0}".format(e)) Log.error(self, "Unable to git init at {0}" .format(path)) status = git.status("-s") if len(status.splitlines()) > 0: try: Log.debug(self, "WOGit: git commit at {0}" .format(path)) git.add("--all") git.commit("-am {0}".format(msg)) except ErrorReturnCode as e: Log.debug(self, "{0}".format(e)) Log.error(self, "Unable to git commit at {0} " .format(path)) else: Log.debug(self, "WOGit: Path {0} not present".format(path))
def disable(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() 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, "Disable domain {0:10} \t" .format(wo_domain), end='') if not os.path.isfile('/etc/nginx/sites-enabled/{0}' .format(wo_domain)): Log.debug(self, "Site {0} already disabled".format(wo_domain)) Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE + "]") else: WOFileUtils.remove_symlink(self, '/etc/nginx/sites-enabled/{0}' .format(wo_domain)) WOGit.add(self, ["/etc/nginx"], msg="Disabled {0} " .format(wo_domain)) updateSiteInfo(self, wo_domain, enabled=False) 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 clean_opcache(self): if (os.path.exists('/usr/sbin/nginx') and os.path.exists( '/var/www/22222/htdocs/cache/opcache/php72.php')): try: Log.info(self, "Cleaning opcache") opgui = requests.get( "http://127.0.0.1/cache/opcache/php72.php") if opgui.status_code != '200' or opgui.status_code != '302': Log.warn(self, 'Cleaning opcache failed') except Exception as e: Log.debug(self, "{0}".format(e)) Log.debug( self, "Unable hit url, " " http://127.0.0.1/cache/opcache/" "php72.php," " please check you have admin tools installed") Log.debug( self, "please check you have admin tools installed," " or install them with `wo stack install --admin`") Log.error(self, "Unable to clean opcache", False)
def default(self, disp_msg=False): # All package update apt_packages = [] packages = [] self.msg = [] pargs = self.app.pargs if ((not pargs.web) and (not pargs.nginx) and (not pargs.php) and (not pargs.php73) and (not pargs.mysql) and (not pargs.all) and (not pargs.wpcli) and (not pargs.netdata) and (not pargs.composer) and (not pargs.phpmyadmin) and (not pargs.dashboard) and (not pargs.redis)): pargs.web = True if pargs.all: pargs.web = True pargs.netdata = True pargs.composer = True pargs.dashboard = True pargs.phpmyadmin = True pargs.redis = True pargs.wpcli = True pargs.php73 = True if pargs.web: if WOAptGet.is_installed(self, 'nginx-custom'): pargs.nginx = True pargs.php = True pargs.mysql = True pargs.wpcli = True if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): apt_packages = apt_packages + WOVar.wo_nginx else: if os.path.isfile('/usr/sbin/nginx'): Log.info(self, "Updating Nginx templates") post_pref(self, WOVar.wo_nginx, []) else: Log.info(self, "Nginx Stable is not already installed") if pargs.php: if WOAptGet.is_installed(self, 'php7.2-fpm'): apt_packages = apt_packages + WOVar.wo_php + \ WOVar.wo_php_extra else: Log.info(self, "PHP 7.2 is not installed") if pargs.php73: if WOAptGet.is_installed(self, 'php7.3-fpm'): apt_packages = apt_packages + WOVar.wo_php73 + \ WOVar.wo_php_extra else: Log.info(self, "PHP 7.3 is not installed") if pargs.mysql: if WOShellExec.cmd_exec(self, 'mysqladmin ping'): apt_packages = apt_packages + ['mariadb-server'] else: Log.info(self, "MariaDB is not installed") if pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): apt_packages = apt_packages + ['redis-server'] else: Log.info(self, "Redis is not installed") if pargs.wpcli: if os.path.isfile('/usr/local/bin/wp'): packages = packages + [[ "https://github.com/wp-cli/wp-cli/" "releases/download/v{0}/" "wp-cli-{0}.phar" "".format(WOVar.wo_wp_cli), "/usr/local/bin/wp", "WP-CLI" ]] else: Log.info(self, "WPCLI is not installed with WordOps") if pargs.netdata: if (os.path.isdir('/opt/netdata') or os.path.isdir('/etc/netdata')): packages = packages + [[ 'https://my-netdata.io/' 'kickstart-static64.sh', '/var/lib/wo/tmp/kickstart.sh', 'Netdata' ]] if pargs.dashboard: if (os.path.isfile('/var/www/22222/htdocs/index.php') or os.path.isfile('/var/www/22222/htdocs/index.html')): packages = packages + \ [["https://github.com/WordOps/wordops-dashboard/" "releases/download/v{0}/wordops-dashboard.tar.gz" .format(WOVar.wo_dashboard), "/var/lib/wo/tmp/wo-dashboard.tar.gz", "WordOps Dashboard"]] if pargs.phpmyadmin: if os.path.isdir('/var/www/22222/htdocs/db/pma'): packages = packages + \ [["https://files.phpmyadmin.net" "/phpMyAdmin/{0}/" "phpMyAdmin-{0}-" "all-languages" ".tar.gz".format(WOVar.wo_phpmyadmin), "/var/lib/wo/tmp/pma.tar.gz", "PHPMyAdmin"]] else: Log.info(self, "phpMyAdmin isn't installed") if pargs.composer: if os.path.isfile('/usr/local/bin/composer'): packages = packages + [[ "https://getcomposer.org/installer", "/var/lib/wo/tmp/composer-install", "Composer" ]] else: Log.info(self, "Composer isn't installed") if ((not (apt_packages)) and (not (packages))): self.app.args.print_help() else: if (apt_packages): if (("php7.2-fpm" not in apt_packages) and ("php7.3-fpm" not in apt_packages) and ("nginx-custom" not in apt_packages) and ("mariadb-server" not in apt_packages)): pass else: Log.info( self, "Your sites may be down for few seconds if " "you are upgrading Nginx, PHP-FPM, MariaDB or Redis") # Check prompt if ((not pargs.no_prompt) and (not pargs.force)): 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.wait(self, "Updating APT packages") # apt-get update WOAptGet.update(self) Log.valide(self, "Updating APT packages") Log.wait(self, "Upgrading APT Packages") # additional pre_pref if ["nginx-custom"] in apt_packages: pre_pref(self, WOVar.wo_nginx) if ["php7.2-fpm"] in apt_packages: WOAptGet.remove(self, ['php7.2-fpm'], auto=False, purge=True) if ["php7.3-fpm"] in apt_packages: WOAptGet.remove(self, ['php7.3-fpm'], auto=False, purge=True) # check if nginx upgrade is blocked if os.path.isfile('/etc/apt/preferences.d/nginx-block'): post_pref(self, WOVar.wo_nginx, [], True) # upgrade packages WOAptGet.install(self, apt_packages) Log.valide(self, "Upgrading APT Packages") Log.wait(self, "Configuring APT Packages") post_pref(self, apt_packages, [], True) Log.valide(self, "Configuring APT Packages") # Post Actions after package updates if (packages): if pargs.wpcli: WOFileUtils.rm(self, '/usr/local/bin/wp') if pargs.netdata: WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh') if pargs.dashboard: if os.path.isfile('/var/www/22222/htdocs/index.php'): WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php') if os.path.isfile('/var/www/22222/htdocs/index.html'): WOFileUtils.rm(self, '/var/www/22222/htdocs/index.html') Log.debug(self, "Downloading following: {0}".format(packages)) WODownload.download(self, packages) if pargs.wpcli: WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775) if pargs.netdata: Log.wait(self, "Upgrading Netdata") if os.path.isdir('/opt/netdata'): WOShellExec.cmd_exec( self, "bash /opt/netdata/usr/" "libexec/netdata/netdata-" "updater.sh") elif os.path.isdir('/etc/netdata'): WOShellExec.cmd_exec( self, "bash /usr/" "libexec/netdata/netdata-" "updater.sh") Log.valide(self, "Upgrading Netdata") if pargs.dashboard: post_pref(self, [], [[ "https://github.com/WordOps" "/wordops-dashboard/" "releases/download/v{0}/" "wordops-dashboard.tar.gz".format(WOVar.wo_dashboard), "/var/lib/wo/tmp/wo-dashboard.tar.gz", "WordOps Dashboard" ]]) if pargs.composer: Log.wait(self, "Upgrading Composer") WOShellExec.cmd_exec( self, "php -q /var/lib/wo" "/tmp/composer-install " "--install-dir=/var/lib/wo/tmp/") shutil.copyfile('/var/lib/wo/tmp/composer.phar', '/usr/local/bin/composer') WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775) Log.valide(self, "Upgrading Composer ") if pargs.phpmyadmin: Log.wait(self, "Upgrading phpMyAdmin") WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz', '/var/lib/wo/tmp/') shutil.copyfile( ('{0}22222/htdocs/db/pma' '/config.inc.php'.format(WOVar.wo_webroot)), ('/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/config.inc.php'.format( WOVar.wo_phpmyadmin))) WOFileUtils.rm( self, '{0}22222/htdocs/db/pma'.format(WOVar.wo_webroot)) shutil.move( '/var/lib/wo/tmp/phpMyAdmin-{0}' '-all-languages/'.format(WOVar.wo_phpmyadmin), '{0}22222/htdocs/db/pma/'.format(WOVar.wo_webroot)) WOFileUtils.chown(self, "{0}22222/htdocs".format( WOVar.wo_webroot), 'www-data', 'www-data', recursive=True) Log.valide(self, "Upgrading phpMyAdmin") Log.info(self, "Successfully updated packages")
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/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") 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 purge(self): """Start purging of packages""" apt_packages = [] packages = [] pargs = self.app.pargs # Default action for stack purge if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx) and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli) and (not pargs.phpmyadmin) and (not pargs.composer) and (not pargs.netdata) and (not pargs.dashboard) and (not pargs.fail2ban) and (not pargs.security) and (not pargs.mysqlclient) and (not pargs.mysqltuner) and (not pargs.adminer) and (not pargs.utils) and (not pargs.redis) and (not pargs.proftpd) and (not pargs.extplorer) and (not pargs.cheat) and (not pargs.clamav) and (not pargs.phpredisadmin) and (not pargs.php73)): pargs.web = True pargs.admin = True pargs.security = True if pargs.all: pargs.web = True pargs.admin = True pargs.php73 = True pargs.fail2ban = True pargs.proftpd = True pargs.utils = True pargs.redis = True packages = packages + ['/var/www/22222/htdocs/*'] if pargs.web: pargs.nginx = True pargs.php = True pargs.mysql = True pargs.wpcli = True if pargs.admin: pargs.utils = True pargs.composer = True pargs.netdata = True pargs.mysqltuner = True pargs.cheat = True if pargs.security: pargs.fail2ban = True pargs.clamav = True # NGINX if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): Log.debug(self, "Purge apt_packages variable of Nginx") apt_packages = apt_packages + WOVariables.wo_nginx # PHP if pargs.php: Log.debug(self, "Purge apt_packages variable PHP") if WOAptGet.is_installed(self, 'php7.2-fpm'): if not (WOAptGet.is_installed(self, 'php7.3-fpm')): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php # PHP 7.3 if pargs.php73: Log.debug(self, "Removing apt_packages variable of PHP 7.3") if WOAptGet.is_installed(self, 'php7.3-fpm'): if not (WOAptGet.is_installed(self, 'php7.2-fpm')): apt_packages = apt_packages + WOVariables.wo_php73 + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php73 # REDIS if pargs.redis: Log.debug(self, "Remove apt_packages variable of Redis") apt_packages = apt_packages + WOVariables.wo_redis # MariaDB if pargs.mysql: Log.debug(self, "Removing apt_packages variable of MySQL") apt_packages = apt_packages + WOVariables.wo_mysql # mysqlclient if pargs.mysqlclient: Log.debug(self, "Removing apt_packages variable " "for MySQL Client") if WOShellExec.cmd_exec(self, "mysqladmin ping"): apt_packages = apt_packages + WOVariables.wo_mysql_client # fail2ban if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): Log.debug(self, "Remove apt_packages variable of Fail2ban") apt_packages = apt_packages + WOVariables.wo_fail2ban # ClamAV if pargs.clamav: Log.debug(self, "Setting apt_packages variable for ClamAV") if WOAptGet.is_installed(self, 'clamav'): apt_packages = apt_packages + ["clamav"] # proftpd if pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): Log.debug(self, "Purge apt_packages variable for ProFTPd") apt_packages = apt_packages + ["proftpd-basic"] # WP-CLI if pargs.wpcli: Log.debug(self, "Purge package variable WPCLI") if os.path.isfile('/usr/local/bin/wp'): packages = packages + ['/usr/local/bin/wp'] # PHPMYADMIN if pargs.phpmyadmin: packages = packages + [ '{0}22222/htdocs/db/pma'.format(WOVariables.wo_webroot) ] Log.debug(self, "Purge package variable phpMyAdmin") # Composer if pargs.composer: Log.debug(self, "Removing package variable of Composer ") if os.path.isfile('/usr/local/bin/composer'): packages = packages + ['/usr/local/bin/composer'] if pargs.mysqltuner: Log.debug(self, "Removing packages for MySQLTuner ") packages = packages + ['/usr/bin/mysqltuner'] # PHPREDISADMIN if pargs.phpredisadmin: Log.debug(self, "Removing package variable of phpRedisAdmin ") if os.path.isdir('{0}22222/htdocs/cache/redis'.format( WOVariables.wo_webroot)): packages = packages + [ '{0}22222/htdocs/' 'cache/redis'.format(WOVariables.wo_webroot) ] # Adminer if pargs.adminer: Log.debug(self, "Purge package variable Adminer") packages = packages + [ '{0}22222/htdocs/db/adminer'.format(WOVariables.wo_webroot) ] # utils if pargs.utils: Log.debug(self, "Purge package variable utils") packages = packages + [ '{0}22222/htdocs/php/webgrind/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/cache/opcache'.format( WOVariables.wo_webroot), '{0}22222/htdocs/cache/nginx/' 'clean.php'.format( WOVariables.wo_webroot), '/usr/bin/pt-query-advisor', '{0}22222/htdocs/db/anemometer'.format(WOVariables.wo_webroot) ] if pargs.netdata: Log.debug(self, "Removing Netdata") if os.path.isfile('/opt/netdata/usr/' 'libexec/netdata-uninstaller.sh'): packages = packages + ['/var/lib/wo/tmp/kickstart.sh'] if pargs.dashboard: Log.debug(self, "Removing Wo-Dashboard") packages = packages + [ '{0}22222/htdocs/assets/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/index.php'.format(WOVariables.wo_webroot) ] if (packages) or (apt_packages): if (not pargs.force): start_purge = input('Are you sure you to want to' ' purge stacks from this server ?' '\nPackage configuration and data ' 'will not remain' ' on this server after this operation.\n' 'Purge stacks [y/N]') if start_purge != "Y" and start_purge != "y": Log.error(self, "Not starting stack purge") if (set(["nginx-custom"]).issubset(set(apt_packages))): WOService.stop_service(self, 'nginx') if (set(["fail2ban"]).issubset(set(apt_packages))): WOService.stop_service(self, 'fail2ban') # Netdata uninstaller if (set(['/var/lib/wo/tmp/' 'kickstart.sh']).issubset(set(packages))): if WOVariables.wo_distro == 'Raspbian': WOShellExec.cmd_exec( self, "bash /usr/" "libexec/netdata-" "uninstaller.sh -y -f") else: WOShellExec.cmd_exec( self, "bash /opt/netdata/usr/" "libexec/netdata-" "uninstaller.sh -y -f") if (apt_packages): Log.info(self, "Purging apt packages, please wait...") WOAptGet.remove(self, apt_packages, purge=True) WOAptGet.auto_remove(self) if (packages): Log.info(self, "Purging packages, please wait...") WOFileUtils.remove(self, packages) WOAptGet.auto_remove(self) Log.info(self, "Successfully purged packages")
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 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") 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(WOVariables.wo_fqdn), "Hi,\n The requested logfiles are attached." "\n\nBest regards,\nYour WordOps worker", files=mail_list, port=25, isTls=False)
def sync(self): """ 1. reads database information from wp/wo-config.php 2. updates records into wo database accordingly. """ Log.info(self, "Synchronizing wo database, please wait...") sites = getAllsites(self) if not sites: pass for site in sites: if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: wo_site_webroot = site.site_path # Read config files configfiles = glob.glob(wo_site_webroot + '/*-config.php') # search for wp-config.php inside htdocs/ if not configfiles: Log.debug(self, "Config files not found in {0}/ " .format(wo_site_webroot)) if site.site_type != 'mysql': Log.debug(self, "Searching wp-config.php in {0}/htdocs/ " .format(wo_site_webroot)) configfiles = glob.glob( wo_site_webroot + '/htdocs/wp-config.php') if configfiles: if WOFileUtils.isexist(self, configfiles[0]): wo_db_name = (WOFileUtils.grep(self, configfiles[0], 'DB_NAME').split(',')[1] .split(')')[0].strip().replace('\'', '')) wo_db_user = (WOFileUtils.grep(self, configfiles[0], 'DB_USER').split(',')[1] .split(')')[0].strip().replace('\'', '')) wo_db_pass = (WOFileUtils.grep(self, configfiles[0], 'DB_PASSWORD').split(',')[1] .split(')')[0].strip().replace('\'', '')) wo_db_host = (WOFileUtils.grep(self, configfiles[0], 'DB_HOST').split(',')[1] .split(')')[0].strip().replace('\'', '')) # Check if database really exist try: if not WOMysql.check_db_exists(self, wo_db_name): # Mark it as deleted if not exist wo_db_name = 'deleted' wo_db_user = '******' wo_db_pass = '******' except StatementExcecutionError as e: Log.debug(self, str(e)) except Exception as e: Log.debug(self, str(e)) if site.db_name != wo_db_name: # update records if any mismatch found Log.debug(self, "Updating wo db record for {0}" .format(site.sitename)) updateSiteInfo(self, site.sitename, db_name=wo_db_name, db_user=wo_db_user, db_password=wo_db_pass, db_host=wo_db_host) else: Log.debug(self, "Config files not found for {0} " .format(site.sitename))
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.hhvm or self.app.pargs.memcache or self.app.pargs.redis): self.app.pargs.nginx = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed( self, 'nginx-mainline'): services = services + ['nginx'] else: Log.info(self, "Nginx is not installed") if self.app.pargs.php: if (WOVariables.wo_platform_distro == 'debian' or WOVariables.wo_platform_codename == 'precise'): if WOAptGet.is_installed(self, 'php5-fpm'): services = services + ['php5-fpm'] else: Log.info(self, "PHP5-FPM is not installed") else: if WOAptGet.is_installed(self, 'php5.6-fpm'): services = services + ['php5.6-fpm'] else: Log.info(self, "PHP5.6-FPM is not installed") if WOAptGet.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 (WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic'): if WOAptGet.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 ((WOVariables.wo_mysql_host is "localhost") or (WOVariables.wo_mysql_host is "127.0.0.1")): if (WOAptGet.is_installed(self, 'mysql-server') or WOAptGet.is_installed(self, 'percona-server-server-5.6') or WOAptGet.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.hhvm: Log.info(self, "HHVM does not support to reload") if self.app.pargs.memcache: if WOAptGet.is_installed(self, 'memcached'): services = services + ['memcached'] else: Log.info(self, "Memcache is not installed") if self.app.pargs.redis: if WOAptGet.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)) WOService.reload_service(self, service)