Beispiel #1
0
 def status(self):
     """Status of services"""
     services = []
     if self.app.pargs.nginx:
         Log.debug(self, "nginx service status")
         services = services + ['nginx']
     if self.app.pargs.php:
         Log.debug(self, "php5-fpm service status")
         services = services + ['php5-fpm']
     if self.app.pargs.mysql:
         if EEVariables.ee_mysql_host is "localhost":
             Log.debug(self, "mysql service status")
             services = services + ['mysql']
         else:
             Log.warn(self, "Remote MySQL found, "
                      "unable to get MySQL service status")
     if self.app.pargs.postfix:
         services = services + ['postfix']
         Log.debug(self, "postfix service status")
     if self.app.pargs.memcache:
         Log.debug(self, "memcached service status")
         services = services + ['memcached']
     if self.app.pargs.dovecot:
         Log.debug(self, "dovecot service status")
         services = services + ['dovecot']
     if not services and EEVariables.ee_mysql_host is "localhost":
         services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
         Log.debug(self, "nginx,php5-fpm,mysql,postfix services status")
     elif not services:
         services = services + ['nginx', 'php5-fpm', 'postfix']
         Log.debug(self, "nginx,php5-fpm,postfix services status")
     for service in services:
         if EEService.get_service_status(self, service):
             Log.info(self, "{0:10}:  {1}".format(service, "Running"))
Beispiel #2
0
 def restart(self):
     """Restart services"""
     services = []
     if self.app.pargs.nginx:
         Log.debug(self, "nginx service restart")
         services = services + ['nginx']
     if self.app.pargs.php:
         Log.debug(self, "php5-fpm service restart")
         services = services + ['php5-fpm']
     if self.app.pargs.mysql:
         if EEVariables.ee_mysql_host is "localhost":
             Log.debug(self, "mysql service restart")
             services = services + ['mysql']
         else:
             Log.warn(self, "Remote MySQL found, "
                      "unable to restart MySQL service")
     if self.app.pargs.postfix:
         Log.debug(self, "postfix service restart")
         services = services + ['postfix']
     if self.app.pargs.memcache:
         Log.debug(self, "memcached service restart")
         services = services + ['memcached']
     if self.app.pargs.dovecot:
         Log.debug(self, "dovecot service restart")
         services = services + ['dovecot']
     if not services and EEVariables.ee_mysql_host is "localhost":
         services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
         Log.debug(self, "nginx,php5-fpm,mysql,postfix services restart")
     elif not services:
         services = services + ['nginx', 'php5-fpm', 'postfix']
         Log.debug(self, "nginx,php5-fpm,postfix services restart")
     for service in services:
         EEService.restart_service(self, service)
Beispiel #3
0
 def status(self):
     """Status of services"""
     services = []
     if self.app.pargs.nginx:
         Log.debug(self, "nginx service status")
         services = services + ['nginx']
     if self.app.pargs.php:
         Log.debug(self, "php5-fpm service status")
         services = services + ['php5-fpm']
     if self.app.pargs.mysql:
         if EEVariables.ee_mysql_host is "localhost":
             Log.debug(self, "mysql service status")
             services = services + ['mysql']
         else:
             Log.warn(
                 self, "Remote MySQL found, "
                 "unable to get MySQL service status")
     if self.app.pargs.postfix:
         services = services + ['postfix']
         Log.debug(self, "postfix service status")
     if self.app.pargs.memcache:
         Log.debug(self, "memcached service status")
         services = services + ['memcached']
     if self.app.pargs.dovecot:
         Log.debug(self, "dovecot service status")
         services = services + ['dovecot']
     if not services and EEVariables.ee_mysql_host is "localhost":
         services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
         Log.debug(self, "nginx,php5-fpm,mysql,postfix services status")
     elif not services:
         services = services + ['nginx', 'php5-fpm', 'postfix']
         Log.debug(self, "nginx,php5-fpm,postfix services status")
     for service in services:
         if EEService.get_service_status(self, service):
             Log.info(self, "{0:10}:  {1}".format(service, "Running"))
Beispiel #4
0
 def restart(self):
     """Restart services"""
     services = []
     if self.app.pargs.nginx:
         Log.debug(self, "nginx service restart")
         services = services + ['nginx']
     if self.app.pargs.php:
         Log.debug(self, "php5-fpm service restart")
         services = services + ['php5-fpm']
     if self.app.pargs.mysql:
         if EEVariables.ee_mysql_host is "localhost":
             Log.debug(self, "mysql service restart")
             services = services + ['mysql']
         else:
             Log.warn(
                 self, "Remote MySQL found, "
                 "unable to restart MySQL service")
     if self.app.pargs.postfix:
         Log.debug(self, "postfix service restart")
         services = services + ['postfix']
     if self.app.pargs.memcache:
         Log.debug(self, "memcached service restart")
         services = services + ['memcached']
     if self.app.pargs.dovecot:
         Log.debug(self, "dovecot service restart")
         services = services + ['dovecot']
     if not services and EEVariables.ee_mysql_host is "localhost":
         services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
         Log.debug(self, "nginx,php5-fpm,mysql,postfix services restart")
     elif not services:
         services = services + ['nginx', 'php5-fpm', 'postfix']
         Log.debug(self, "nginx,php5-fpm,postfix services restart")
     for service in services:
         EEService.restart_service(self, service)
Beispiel #5
0
    def signal_handler(self, signal, frame):
        """Handle Ctrl+c hevent for -i option of debug"""
        self.start = False
        if self.app.pargs.nginx:
            self.debug_nginx()
        if self.app.pargs.php:
            self.debug_php()
        if self.app.pargs.fpm:
            self.debug_fpm()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine will not "
                         "enable remote debug")
        if self.app.pargs.wp:
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.debug_rewrite()

        # Reload Nginx
        if self.trigger_nginx:
            EEService.reload_service(self, 'nginx')

        # Reload PHP
        if self.trigger_php:
            EEService.reload_service(self, 'php5-fpm')
        self.app.close(0)
Beispiel #6
0
    def signal_handler(self, signal, frame):
        """Handle Ctrl+c hevent for -i option of debug"""
        self.start = False
        if self.app.pargs.nginx:
            self.debug_nginx()
        if self.app.pargs.php:
            self.debug_php()
        if self.app.pargs.fpm:
            self.debug_fpm()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine will not "
                         "enable remote debug")
        if self.app.pargs.wp:
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.debug_rewrite()

        # Reload Nginx
        if self.trigger_nginx:
            EEService.reload_service(self, 'nginx')

        # Reload PHP
        if self.trigger_php:
            EEService.reload_service(self, 'php5-fpm')
        self.app.close(0)
Beispiel #7
0
    def signal_handler(self, signal, frame):
        """Handle Ctrl+c hevent for -i option of debug"""
        self.start = False
        if self.app.pargs.nginx:
            self.app.pargs.nginx = 'off'
            self.debug_nginx()
        if self.app.pargs.php:
            self.app.pargs.php = 'off'
            self.debug_php()
        if self.app.pargs.php7:
            self.app.pargs.php7 = 'off'
            self.debug_php7()
        if self.app.pargs.fpm:
            self.app.pargs.fpm = 'off'
            self.debug_fpm()
        if self.app.pargs.fpm7:
            self.app.pargs.fpm7 = 'off'
            self.debug_fpm7()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.app.pargs.mysql = 'off'
                self.debug_mysql()
            else:
                Log.warn(
                    self, "Remote MySQL found, EasyEngine will not "
                    "enable remote debug")
        if self.app.pargs.wp:
            self.app.pargs.wp = 'off'
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.app.pargs.rewrite = 'off'
            self.debug_rewrite()

        # Reload Nginx
        if self.trigger_nginx:
            EEService.reload_service(self, 'nginx')

        # Reload PHP
        if self.trigger_php:
            if EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'bionic':
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    EEService.reload_service(self, 'php5.6-fpm')
                if EEAptGet.is_installed(self, 'php7.2-fpm'):
                    EEService.reload_service(self, 'php7.2-fpm')
            else:
                EEService.reload_service(self, 'php5-fpm')
        self.app.close(0)
Beispiel #8
0
    def signal_handler(self, signal, frame):
        """Handle Ctrl+c hevent for -i option of debug"""
        self.start = False
        if self.app.pargs.nginx:
            self.app.pargs.nginx = 'off'
            self.debug_nginx()
        if self.app.pargs.php:
            self.app.pargs.php = 'off'
            self.debug_php()
        if self.app.pargs.php7:
            self.app.pargs.php7 = 'off'
            self.debug_php7()
        if self.app.pargs.fpm:
            self.app.pargs.fpm = 'off'
            self.debug_fpm()
        if self.app.pargs.fpm7:
            self.app.pargs.fpm7 = 'off'
            self.debug_fpm7()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.app.pargs.mysql = 'off'
                self.debug_mysql()
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine will not "
                         "enable remote debug")
        if self.app.pargs.wp:
            self.app.pargs.wp = 'off'
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.app.pargs.rewrite = 'off'
            self.debug_rewrite()

        # Reload Nginx
        if self.trigger_nginx:
            EEService.reload_service(self, 'nginx')

        # Reload PHP
        if self.trigger_php:
            if EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial':
                if EEAptGet.is_installed(self,'php5.6-fpm'):
                    EEService.reload_service(self, 'php5.6-fpm')
                if EEAptGet.is_installed(self,'php7.0-fpm'):
                    EEService.reload_service(self, 'php7.0-fpm')
            else:
                EEService.reload_service(self, 'php5-fpm')
        self.app.close(0)
Beispiel #9
0
def setupwordpress(self, data):
    ee_domain_name = data['site_name']
    ee_site_webroot = data['webroot']
    prompt_wpprefix = self.app.config.get('wordpress', 'prefix')
    ee_wp_user = self.app.config.get('wordpress', 'user')
    ee_wp_pass = self.app.config.get('wordpress', 'password')
    ee_wp_email = self.app.config.get('wordpress', 'email')
    # Random characters
    ee_random = (''.join(random.sample(string.ascii_uppercase +
                 string.ascii_lowercase + string.digits, 15)))
    ee_wp_prefix = ''
    # ee_wp_user = ''
    # ee_wp_pass = ''

    if 'wp-user' in data.keys() and data['wp-user']:
        ee_wp_user = data['wp-user']
    if 'wp-email' in data.keys() and data['wp-email']:
        ee_wp_email = data['wp-email']
    if 'wp-pass' in data.keys() and data['wp-pass']:
        ee_wp_pass = data['wp-pass']

    Log.info(self, "Downloading Wordpress \t\t", end='')
    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    try:
        EEShellExec.cmd_exec(self, "wp --allow-root core"
                             " download")
    except CommandExecutionError as e:
        Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]")
        raise SiteError(self, "download wordpress core failed")

    Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")

    if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']):
        data = setupdatabase(self, data)
    if prompt_wpprefix == 'True' or prompt_wpprefix == 'true':
        try:
            ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ')
            while not re.match('^[A-Za-z0-9_]*$', ee_wp_prefix):
                Log.warn(self, "table prefix can only "
                         "contain numbers, letters, and underscores")
                ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: '
                                     )
        except EOFError as e:
            Log.debug(self, "{0}".format(e))
            raise SiteError("input table prefix failed")

    if not ee_wp_prefix:
        ee_wp_prefix = 'wp_'

    # Modify wp-config.php & move outside the webroot

    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    Log.debug(self, "Setting up wp-config file")
    if not data['multisite']:
        Log.debug(self, "Generating wp-config for WordPress Single site")
        Log.debug(self, "bash -c \"php {0} --allow-root "
                  .format(EEVariables.ee_wpcli_path)
                  + "core config "
                  + "--dbname=\'{0}\' --dbprefix=\'{1}\' --dbuser=\'{2}\' "
                  "--dbhost=\'{3}\' "
                  .format(data['ee_db_name'], ee_wp_prefix,
                          data['ee_db_user'], data['ee_db_host'])
                  + "--dbpass= "******"--extra-php<<PHP \n {1}\nPHP\""
                  .format(data['ee_db_pass'],
                          "\n\ndefine(\'WP_DEBUG\', false);"))
        try:
            EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root"
                                 .format(EEVariables.ee_wpcli_path)
                                 + " core config "
                                 + "--dbname=\'{0}\' --dbprefix=\'{1}\' "
                                 "--dbuser=\'{2}\' --dbhost=\'{3}\' "
                                 .format(data['ee_db_name'], ee_wp_prefix,
                                         data['ee_db_user'], data['ee_db_host']
                                         )
                                 + "--dbpass=\'{0}\' "
                                   "--extra-php<<PHP \n {1} {redissalt}\nPHP\""
                                   .format(data['ee_db_pass'],
                                           "\n\ndefine(\'WP_DEBUG\', false);",
                                           redissalt="\n\ndefine( \'WP_CACHE_KEY_SALT\', \'{0}:\' );"
                                                      .format(ee_domain_name) if data['wpredis'] 
                                                      else ''),
                                   log=False
                                 )
        except CommandExecutionError as e:
                raise SiteError("generate wp-config failed for wp single site")
    else:
        Log.debug(self, "Generating wp-config for WordPress multisite")
        Log.debug(self, "bash -c \"php {0} --allow-root "
                  .format(EEVariables.ee_wpcli_path)
                  + "core config "
                  + "--dbname=\'{0}\' --dbprefix=\'{1}\' --dbhost=\'{2}\' "
                  .format(data['ee_db_name'], ee_wp_prefix, data['ee_db_host'])
                  + "--dbuser=\'{0}\' --dbpass= "******"--extra-php<<PHP \n {2} {3} {4}\nPHP\""
                  .format(data['ee_db_user'], data['ee_db_pass'],
                          "\ndefine(\'WP_ALLOW_MULTISITE\', "
                          "true);",
                          "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
                          " true);",
                          "\n\ndefine(\'WP_DEBUG\', false);"))
        try:
            EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root"
                                 .format(EEVariables.ee_wpcli_path)
                                 + " core config "
                                 + "--dbname=\'{0}\' --dbprefix=\'{1}\' "
                                 "--dbhost=\'{2}\' "
                                 .format(data['ee_db_name'], ee_wp_prefix,
                                         data['ee_db_host'])
                                 + "--dbuser=\'{0}\' --dbpass=\'{1}\' "
                                   "--extra-php<<PHP \n {2} {3} {4} {redissalt}\nPHP\""
                                 .format(data['ee_db_user'],
                                         data['ee_db_pass'],
                                         "\ndefine(\'WP_ALLOW_MULTISITE\', "
                                         "true);",
                                         "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
                                         " true);",
                                         "\n\ndefine(\'WP_DEBUG\', false);",
                                         redissalt="\n\ndefine( \'WP_CACHE_KEY_SALT\', \'{0}:\' );"
                                                      .format(ee_domain_name) if data['wpredis'] 
                                                      else ''),
                                 log=False
                                 )
        except CommandExecutionError as e:
                raise SiteError("generate wp-config failed for wp multi site")

    EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php',
                       os.path.abspath(os.path.join(os.getcwd(), os.pardir)))

    if not ee_wp_user:
        ee_wp_user = EEVariables.ee_user
        while not ee_wp_user:
            Log.warn(self, "Username can have only alphanumeric"
                     "characters, spaces, underscores, hyphens,"
                     "periods and the @ symbol.")
            try:
                ee_wp_user = input('Enter WordPress username: '******'Enter WordPress email: ')
            except EOFError as e:
                Log.debug(self, "{0}".format(e))
                raise SiteError("input wordpress username failed")

    try:
        while not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
                           ee_wp_email):
            Log.info(self, "EMail not Valid in config, "
                     "Please provide valid email id")
            ee_wp_email = input("Enter your email: ")
    except EOFError as e:
        Log.debug(self, "{0}".format(e))
        raise SiteError("input WordPress user email failed")

    Log.debug(self, "Setting up WordPress tables")

    if not data['multisite']:
        Log.debug(self, "Creating tables for WordPress Single site")
        Log.debug(self, "php {0} --allow-root core install "
                  .format(EEVariables.ee_wpcli_path)
                  + "--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' "
                  .format(data['www_domain'], ee_wp_user)
                  + "--admin_password= --admin_email=\'{1}\'"
                  .format(ee_wp_pass, ee_wp_email))
        try:
            EEShellExec.cmd_exec(self, "php {0} --allow-root core "
                                 .format(EEVariables.ee_wpcli_path)
                                 + "install --url=\'{0}\' --title=\'{0}\' "
                                 "--admin_name=\'{1}\' "
                                 .format(data['www_domain'], ee_wp_user)
                                 + "--admin_password=\'{0}\' "
                                 "--admin_email=\'{1}\'"
                                 .format(ee_wp_pass, ee_wp_email),
                                 log=False)
        except CommandExceutionError as e:
            raise SiteError("setup wordpress tables failed for single site")
    else:
        Log.debug(self, "Creating tables for WordPress multisite")
        Log.debug(self, "php {0} --allow-root "
                  .format(EEVariables.ee_wpcli_path)
                  + "core multisite-install "
                  "--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' "
                  .format(data['www_domain'], ee_wp_user)
                  + "--admin_password= --admin_email=\'{1}\' "
                  "{subdomains}"
                  .format(ee_wp_pass, ee_wp_email,
                          subdomains='--subdomains'
                          if not data['wpsubdir'] else ''))
        try:
            EEShellExec.cmd_exec(self, "php {0} --allow-root "
                                 .format(EEVariables.ee_wpcli_path)
                                 + "core multisite-install "
                                 "--url=\'{0}\' --title=\'{0}\' "
                                 "--admin_name=\'{1}\' "
                                 .format(data['www_domain'], ee_wp_user)
                                 + "--admin_password=\'{0}\' "
                                 "--admin_email=\'{1}\' "
                                 "{subdomains}"
                                 .format(ee_wp_pass, ee_wp_email,
                                         subdomains='--subdomains'
                                         if not data['wpsubdir'] else ''),
                                 log=False)
        except CommandExecutionError as e:
            raise SiteError("setup wordpress tables failed for wp multi site")

    Log.debug(self, "Updating WordPress permalink")
    try:
        EEShellExec.cmd_exec(self, " php {0} --allow-root "
                             .format(EEVariables.ee_wpcli_path)
                             + "rewrite structure "
                             "/%year%/%monthnum%/%day%/%postname%/")
    except CommandExecutionError as e:
        raise SiteError("Update wordpress permalinks failed")

    """Install nginx-helper plugin """
    installwp_plugin(self, 'nginx-helper', data)
    if data['wpfc']:
        plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_fastcgi","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
        setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
    elif data['wpredis']:
        plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
        setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)

    """Install Wp Super Cache"""
    if data['wpsc']:
        installwp_plugin(self, 'wp-super-cache', data)

    """Install Redis Cache"""
    if data['wpredis']:
        installwp_plugin(self, 'redis-cache', data)

    """Install W3 Total Cache"""
    if data['w3tc'] or data['wpfc']:
        installwp_plugin(self, 'w3-total-cache', data)

    wp_creds = dict(wp_user=ee_wp_user, wp_pass=ee_wp_pass,
                    wp_email=ee_wp_email)

    return(wp_creds)
Beispiel #10
0
def setupwordpress(self, data):
    ee_domain_name = data['site_name']
    ee_site_webroot = data['webroot']
    prompt_wpprefix = self.app.config.get('wordpress', 'prefix')
    ee_wp_user = self.app.config.get('wordpress', 'user')
    ee_wp_pass = self.app.config.get('wordpress', 'password')
    ee_wp_email = self.app.config.get('wordpress', 'email')
    # Random characters
    ee_random = (''.join(
        random.sample(
            string.ascii_uppercase + string.ascii_lowercase + string.digits,
            15)))
    ee_wp_prefix = ''
    # ee_wp_user = ''
    # ee_wp_pass = ''

    Log.info(self, "Downloading Wordpress \t\t", end='')
    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    EEShellExec.cmd_exec(self, "wp --allow-root core download")
    Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")

    if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']):
        data = setupdatabase(self, data)
    if prompt_wpprefix == 'True' or prompt_wpprefix == 'true':
        try:
            ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ')
            while not re.match('^[A-Za-z0-9_]*$', ee_wp_prefix):
                Log.warn(
                    self, "table prefix can only "
                    "contain numbers, letters, and underscores")
                ee_wp_prefix = input(
                    'Enter the WordPress table prefix [wp_]: ')
        except EOFError as e:
            Log.debug(self, "{0}".format(e))
            Log.error(self, "Unable to input table prefix")

    if not ee_wp_prefix:
        ee_wp_prefix = 'wp_'

    # Modify wp-config.php & move outside the webroot

    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    Log.debug(self, "Setting up wp-config file")
    if not data['multisite']:
        Log.debug(self, "Generating wp-config for WordPress Single site")
        Log.debug(
            self, "bash -c \"php /usr/bin/wp --allow-root " + "core config " +
            "--dbname={0} --dbprefix={1} --dbuser={2} --dbhost={3} ".format(
                data['ee_db_name'], ee_wp_prefix, data['ee_db_user'],
                data['ee_db_host']) + "--dbpass= "******"--extra-php<<PHP \n {1}\nPHP\"".format(
                data['ee_db_pass'], "\n\ndefine(\'WP_DEBUG\', false);"))
        EEShellExec.cmd_exec(
            self,
            "bash -c \"php /usr/bin/wp --allow-root " + "core config " +
            "--dbname={0} --dbprefix={1} --dbuser={2} --dbhost={3} ".format(
                data['ee_db_name'], ee_wp_prefix, data['ee_db_user'],
                data['ee_db_host']) + "--dbpass={0} "
            "--extra-php<<PHP \n {1}\nPHP\"".format(
                data['ee_db_pass'], "\n\ndefine(\'WP_DEBUG\', false);"),
            log=False)
    else:
        Log.debug(self, "Generating wp-config for WordPress multisite")
        Log.debug(
            self, "bash -c \"php /usr/bin/wp --allow-root " + "core config " +
            "--dbname={0} --dbprefix={1} --dbhost={2} ".format(
                data['ee_db_name'], ee_wp_prefix, data['ee_db_host']) +
            "--dbuser={0} --dbpass= "******"--extra-php<<PHP \n {2} {3} {4}\nPHP\"".format(
                data['ee_db_user'], data['ee_db_pass'],
                "\ndefine(\'WP_ALLOW_MULTISITE\', "
                "true);", "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
                " true);", "\n\ndefine(\'WP_DEBUG\', false);"))
        EEShellExec.cmd_exec(
            self,
            "bash -c \"php /usr/bin/wp --allow-root " + "core config " +
            "--dbname={0} --dbprefix={1} --dbhost={2} ".format(
                data['ee_db_name'], ee_wp_prefix, data['ee_db_host']) +
            "--dbuser={0} --dbpass={1} "
            "--extra-php<<PHP \n {2} {3} {4}\nPHP\"".format(
                data['ee_db_user'], data['ee_db_pass'],
                "\ndefine(\'WP_ALLOW_MULTISITE\', "
                "true);", "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
                " true);", "\n\ndefine(\'WP_DEBUG\', false);"),
            log=False)
    EEFileUtils.mvfile(self,
                       os.getcwd() + '/wp-config.php',
                       os.path.abspath(os.path.join(os.getcwd(), os.pardir)))

    if not ee_wp_user:
        ee_wp_user = EEVariables.ee_user
        while not ee_wp_user:
            Log.warn(
                self, "Username can have only alphanumeric"
                "characters, spaces, underscores, hyphens,"
                "periods and the @ symbol.")
            try:
                ee_wp_user = input('Enter WordPress username: '******'Enter WordPress email: ')
            except EOFError as e:
                Log.debug(self, "{0}".format(e))
                Log.error(self, "Unable to input WordPress user email")

    Log.debug(self, "Setting up WordPress tables")

    if not data['multisite']:
        Log.debug(self, "Creating tables for WordPress Single site")
        Log.debug(
            self, "php /usr/bin/wp --allow-root core install "
            "--url={0} --title={0} --admin_name={1} ".format(
                data['www_domain'], ee_wp_user) +
            "--admin_password= --admin_email={1}".format(
                ee_wp_pass, ee_wp_email))
        EEShellExec.cmd_exec(self,
                             "php /usr/bin/wp --allow-root core install "
                             "--url={0} --title={0} --admin_name={1} ".format(
                                 data['www_domain'], ee_wp_user) +
                             "--admin_password={0} --admin_email={1}".format(
                                 ee_wp_pass, ee_wp_email),
                             errormsg="Unable to setup WordPress Tables",
                             log=False)
    else:
        Log.debug(self, "Creating tables for WordPress multisite")
        Log.debug(
            self, "php /usr/bin/wp --allow-root "
            "core multisite-install "
            "--url={0} --title={0} --admin_name={1} ".format(
                data['www_domain'], ee_wp_user) +
            "--admin_password= --admin_email={1} "
            "{subdomains}".format(
                ee_wp_pass,
                ee_wp_email,
                subdomains='--subdomains' if not data['wpsubdir'] else ''))
        EEShellExec.cmd_exec(
            self,
            "php /usr/bin/wp --allow-root "
            "core multisite-install "
            "--url={0} --title={0} --admin_name={1} ".format(
                data['www_domain'], ee_wp_user) +
            "--admin_password={0} --admin_email={1} "
            "{subdomains}".format(
                ee_wp_pass,
                ee_wp_email,
                subdomains='--subdomains' if not data['wpsubdir'] else ''),
            errormsg="Unable to setup WordPress Tables")

    Log.debug(self, "Updating WordPress permalink")
    EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root "
                         "rewrite structure "
                         "/%year%/%monthnum%/%day%/%postname%/",
                         errormsg="Unable to Update WordPress permalink")
    """Install nginx-helper plugin """
    installwp_plugin(self, 'nginx-helper', data)
    """Install Wp Super Cache"""
    if data['wpsc']:
        installwp_plugin(self, 'wp-super-cache', data)
    """Install W3 Total Cache"""
    if data['w3tc'] or data['wpfc']:
        installwp_plugin(self, 'w3-total-cache', data)

    wp_creds = dict(wp_user=ee_wp_user,
                    wp_pass=ee_wp_pass,
                    wp_email=ee_wp_email)

    return (wp_creds)
Beispiel #11
0
    def reload(self):
        """Reload service"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php
                or self.app.pargs.php7 or self.app.pargs.mysql
                or self.app.pargs.postfix or self.app.pargs.hhvm
                or self.app.pargs.memcache or self.app.pargs.dovecot
                or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True

        if self.app.pargs.nginx:
            if EEAptGet.is_installed(self,
                                     'nginx-custom') or EEAptGet.is_installed(
                                         self, 'nginx-mainline'):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if self.app.pargs.php:
            if (EEVariables.ee_platform_distro == 'debian'
                    or EEVariables.ee_platform_codename == 'precise'):
                if EEAptGet.is_installed(self, 'php5-fpm'):
                    services = services + ['php5-fpm']
                else:
                    Log.info(self, "PHP5-FPM is not installed")
            else:
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    services = services + ['php5.6-fpm']
                else:
                    Log.info(self, "PHP5.6-FPM is not installed")

                if EEAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")

        if self.app.pargs.php7:
            if (EEVariables.ee_platform_codename == 'trusty'
                    or EEVariables.ee_platform_codename == 'xenial'
                    or EEVariables.ee_platform_codename == 'bionic'):
                if EEAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")
            else:
                Log.info(self, "Your platform does not support PHP 7")

        if self.app.pargs.mysql:
            if ((EEVariables.ee_mysql_host is "localhost")
                    or (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server')
                        or EEAptGet.is_installed(self,
                                                 'percona-server-server-5.6')
                        or EEAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(
                    self, "Remote MySQL found, "
                    "Unable to check MySQL service status")

        if self.app.pargs.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

        if self.app.pargs.hhvm:
            Log.info(self, "HHVM does not support to reload")

        if self.app.pargs.memcache:
            if EEAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcache is not installed")

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        for service in services:
            Log.debug(self, "Reloading service: {0}".format(service))
            EEService.reload_service(self, service)
    def reload(self):
        """Reload service"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php7
                or self.app.pargs.mysql or self.app.pargs.postfix
                or self.app.pargs.hhvm or self.app.pargs.memcache
                or self.app.pargs.dovecot or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True

        if self.app.pargs.nginx:
            if EEAptGet.is_installed(self, 'nginx-custom') or EEAptGet.is_installed(self,'nginx-mainline'):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if self.app.pargs.php:
            if EEVariables.ee_platform_codename != 'trusty':
                if EEAptGet.is_installed(self, 'php5-fpm'):
                    services = services + ['php5-fpm']
                else:
                    Log.info(self, "PHP5-FPM is not installed")
            else:
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    services = services + ['php5.6-fpm']
                else:
                    Log.info(self, "PHP5.6-FPM is not installed")

                if EEAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")

        if self.app.pargs.php7:
            if EEVariables.ee_platform_codename == 'trusty':
                if EEAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")
            else:
                Log.info(self, "Your platform does not support PHP 7")

        if self.app.pargs.mysql:
            if ((EEVariables.ee_mysql_host is "localhost") or
               (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server') or
                   EEAptGet.is_installed(self, 'percona-server-server-5.6') or
                   EEAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(self, "Remote MySQL found, "
                         "Unable to check MySQL service status")

        if self.app.pargs.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

        if self.app.pargs.hhvm:
            Log.info(self, "HHVM does not support to reload")

        if self.app.pargs.memcache:
            if EEAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcache is not installed")

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        for service in services:
            Log.debug(self, "Reloading service: {0}".format(service))
            EEService.reload_service(self, service)
Beispiel #13
0
def setupwordpress(self, data):
    ee_domain_name = data['site_name']
    ee_site_webroot = data['webroot']
    prompt_wpprefix = self.app.config.get('wordpress', 'prefix')
    ee_wp_user = self.app.config.get('wordpress', 'user')
    ee_wp_pass = self.app.config.get('wordpress', 'password')
    ee_wp_email = self.app.config.get('wordpress', 'email')
    # Random characters
    ee_random = (''.join(random.sample(string.ascii_uppercase +
                 string.ascii_lowercase + string.digits, 15)))
    ee_wp_prefix = ''
    # ee_wp_user = ''
    # ee_wp_pass = ''

    if 'wp-user' in data.keys() and data['wp-user']:
        ee_wp_user = data['wp-user']
    if 'wp-email' in data.keys() and data['wp-email']:
        ee_wp_email = data['wp-email']
    if 'wp-pass' in data.keys() and data['wp-pass']:
        ee_wp_pass = data['wp-pass']

    Log.info(self, "Downloading Wordpress \t\t", end='')
    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    try:
        EEShellExec.cmd_exec(self, "wp --allow-root core"
                             " download")
    except CommandExecutionError as e:
        Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]")
        raise SiteError(self, "download wordpress core failed")

    Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")

    if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']):
        data = setupdatabase(self, data)
    if prompt_wpprefix == 'True' or prompt_wpprefix == 'true':
        try:
            ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ')
            while not re.match('^[A-Za-z0-9_]*$', ee_wp_prefix):
                Log.warn(self, "table prefix can only "
                         "contain numbers, letters, and underscores")
                ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: '
                                     )
        except EOFError as e:
            Log.debug(self, "{0}".format(e))
            raise SiteError("input table prefix failed")

    if not ee_wp_prefix:
        ee_wp_prefix = 'wp_'

    # Modify wp-config.php & move outside the webroot

    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    Log.debug(self, "Setting up wp-config file")
    if not data['multisite']:
        Log.debug(self, "Generating wp-config for WordPress Single site")
        Log.debug(self, "bash -c \"php {0} --allow-root "
                  .format(EEVariables.ee_wpcli_path)
                  + "core config "
                  + "--dbname=\'{0}\' --dbprefix=\'{1}\' --dbuser=\'{2}\' "
                  "--dbhost=\'{3}\' "
                  .format(data['ee_db_name'], ee_wp_prefix,
                          data['ee_db_user'], data['ee_db_host'])
                  + "--dbpass= "******"--extra-php<<PHP \n {1}\nPHP\""
                  .format(data['ee_db_pass'],
                          "\n\ndefine(\'WP_DEBUG\', false);"))
        try:
            EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root"
                                 .format(EEVariables.ee_wpcli_path)
                                 + " core config "
                                 + "--dbname=\'{0}\' --dbprefix=\'{1}\' "
                                 "--dbuser=\'{2}\' --dbhost=\'{3}\' "
                                 .format(data['ee_db_name'], ee_wp_prefix,
                                         data['ee_db_user'], data['ee_db_host']
                                         )
                                 + "--dbpass=\'{0}\' "
                                   "--extra-php<<PHP \n {1}\nPHP\""
                                   .format(data['ee_db_pass'],
                                           "\n\ndefine(\'WP_DEBUG\', false);"),
                                   log=False
                                 )
        except CommandExecutionError as e:
                raise SiteError("generate wp-config failed for wp single site")
    else:
        Log.debug(self, "Generating wp-config for WordPress multisite")
        Log.debug(self, "bash -c \"php {0} --allow-root "
                  .format(EEVariables.ee_wpcli_path)
                  + "core config "
                  + "--dbname=\'{0}\' --dbprefix=\'{1}\' --dbhost=\'{2}\' "
                  .format(data['ee_db_name'], ee_wp_prefix, data['ee_db_host'])
                  + "--dbuser=\'{0}\' --dbpass= "******"--extra-php<<PHP \n {2} {3} {4}\nPHP\""
                  .format(data['ee_db_user'], data['ee_db_pass'],
                          "\ndefine(\'WP_ALLOW_MULTISITE\', "
                          "true);",
                          "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
                          " true);",
                          "\n\ndefine(\'WP_DEBUG\', false);"))
        try:
            EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root"
                                 .format(EEVariables.ee_wpcli_path)
                                 + " core config "
                                 + "--dbname=\'{0}\' --dbprefix=\'{1}\' "
                                 "--dbhost=\'{2}\' "
                                 .format(data['ee_db_name'], ee_wp_prefix,
                                         data['ee_db_host'])
                                 + "--dbuser=\'{0}\' --dbpass=\'{1}\' "
                                   "--extra-php<<PHP \n {2} {3} {4}\nPHP\""
                                 .format(data['ee_db_user'],
                                         data['ee_db_pass'],
                                         "\ndefine(\'WP_ALLOW_MULTISITE\', "
                                         "true);",
                                         "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
                                         " true);",
                                         "\n\ndefine(\'WP_DEBUG\', false);"),
                                 log=False
                                 )
        except CommandExecutionError as e:
                raise SiteError("generate wp-config failed for wp multi site")

    EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php',
                       os.path.abspath(os.path.join(os.getcwd(), os.pardir)))

    if not ee_wp_user:
        ee_wp_user = EEVariables.ee_user
        while not ee_wp_user:
            Log.warn(self, "Username can have only alphanumeric"
                     "characters, spaces, underscores, hyphens,"
                     "periods and the @ symbol.")
            try:
                ee_wp_user = input('Enter WordPress username: '******'Enter WordPress email: ')
            except EOFError as e:
                Log.debug(self, "{0}".format(e))
                raise SiteError("input wordpress username failed")

    try:
        while not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
                           ee_wp_email):
            Log.info(self, "EMail not Valid in config, "
                     "Please provide valid email id")
            ee_wp_email = input("Enter your email: ")
    except EOFError as e:
        Log.debug(self, "{0}".format(e))
        raise SiteError("input WordPress user email failed")

    Log.debug(self, "Setting up WordPress tables")

    if not data['multisite']:
        Log.debug(self, "Creating tables for WordPress Single site")
        Log.debug(self, "php {0} --allow-root core install "
                  .format(EEVariables.ee_wpcli_path)
                  + "--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' "
                  .format(data['www_domain'], ee_wp_user)
                  + "--admin_password= --admin_email=\'{1}\'"
                  .format(ee_wp_pass, ee_wp_email))
        try:
            EEShellExec.cmd_exec(self, "php {0} --allow-root core "
                                 .format(EEVariables.ee_wpcli_path)
                                 + "install --url=\'{0}\' --title=\'{0}\' "
                                 "--admin_name=\'{1}\' "
                                 .format(data['www_domain'], ee_wp_user)
                                 + "--admin_password=\'{0}\' "
                                 "--admin_email=\'{1}\'"
                                 .format(ee_wp_pass, ee_wp_email),
                                 log=False)
        except CommandExceutionError as e:
            raise SiteError("setup wordpress tables failed for single site")
    else:
        Log.debug(self, "Creating tables for WordPress multisite")
        Log.debug(self, "php {0} --allow-root "
                  .format(EEVariables.ee_wpcli_path)
                  + "core multisite-install "
                  "--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' "
                  .format(data['www_domain'], ee_wp_user)
                  + "--admin_password= --admin_email=\'{1}\' "
                  "{subdomains}"
                  .format(ee_wp_pass, ee_wp_email,
                          subdomains='--subdomains'
                          if not data['wpsubdir'] else ''))
        try:
            EEShellExec.cmd_exec(self, "php {0} --allow-root "
                                 .format(EEVariables.ee_wpcli_path)
                                 + "core multisite-install "
                                 "--url=\'{0}\' --title=\'{0}\' "
                                 "--admin_name=\'{1}\' "
                                 .format(data['www_domain'], ee_wp_user)
                                 + "--admin_password=\'{0}\' "
                                 "--admin_email=\'{1}\' "
                                 "{subdomains}"
                                 .format(ee_wp_pass, ee_wp_email,
                                         subdomains='--subdomains'
                                         if not data['wpsubdir'] else ''),
                                 log=False)
        except CommandExecutionError as e:
            raise SiteError("setup wordpress tables failed for wp multi site")

    Log.debug(self, "Updating WordPress permalink")
    try:
        EEShellExec.cmd_exec(self, " php {0} --allow-root "
                             .format(EEVariables.ee_wpcli_path)
                             + "rewrite structure "
                             "/%year%/%monthnum%/%day%/%postname%/")
    except CommandExecutionError as e:
        raise SiteError("Update wordpress permalinks failed")

    """Install nginx-helper plugin """
    installwp_plugin(self, 'nginx-helper', data)
    if data['wpfc']:
        plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_fastcgi","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
        setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
    elif data['wpredis']:
        plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
        setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)

    """Install Wp Super Cache"""
    if data['wpsc']:
        installwp_plugin(self, 'wp-super-cache', data)

    """Install Redis Cache"""
    if data['wpredis']:
        installwp_plugin(self, 'redis-cache', data)

    """Install W3 Total Cache"""
    if data['w3tc'] or data['wpfc']:
        installwp_plugin(self, 'w3-total-cache', data)

    wp_creds = dict(wp_user=ee_wp_user, wp_pass=ee_wp_pass,
                    wp_email=ee_wp_email)

    return(wp_creds)
Beispiel #14
0
    def stop(self):
        """Stop services"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php
                or self.app.pargs.mysql or self.app.pargs.postfix
                or self.app.pargs.hhvm or self.app.pargs.memcache
                or self.app.pargs.dovecot or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True

        if self.app.pargs.nginx:
            if EEAptGet.is_installed(self,
                                     'nginx-custom') or EEAptGet.is_installed(
                                         self, 'nginx-mainline'):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if self.app.pargs.php:
            if EEAptGet.is_installed(self, 'php5-fpm'):
                services = services + ['php5-fpm']
            else:
                Log.info(self, "PHP5-FPM is not installed")

        if self.app.pargs.mysql:
            if ((EEVariables.ee_mysql_host is "localhost")
                    or (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server')
                        or EEAptGet.is_installed(self,
                                                 'percona-server-server-5.6')
                        or EEAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(
                    self, "Remote MySQL found, "
                    "Unable to check MySQL service status")

        if self.app.pargs.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

        if self.app.pargs.hhvm:
            if EEAptGet.is_installed(self, 'hhvm'):
                services = services + ['hhvm']
            else:
                Log.info(self, "HHVM is not installed")
        if self.app.pargs.memcache:
            if EEAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcache is not installed")

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        for service in services:
            Log.debug(self, "Stopping service: {0}".format(service))
            EEService.stop_service(self, service)
Beispiel #15
0
    def status(self):
        """Status of services"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php
                or self.app.pargs.php7 or self.app.pargs.mysql
                or self.app.pargs.postfix or self.app.pargs.hhvm
                or self.app.pargs.memcache or self.app.pargs.dovecot
                or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True
            self.app.pargs.hhvm = True

        if self.app.pargs.nginx:
            if EEAptGet.is_installed(self,
                                     'nginx-custom') or EEAptGet.is_installed(
                                         self, 'nginx-mainline'):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if self.app.pargs.php:
            if EEVariables.ee_platform_codename != 'trusty':
                if EEAptGet.is_installed(self, 'php5-fpm'):
                    services = services + ['php5-fpm']
                else:
                    Log.info(self, "PHP5-FPM is not installed")
            else:
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    services = services + ['php5.6-fpm']
                else:
                    Log.info(self, "PHP5.6-FPM is not installed")

                if EEAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")

        if self.app.pargs.php7:
            if EEVariables.ee_platform_codename == 'trusty':
                if EEAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")
            else:
                Log.info(self, "Your platform does not support PHP 7")

        if self.app.pargs.mysql:
            if ((EEVariables.ee_mysql_host is "localhost")
                    or (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server')
                        or EEAptGet.is_installed(self,
                                                 'percona-server-server-5.6')
                        or EEAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(
                    self, "Remote MySQL found, "
                    "Unable to check MySQL service status")

        if self.app.pargs.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

        if self.app.pargs.hhvm:
            if EEAptGet.is_installed(self, 'hhvm'):
                services = services + ['hhvm']
            else:
                Log.info(self, "HHVM is not installed")
        if self.app.pargs.memcache:
            if EEAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcache is not installed")

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        for service in services:
            if EEService.get_service_status(self, service):
                Log.info(self, "{0:10}:  {1}".format(service, "Running"))
Beispiel #16
0
    def default(self):
        """Default function of log show"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (not self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php5/slow.log', 'a').close()
            open('/var/log/php5/fpm.log', 'a').close()
            self.msg = self.msg + ['/var/log/php5/slow.log',
                                   '/var/log/php5/fpm.log']
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine is not able to"
                         "show MySQL log file")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(EEVariables.ee_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + ["{0}/{1}/logs/access.log"
                                       .format(EEVariables.ee_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.nginx:
                self.msg = self.msg + ["{0}/{1}/logs/error.log"
                                       .format(EEVariables.ee_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile('{0}/logs/debug.log'
                                          .format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log"
                                 .format(webroot),
                                 encoding='utf-8', mode='a').close()
                            EEShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/"
                                                 "wp-content/debug.log"
                                                 "".format(webroot,
                                                           EEVariables
                                                           .ee_php_user)
                                                 )
                    # create symbolic link for debug log
                    EEFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/"
                                                      "debug.log"
                                                      .format(webroot),
                                                      '{0}/logs/debug.log'
                                                      .format(webroot)])

                    self.msg = self.msg + ["{0}/{1}/logs/debug.log"
                                           .format(EEVariables.ee_webroot,
                                                   self.app.pargs.site_name)]
                else:
                    Log.info(self, "Site is not WordPress site, skipping "
                             "WordPress logs")

        watch_list = []
        for w_list in self.msg:
            watch_list = watch_list + glob.glob(w_list)

        logwatch(self, watch_list)
Beispiel #17
0
    def default(self):
        """Default function of debug"""
        # self.start = True
        self.interactive = False
        self.msg = []
        self.trigger_nginx = False
        self.trigger_php = False

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.php7)
           and (not self.app.pargs.fpm) and (not self.app.pargs.fpm7) and (not self.app.pargs.mysql)
           and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
           and (not self.app.pargs.all)
           and (not self.app.pargs.site_name)
           and (not self.app.pargs.import_slow_log)
           and (not self.app.pargs.interval)):
            if self.app.pargs.stop or self.app.pargs.start:
                print("--start/stop option is deprecated since ee3.0.5")
                self.app.args.print_help()
            else:
                self.app.args.print_help()

        if self.app.pargs.import_slow_log:
            self.import_slow_log()

        if self.app.pargs.interval:
            try:
                cron_time = int(self.app.pargs.interval)
            except Exception as e:
                cron_time = 5

            try:
                if not EEShellExec.cmd_exec(self, "crontab -l | grep "
                                            "'ee debug --import-slow-log'"):
                    if not cron_time == 0:
                        Log.info(self, "setting up crontab entry,"
                                 " please wait...")
                        EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
                                             "2> /dev/null | {{ cat; echo -e"
                                             " \\\"#EasyEngine start MySQL "
                                             "slow log \\n*/{0} * * * * "
                                             "/usr/local/bin/ee debug"
                                             " --import-slow-log\\n"
                                             "#EasyEngine end MySQL slow log"
                                             "\\\"; }} | crontab -\""
                                             .format(cron_time))
                else:
                    if not cron_time == 0:
                        Log.info(self, "updating crontab entry,"
                                 " please wait...")
                        if not EEShellExec.cmd_exec(self, "/bin/bash -c "
                                                    "\"crontab "
                                                    "-l | sed '/EasyEngine "
                                                    "start MySQL slow "
                                                    "log/!b;n;c\*\/{0} "
                                                    "\* \* \* "
                                                    "\* \/usr"
                                                    "\/local\/bin\/ee debug "
                                                    "--import\-slow\-log' "
                                                    "| crontab -\""
                                                    .format(cron_time)):
                            Log.error(self, "failed to update crontab entry")
                    else:
                        Log.info(self, "removing crontab entry,"
                                 " please wait...")
                        if not EEShellExec.cmd_exec(self, "/bin/bash -c "
                                                    "\"crontab "
                                                    "-l | sed '/EasyEngine "
                                                    "start MySQL slow "
                                                    "log/,+2d'"
                                                    "| crontab -\""
                                                    .format(cron_time)):
                            Log.error(self, "failed to remove crontab entry")
            except CommandExecutionError as e:
                Log.debug(self, str(e))

        if self.app.pargs.all == 'on':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'on'
            self.app.pargs.nginx = 'on'
            self.app.pargs.php = 'on'
            self.app.pargs.fpm = 'on'
            if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial') and EEAptGet.is_installed(self,'php7.0-fpm'):
                self.app.pargs.php7 = 'on'
                self.app.pargs.fpm7 = 'on'
            self.app.pargs.mysql = 'on'
            self.app.pargs.rewrite = 'on'

        if self.app.pargs.all == 'off':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'off'
            self.app.pargs.nginx = 'off'
            self.app.pargs.php = 'off'
            self.app.pargs.fpm = 'off'
            if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial') and EEAptGet.is_installed(self,'php7.0-fpm'):
                self.app.pargs.php7 = 'off'
                self.app.pargs.fpm7 = 'off'
            self.app.pargs.mysql = 'off'
            self.app.pargs.rewrite = 'off'

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.php7)
           and (not self.app.pargs.fpm) and (not self.app.pargs.fpm7) and (not self.app.pargs.mysql)
           and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
           and self.app.pargs.site_name):
            self.app.args.print_help()
            # self.app.pargs.nginx = 'on'
            # self.app.pargs.wp = 'on'
            # self.app.pargs.rewrite = 'on'

        if self.app.pargs.nginx:
            self.debug_nginx()
        if self.app.pargs.php:
            self.debug_php()
        if self.app.pargs.fpm:
            self.debug_fpm()
        if self.app.pargs.php7:
            self.debug_php7()
        if self.app.pargs.fpm7:
            self.debug_fpm7()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine will not "
                         "enable remote debug")
        if self.app.pargs.wp:
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.debug_rewrite()

        if self.app.pargs.interactive:
            self.interactive = True

        # Reload Nginx
        if self.trigger_nginx:
            EEService.reload_service(self, 'nginx')
        # Reload PHP
        if self.trigger_php:
            if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial'):
                if EEAptGet.is_installed(self,'php5.6-fpm'):
                    EEService.restart_service(self, 'php5.6-fpm')
                if EEAptGet.is_installed(self,'php7.0-fpm'):
                    EEService.restart_service(self, 'php7.0-fpm')
            else:
                EEService.restart_service(self, 'php5-fpm')

        if len(self.msg) > 0:
            if not self.app.pargs.interactive:
                disp_msg = ' '.join(self.msg)
                Log.info(self, "Use following command to check debug logs:\n"
                         + Log.ENDC + "tail -f {0}".format(disp_msg))
            else:
                signal.signal(signal.SIGINT, self.signal_handler)
                watch_list = []
                for w_list in self.msg:
                    watch_list = watch_list + glob.glob(w_list)

                logwatch(self, watch_list)
Beispiel #18
0
    def default(self):
        """Default function of debug"""
        self.start = True
        self.interactive = False
        self.msg = []
        self.trigger_nginx = False
        self.trigger_php = False

        if self.app.pargs.stop:
            self.start = False

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
           and (not self.app.pargs.fpm) and (not self.app.pargs.mysql)
           and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
           and (not self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.rewrite = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
           and (not self.app.pargs.fpm) and (not self.app.pargs.mysql)
           and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
           and self.app.pargs.site_name):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.rewrite = True

        if self.app.pargs.nginx:
            self.debug_nginx()
        if self.app.pargs.php:
            self.debug_php()
        if self.app.pargs.fpm:
            self.debug_fpm()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine will not "
                         "enable remote debug")
        if self.app.pargs.wp:
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.debug_rewrite()

        if self.app.pargs.interactive:
            self.interactive = True

        # Reload Nginx
        if self.trigger_nginx:
            EEService.reload_service(self, 'nginx')
        # Reload PHP
        if self.trigger_php:
            EEService.reload_service(self, 'php5-fpm')

        if len(self.msg) > 0:
            if not self.app.pargs.interactive:
                disp_msg = ' '.join(self.msg)
                Log.info(self, "Use following command to check debug logs:\n"
                         + Log.ENDC + "tail -f {0}".format(disp_msg))
            else:
                signal.signal(signal.SIGINT, self.signal_handler)
                watch_list = []
                for w_list in self.msg:
                    watch_list = watch_list + glob.glob(w_list)

                logwatch(self, watch_list)
Beispiel #19
0
    def default(self):
        """Default function of debug"""
        # self.start = True
        self.interactive = False
        self.msg = []
        self.trigger_nginx = False
        self.trigger_php = False

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
                and (not self.app.pargs.php7) and (not self.app.pargs.fpm)
                and (not self.app.pargs.fpm7) and (not self.app.pargs.mysql)
                and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
                and (not self.app.pargs.all) and (not self.app.pargs.site_name)
                and (not self.app.pargs.import_slow_log)
                and (not self.app.pargs.interval)):
            if self.app.pargs.stop or self.app.pargs.start:
                print("--start/stop option is deprecated since ee3.0.5")
                self.app.args.print_help()
            else:
                self.app.args.print_help()

        if self.app.pargs.import_slow_log:
            self.import_slow_log()

        if self.app.pargs.interval:
            try:
                cron_time = int(self.app.pargs.interval)
            except Exception as e:
                cron_time = 5

            try:
                if not EEShellExec.cmd_exec(
                        self, "crontab -l | grep "
                        "'ee debug --import-slow-log'"):
                    if not cron_time == 0:
                        Log.info(self, "setting up crontab entry,"
                                 " please wait...")
                        EEShellExec.cmd_exec(
                            self, "/bin/bash -c \"crontab -l "
                            "2> /dev/null | {{ cat; echo -e"
                            " \\\"#EasyEngine start MySQL "
                            "slow log \\n*/{0} * * * * "
                            "/usr/local/bin/ee debug"
                            " --import-slow-log\\n"
                            "#EasyEngine end MySQL slow log"
                            "\\\"; }} | crontab -\"".format(cron_time))
                else:
                    if not cron_time == 0:
                        Log.info(self, "updating crontab entry,"
                                 " please wait...")
                        if not EEShellExec.cmd_exec(
                                self, "/bin/bash -c "
                                "\"crontab "
                                "-l | sed '/EasyEngine "
                                "start MySQL slow "
                                "log/!b;n;c\*\/{0} "
                                "\* \* \* "
                                "\* \/usr"
                                "\/local\/bin\/ee debug "
                                "--import\-slow\-log' "
                                "| crontab -\"".format(cron_time)):
                            Log.error(self, "failed to update crontab entry")
                    else:
                        Log.info(self, "removing crontab entry,"
                                 " please wait...")
                        if not EEShellExec.cmd_exec(
                                self, "/bin/bash -c "
                                "\"crontab "
                                "-l | sed '/EasyEngine "
                                "start MySQL slow "
                                "log/,+2d'"
                                "| crontab -\"".format(cron_time)):
                            Log.error(self, "failed to remove crontab entry")
            except CommandExecutionError as e:
                Log.debug(self, str(e))

        if self.app.pargs.all == 'on':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'on'
            self.app.pargs.nginx = 'on'
            self.app.pargs.php = 'on'
            self.app.pargs.fpm = 'on'
            if (EEVariables.ee_platform_codename == 'trusty'
                    or EEVariables.ee_platform_codename
                    == 'bionic') and EEAptGet.is_installed(self, 'php7.2-fpm'):
                self.app.pargs.php7 = 'on'
                self.app.pargs.fpm7 = 'on'
            self.app.pargs.mysql = 'on'
            self.app.pargs.rewrite = 'on'

        if self.app.pargs.all == 'off':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'off'
            self.app.pargs.nginx = 'off'
            self.app.pargs.php = 'off'
            self.app.pargs.fpm = 'off'
            if (EEVariables.ee_platform_codename == 'trusty'
                    or EEVariables.ee_platform_codename
                    == 'bionic') and EEAptGet.is_installed(self, 'php7.2-fpm'):
                self.app.pargs.php7 = 'off'
                self.app.pargs.fpm7 = 'off'
            self.app.pargs.mysql = 'off'
            self.app.pargs.rewrite = 'off'

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
                and (not self.app.pargs.php7) and (not self.app.pargs.fpm)
                and (not self.app.pargs.fpm7) and (not self.app.pargs.mysql)
                and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
                and self.app.pargs.site_name):
            self.app.args.print_help()
            # self.app.pargs.nginx = 'on'
            # self.app.pargs.wp = 'on'
            # self.app.pargs.rewrite = 'on'

        if self.app.pargs.nginx:
            self.debug_nginx()
        if self.app.pargs.php:
            self.debug_php()
        if self.app.pargs.fpm:
            self.debug_fpm()
        if self.app.pargs.php7:
            self.debug_php7()
        if self.app.pargs.fpm7:
            self.debug_fpm7()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(
                    self, "Remote MySQL found, EasyEngine will not "
                    "enable remote debug")
        if self.app.pargs.wp:
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.debug_rewrite()

        if self.app.pargs.interactive:
            self.interactive = True

        # Reload Nginx
        if self.trigger_nginx:
            EEService.reload_service(self, 'nginx')
        # Reload PHP
        if self.trigger_php:
            if (EEVariables.ee_platform_codename == 'trusty'
                    or EEVariables.ee_platform_codename == 'bionic'):
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    EEService.restart_service(self, 'php5.6-fpm')
                if EEAptGet.is_installed(self, 'php7.2-fpm'):
                    EEService.restart_service(self, 'php7.2-fpm')
            else:
                EEService.restart_service(self, 'php5-fpm')
                if EEVariables.ee_platform_codename == 'jessie':
                    EEService.restart_service(self, 'php7.2-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)
Beispiel #20
0
    def default(self):
        """Default function of log reset"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (not self.app.pargs.site_name)
           and (not self.app.pargs.slow_log_db)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True
            self.app.pargs.slow_log_db = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (self.app.pargs.site_name)
           and (not self.app.pargs.slow-log-db)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.slow_log_db:
            if os.path.isdir("/var/www/22222/htdocs/db/anemometer"):
                Log.info(self, "Resetting MySQL slow_query_log database table")
                EEMysql.execute(self, "TRUNCATE TABLE  "
                                "slow_query_log.global_query_review_history")
                EEMysql.execute(self, "TRUNCATE TABLE "
                                "slow_query_log.global_query_review")

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php5/slow.log', 'a').close()
            open('/var/log/php5/fpm.log', 'a').close()
            self.msg = self.msg + ['/var/log/php5/slow.log',
                                   '/var/log/php5/fpm.log']
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine is not able to"
                         "show MySQL log file")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(EEVariables.ee_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + ["{0}/{1}/logs/access.log"
                                       .format(EEVariables.ee_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.nginx:
                self.msg = self.msg + ["{0}/{1}/logs/error.log"
                                       .format(EEVariables.ee_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile('{0}/logs/debug.log'
                                          .format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log"
                                 .format(webroot),
                                 encoding='utf-8', mode='a').close()
                            EEShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/"
                                                 "wp-content/debug.log"
                                                 "".format(webroot,
                                                           EEVariables
                                                           .ee_php_user)
                                                 )
                    # create symbolic link for debug log
                    EEFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/"
                                                      "debug.log"
                                                      .format(webroot),
                                                      '{0}/logs/debug.log'
                                                      .format(webroot)])

                    self.msg = self.msg + ["{0}/{1}/logs/debug.log"
                                           .format(EEVariables.ee_webroot,
                                                   self.app.pargs.site_name)]
                else:
                    Log.info(self, "Site is not WordPress site, skipping "
                             "WordPress logs")

        reset_list = []
        for r_list in self.msg:
            reset_list = reset_list + glob.glob(r_list)

        # Clearing content of file
        for r_list in reset_list:
            Log.info(self, "Resetting file {file}".format(file=r_list))
            open(r_list, 'w').close()
    def stop(self):
        """Stop services"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php
                or self.app.pargs.mysql or self.app.pargs.postfix
                or self.app.pargs.hhvm or self.app.pargs.memcache
                or self.app.pargs.dovecot or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True

        if self.app.pargs.nginx:
            if EEAptGet.is_installed(self, 'nginx-custom') or EEAptGet.is_installed(self,'nginx-mainline'):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if self.app.pargs.php:
            if EEAptGet.is_installed(self, 'php5-fpm'):
                services = services + ['php5-fpm']
            else:
                Log.info(self, "PHP5-FPM is not installed")

        if self.app.pargs.mysql:
            if ((EEVariables.ee_mysql_host is "localhost") or
               (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server') or
                   EEAptGet.is_installed(self, 'percona-server-server-5.6') or
                   EEAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(self, "Remote MySQL found, "
                         "Unable to check MySQL service status")

        if self.app.pargs.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

        if self.app.pargs.hhvm:
            if EEAptGet.is_installed(self, 'hhvm'):
                services = services + ['hhvm']
            else:
                Log.info(self, "HHVM is not installed")
        if self.app.pargs.memcache:
            if EEAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcache is not installed")

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        for service in services:
            Log.debug(self, "Stopping service: {0}".format(service))
            EEService.stop_service(self, service)
Beispiel #22
0
    def default(self):
        """Default function of debug"""
        # self.start = True
        self.interactive = False
        self.msg = []
        self.trigger_nginx = False
        self.trigger_php = False

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
           and (not self.app.pargs.fpm) and (not self.app.pargs.mysql)
           and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
           and (not self.app.pargs.all)
           and (not self.app.pargs.site_name)):
            if self.app.pargs.stop or self.app.pargs.start:
                print("--start/stop option is deprecated since ee3.0.5")
                self.app.args.print_help()
            else:
                self.app.args.print_help()

        if self.app.pargs.all == 'on':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'on'
            self.app.pargs.nginx = 'on'
            self.app.pargs.php = 'on'
            self.app.pargs.fpm = 'on'
            self.app.pargs.mysql = 'on'
            self.app.pargs.rewrite = 'on'

        if self.app.pargs.all == 'off':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'off'
            self.app.pargs.nginx = 'off'
            self.app.pargs.php = 'off'
            self.app.pargs.fpm = 'off'
            self.app.pargs.mysql = 'off'
            self.app.pargs.rewrite = 'off'

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
           and (not self.app.pargs.fpm) and (not self.app.pargs.mysql)
           and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
           and self.app.pargs.site_name):
            self.app.args.print_help()
            # self.app.pargs.nginx = 'on'
            # self.app.pargs.wp = 'on'
            # self.app.pargs.rewrite = 'on'

        if self.app.pargs.nginx:
            self.debug_nginx()
        if self.app.pargs.php:
            self.debug_php()
        if self.app.pargs.fpm:
            self.debug_fpm()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine will not "
                         "enable remote debug")
        if self.app.pargs.wp:
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.debug_rewrite()

        if self.app.pargs.interactive:
            self.interactive = True

        # Reload Nginx
        if self.trigger_nginx:
            EEService.reload_service(self, 'nginx')
        # Reload PHP
        if self.trigger_php:
            EEService.restart_service(self, 'php5-fpm')

        if len(self.msg) > 0:
            if not self.app.pargs.interactive:
                disp_msg = ' '.join(self.msg)
                Log.info(self, "Use following command to check debug logs:\n"
                         + Log.ENDC + "tail -f {0}".format(disp_msg))
            else:
                signal.signal(signal.SIGINT, self.signal_handler)
                watch_list = []
                for w_list in self.msg:
                    watch_list = watch_list + glob.glob(w_list)

                logwatch(self, watch_list)
    def status(self):
        """Status of services"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php7
                or self.app.pargs.mysql or self.app.pargs.postfix
                or self.app.pargs.hhvm or self.app.pargs.memcache
                or self.app.pargs.dovecot or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True
            self.app.pargs.hhvm = True

        if self.app.pargs.nginx:
            if EEAptGet.is_installed(self, 'nginx-custom') or EEAptGet.is_installed(self,'nginx-mainline'):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if self.app.pargs.php:
            if (EEVariables.ee_platform_distro == 'debian' or EEVariables.ee_platform_codename == 'precise'):
                if EEAptGet.is_installed(self, 'php5-fpm'):
                    services = services + ['php5-fpm']
                else:
                    Log.info(self, "PHP5-FPM is not installed")
            else:
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    services = services + ['php5.6-fpm']
                else:
                    Log.info(self, "PHP5.6-FPM is not installed")

                if EEAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")

        if self.app.pargs.php7:
            if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial'):
                if EEAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")
            else:
                Log.info(self, "Your platform does not support PHP 7")

        if self.app.pargs.mysql:
            if ((EEVariables.ee_mysql_host is "localhost") or
               (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server') or
                   EEAptGet.is_installed(self, 'percona-server-server-5.6') or
                   EEAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(self, "Remote MySQL found, "
                         "Unable to check MySQL service status")

        if self.app.pargs.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

        if self.app.pargs.hhvm:
            if EEAptGet.is_installed(self, 'hhvm'):
                services = services + ['hhvm']
            else:
                Log.info(self, "HHVM is not installed")
        if self.app.pargs.memcache:
            if EEAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcache is not installed")

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        for service in services:
            if EEService.get_service_status(self, service):
                Log.info(self, "{0:10}:  {1}".format(service, "Running"))
Beispiel #24
0
    def default(self):
        """Default function of debug"""
        self.start = True
        self.interactive = False
        self.msg = []
        self.trigger_nginx = False
        self.trigger_php = False

        if self.app.pargs.stop:
            self.start = False

        if (
            (not self.app.pargs.nginx)
            and (not self.app.pargs.php)
            and (not self.app.pargs.fpm)
            and (not self.app.pargs.mysql)
            and (not self.app.pargs.wp)
            and (not self.app.pargs.rewrite)
            and (not self.app.pargs.site_name)
        ):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.rewrite = True

        if (
            (not self.app.pargs.nginx)
            and (not self.app.pargs.php)
            and (not self.app.pargs.fpm)
            and (not self.app.pargs.mysql)
            and (not self.app.pargs.wp)
            and (not self.app.pargs.rewrite)
            and self.app.pargs.site_name
        ):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.rewrite = True

        if self.app.pargs.nginx:
            self.debug_nginx()
        if self.app.pargs.php:
            self.debug_php()
        if self.app.pargs.fpm:
            self.debug_fpm()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine will not " "enable remote debug")
        if self.app.pargs.wp:
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.debug_rewrite()

        if self.app.pargs.interactive:
            self.interactive = True

        # Reload Nginx
        if self.trigger_nginx:
            EEService.reload_service(self, "nginx")
        # Reload PHP
        if self.trigger_php:
            EEService.reload_service(self, "php5-fpm")

        if len(self.msg) > 0:
            if not self.app.pargs.interactive:
                disp_msg = " ".join(self.msg)
                Log.info(
                    self, "Use following command to check debug logs:\n" + Log.ENDC + "tail -f {0}".format(disp_msg)
                )
            else:
                signal.signal(signal.SIGINT, self.signal_handler)
                watch_list = []
                for w_list in self.msg:
                    watch_list = watch_list + glob.glob(w_list)

                logwatch(self, watch_list)
Beispiel #25
0
    def default(self):
        """Default function of log Mail"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (not self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php5/slow.log', 'a').close()
            open('/var/log/php5/fpm.log', 'a').close()
            self.msg = self.msg + ['/var/log/php5/slow.log',
                                   '/var/log/php5/fpm.log']
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine is not able to"
                         "show MySQL log file")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(EEVariables.ee_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + ["{0}/{1}/logs/access.log"
                                       .format(EEVariables.ee_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.nginx:
                self.msg = self.msg + ["{0}/{1}/logs/error.log"
                                       .format(EEVariables.ee_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile('{0}/logs/debug.log'
                                          .format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log"
                                 .format(webroot),
                                 encoding='utf-8', mode='a').close()
                            EEShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/"
                                                 "wp-content/debug.log"
                                                 "".format(webroot,
                                                           EEVariables
                                                           .ee_php_user)
                                                 )
                    # create symbolic link for debug log
                    EEFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/"
                                                      "debug.log"
                                                      .format(webroot),
                                                      '{0}/logs/debug.log'
                                                      .format(webroot)])

                    self.msg = self.msg + ["{0}/{1}/logs/debug.log"
                                           .format(EEVariables.ee_webroot,
                                                   self.app.pargs.site_name)]
                else:
                    Log.info(self, "Site is not WordPress site, skipping "
                             "WordPress logs")

        mail_list = []
        for m_list in self.msg:
            mail_list = mail_list + glob.glob(m_list)

        for tomail in self.app.pargs.to:
            Log.info(self, "Sending mail to {0}".format(tomail[0]))
            EESendMail("easyengine", tomail[0], "{0} Log Files"
                       .format(EEVariables.ee_fqdn),
                       "Hey Hi,\n  Please find attached server log files"
                       "\n\n\nYour's faithfully,\nEasyEngine",
                       files=mail_list, port=25, isTls=False)
Beispiel #26
0
    def default(self):
        """Default function of log Mail"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp)
                and (not self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php5/slow.log', 'a').close()
            open('/var/log/php5/fpm.log', 'a').close()
            self.msg = self.msg + [
                '/var/log/php5/slow.log', '/var/log/php5/fpm.log'
            ]
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(
                    self, "Remote MySQL found, EasyEngine is not able to"
                    "show MySQL log file")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(EEVariables.ee_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + [
                    "{0}/{1}/logs/access.log".format(EEVariables.ee_webroot,
                                                     self.app.pargs.site_name)
                ]
            if self.app.pargs.nginx:
                self.msg = self.msg + [
                    "{0}/{1}/logs/error.log".format(EEVariables.ee_webroot,
                                                    self.app.pargs.site_name)
                ]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile(
                            '{0}/logs/debug.log'.format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log".format(
                                webroot),
                                 encoding='utf-8',
                                 mode='a').close()
                            EEShellExec.cmd_exec(
                                self, "chown {1}: {0}/htdocs/"
                                "wp-content/debug.log"
                                "".format(webroot, EEVariables.ee_php_user))
                    # create symbolic link for debug log
                    EEFileUtils.create_symlink(self, [
                        "{0}/htdocs/wp-content/"
                        "debug.log".format(webroot),
                        '{0}/logs/debug.log'.format(webroot)
                    ])

                    self.msg = self.msg + [
                        "{0}/{1}/logs/debug.log".format(
                            EEVariables.ee_webroot, self.app.pargs.site_name)
                    ]
                else:
                    Log.info(
                        self, "Site is not WordPress site, skipping "
                        "WordPress logs")

        mail_list = []
        for m_list in self.msg:
            mail_list = mail_list + glob.glob(m_list)

        for tomail in self.app.pargs.to:
            Log.info(self, "Sending mail to {0}".format(tomail[0]))
            EESendMail("easyengine",
                       tomail[0],
                       "{0} Log Files".format(EEVariables.ee_fqdn),
                       "Hey Hi,\n  Please find attached server log files"
                       "\n\n\nYour's faithfully,\nEasyEngine",
                       files=mail_list,
                       port=25,
                       isTls=False)
def setupwordpress(self, data):
    ee_domain_name = data["site_name"]
    ee_site_webroot = data["webroot"]
    prompt_wpprefix = self.app.config.get("wordpress", "prefix")
    ee_wp_user = self.app.config.get("wordpress", "user")
    ee_wp_pass = self.app.config.get("wordpress", "password")
    ee_wp_email = self.app.config.get("wordpress", "email")
    # Random characters
    ee_random = "".join(random.sample(string.ascii_uppercase + string.ascii_lowercase + string.digits, 15))
    ee_wp_prefix = ""
    # ee_wp_user = ''
    # ee_wp_pass = ''

    if "wp-user" in data.keys() and data["wp-user"]:
        ee_wp_user = data["wp-user"]
    if "wp-email" in data.keys() and data["wp-email"]:
        ee_wp_email = data["wp-email"]
    if "wp-pass" in data.keys() and data["wp-pass"]:
        ee_wp_pass = data["wp-pass"]

    Log.info(self, "Downloading Wordpress \t\t", end="")
    EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot))
    try:
        if EEShellExec.cmd_exec(self, "wp --allow-root core" " download"):
            pass
        else:
            Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]")
            raise SiteError("download wordpress core failed")
    except CommandExecutionError as e:
        Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]")
        raise SiteError(self, "download wordpress core failed")

    Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")

    if not (data["ee_db_name"] and data["ee_db_user"] and data["ee_db_pass"]):
        data = setupdatabase(self, data)
    if prompt_wpprefix == "True" or prompt_wpprefix == "true":
        try:
            ee_wp_prefix = input("Enter the WordPress table prefix [wp_]: ")
            while not re.match("^[A-Za-z0-9_]*$", ee_wp_prefix):
                Log.warn(self, "table prefix can only " "contain numbers, letters, and underscores")
                ee_wp_prefix = input("Enter the WordPress table prefix [wp_]: ")
        except EOFError as e:
            Log.debug(self, "{0}".format(e))
            raise SiteError("input table prefix failed")

    if not ee_wp_prefix:
        ee_wp_prefix = "wp_"

    # Modify wp-config.php & move outside the webroot

    EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot))
    Log.debug(self, "Setting up wp-config file")
    if not data["multisite"]:
        Log.debug(self, "Generating wp-config for WordPress Single site")
        Log.debug(
            self,
            'bash -c "php {0} --allow-root '.format(EEVariables.ee_wpcli_path)
            + "core config "
            + "--dbname='{0}' --dbprefix='{1}' --dbuser='******' "
            "--dbhost='{3}' ".format(data["ee_db_name"], ee_wp_prefix, data["ee_db_user"], data["ee_db_host"])
            + "--dbpass= "******"'.format(data["ee_db_pass"], "\n\ndefine('WP_DEBUG', false);"),
        )
        try:
            if EEShellExec.cmd_exec(
                self,
                'bash -c "php {0} --allow-root'.format(EEVariables.ee_wpcli_path)
                + " core config "
                + "--dbname='{0}' --dbprefix='{1}' "
                "--dbuser='******' --dbhost='{3}' ".format(
                    data["ee_db_name"], ee_wp_prefix, data["ee_db_user"], data["ee_db_host"]
                )
                + "--dbpass='******' "
                '--extra-php<<PHP \n {1} {redissalt}\nPHP"'.format(
                    data["ee_db_pass"],
                    "\n\ndefine('WP_DEBUG', false);",
                    redissalt="\n\ndefine( 'WP_CACHE_KEY_SALT', '{0}:' );".format(ee_domain_name)
                    if data["wpredis"]
                    else "",
                ),
                log=False,
            ):
                pass
            else:
                raise SiteError("generate wp-config failed for wp single site")
        except CommandExecutionError as e:
            raise SiteError("generate wp-config failed for wp single site")
    else:
        Log.debug(self, "Generating wp-config for WordPress multisite")
        Log.debug(
            self,
            'bash -c "php {0} --allow-root '.format(EEVariables.ee_wpcli_path)
            + "core config "
            + "--dbname='{0}' --dbprefix='{1}' --dbhost='{2}' ".format(
                data["ee_db_name"], ee_wp_prefix, data["ee_db_host"]
            )
            + "--dbuser='******' --dbpass= "******"'.format(
                data["ee_db_user"],
                data["ee_db_pass"],
                "\ndefine('WP_ALLOW_MULTISITE', " "true);",
                "\ndefine('WPMU_ACCEL_REDIRECT'," " true);",
                "\n\ndefine('WP_DEBUG', false);",
            ),
        )
        try:
            if EEShellExec.cmd_exec(
                self,
                'bash -c "php {0} --allow-root'.format(EEVariables.ee_wpcli_path)
                + " core config "
                + "--dbname='{0}' --dbprefix='{1}' "
                "--dbhost='{2}' ".format(data["ee_db_name"], ee_wp_prefix, data["ee_db_host"])
                + "--dbuser='******' --dbpass='******' "
                '--extra-php<<PHP \n {2} {3} {4} {redissalt}\nPHP"'.format(
                    data["ee_db_user"],
                    data["ee_db_pass"],
                    "\ndefine('WP_ALLOW_MULTISITE', " "true);",
                    "\ndefine('WPMU_ACCEL_REDIRECT'," " true);",
                    "\n\ndefine('WP_DEBUG', false);",
                    redissalt="\n\ndefine( 'WP_CACHE_KEY_SALT', '{0}:' );".format(ee_domain_name)
                    if data["wpredis"]
                    else "",
                ),
                log=False,
            ):
                pass
            else:
                raise SiteError("generate wp-config failed for wp multi site")
        except CommandExecutionError as e:
            raise SiteError("generate wp-config failed for wp multi site")

    # EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php',
    #                   os.path.abspath(os.path.join(os.getcwd(), os.pardir)))

    try:
        import shutil

        Log.debug(
            self,
            "Moving file from {0} to {1}".format(
                os.getcwd() + "/wp-config.php", os.path.abspath(os.path.join(os.getcwd(), os.pardir))
            ),
        )
        shutil.move(os.getcwd() + "/wp-config.php", os.path.abspath(os.path.join(os.getcwd(), os.pardir)))
    except Exception as e:
        Log.error(
            self,
            "Unable to move file from {0} to {1}".format(
                os.getcwd() + "/wp-config.php", os.path.abspath(os.path.join(os.getcwd(), os.pardir))
            ),
            False,
        )
        raise SiteError("Unable to move wp-config.php")

    if not ee_wp_user:
        ee_wp_user = EEVariables.ee_user
        while not ee_wp_user:
            Log.warn(
                self,
                "Username can have only alphanumeric"
                "characters, spaces, underscores, hyphens,"
                "periods and the @ symbol.",
            )
            try:
                ee_wp_user = input("Enter WordPress username: "******"{0}".format(e))
                raise SiteError("input wordpress username failed")
    if not ee_wp_pass:
        ee_wp_pass = ee_random

    if not ee_wp_email:
        ee_wp_email = EEVariables.ee_email
        while not ee_wp_email:
            try:
                ee_wp_email = input("Enter WordPress email: ")
            except EOFError as e:
                Log.debug(self, "{0}".format(e))
                raise SiteError("input wordpress username failed")

    try:
        while not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", ee_wp_email):
            Log.info(self, "EMail not Valid in config, " "Please provide valid email id")
            ee_wp_email = input("Enter your email: ")
    except EOFError as e:
        Log.debug(self, "{0}".format(e))
        raise SiteError("input WordPress user email failed")

    Log.debug(self, "Setting up WordPress tables")

    if not data["multisite"]:
        Log.debug(self, "Creating tables for WordPress Single site")
        Log.debug(
            self,
            "php {0} --allow-root core install ".format(EEVariables.ee_wpcli_path)
            + "--url='{0}' --title='{0}' --admin_name='{1}' ".format(data["www_domain"], ee_wp_user)
            + "--admin_password= --admin_email='{1}'".format(ee_wp_pass, ee_wp_email),
        )
        try:
            if EEShellExec.cmd_exec(
                self,
                "php {0} --allow-root core ".format(EEVariables.ee_wpcli_path) + "install --url='{0}' --title='{0}' "
                "--admin_name='{1}' ".format(data["www_domain"], ee_wp_user) + "--admin_password='******' "
                "--admin_email='{1}'".format(ee_wp_pass, ee_wp_email),
                log=False,
            ):
                pass
            else:
                raise SiteError("setup wordpress tables failed for single site")
        except CommandExecutionError as e:
            raise SiteError("setup wordpress tables failed for single site")
    else:
        Log.debug(self, "Creating tables for WordPress multisite")
        Log.debug(
            self,
            "php {0} --allow-root ".format(EEVariables.ee_wpcli_path) + "core multisite-install "
            "--url='{0}' --title='{0}' --admin_name='{1}' ".format(data["www_domain"], ee_wp_user)
            + "--admin_password= --admin_email='{1}' "
            "{subdomains}".format(ee_wp_pass, ee_wp_email, subdomains="--subdomains" if not data["wpsubdir"] else ""),
        )
        try:
            if EEShellExec.cmd_exec(
                self,
                "php {0} --allow-root ".format(EEVariables.ee_wpcli_path) + "core multisite-install "
                "--url='{0}' --title='{0}' "
                "--admin_name='{1}' ".format(data["www_domain"], ee_wp_user) + "--admin_password='******' "
                "--admin_email='{1}' "
                "{subdomains}".format(
                    ee_wp_pass, ee_wp_email, subdomains="--subdomains" if not data["wpsubdir"] else ""
                ),
                log=False,
            ):
                pass
            else:
                raise SiteError("setup wordpress tables failed for wp multi site")
        except CommandExecutionError as e:
            raise SiteError("setup wordpress tables failed for wp multi site")

    Log.debug(self, "Updating WordPress permalink")
    try:
        EEShellExec.cmd_exec(
            self,
            " php {0} --allow-root ".format(EEVariables.ee_wpcli_path) + "rewrite structure "
            "/%year%/%monthnum%/%day%/%postname%/",
        )
    except CommandExecutionError as e:
        raise SiteError("Update wordpress permalinks failed")

    """Install nginx-helper plugin """
    installwp_plugin(self, "nginx-helper", data)
    if data["wpfc"]:
        plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_fastcgi","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
        setupwp_plugin(self, "nginx-helper", "rt_wp_nginx_helper_options", plugin_data, data)
    elif data["wpredis"]:
        plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
        setupwp_plugin(self, "nginx-helper", "rt_wp_nginx_helper_options", plugin_data, data)

    """Install Wp Super Cache"""
    if data["wpsc"]:
        installwp_plugin(self, "wp-super-cache", data)

    """Install Redis Cache"""
    if data["wpredis"]:
        installwp_plugin(self, "redis-cache", data)

    """Install W3 Total Cache"""
    if data["w3tc"] or data["wpfc"]:
        installwp_plugin(self, "w3-total-cache", data)

    wp_creds = dict(wp_user=ee_wp_user, wp_pass=ee_wp_pass, wp_email=ee_wp_email)

    return wp_creds
Beispiel #28
0
    def default(self):
        """Default function of log reset"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (not self.app.pargs.site_name)
                and (not self.app.pargs.slow_log_db)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True
            self.app.pargs.slow_log_db = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (self.app.pargs.site_name)
                and (not self.app.pargs.slow - log - db)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.slow_log_db:
            if os.path.isdir("/var/www/22222/htdocs/db/anemometer"):
                Log.info(self, "Resetting MySQL slow_query_log database table")
                EEMysql.execute(
                    self, "TRUNCATE TABLE  "
                    "slow_query_log.global_query_review_history")
                EEMysql.execute(
                    self, "TRUNCATE TABLE "
                    "slow_query_log.global_query_review")

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php5/slow.log', 'a').close()
            open('/var/log/php5/fpm.log', 'a').close()
            self.msg = self.msg + [
                '/var/log/php5/slow.log', '/var/log/php5/fpm.log'
            ]
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(
                    self, "Remote MySQL found, EasyEngine is not able to"
                    "show MySQL log file")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(EEVariables.ee_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + [
                    "{0}/{1}/logs/access.log".format(EEVariables.ee_webroot,
                                                     self.app.pargs.site_name)
                ]
            if self.app.pargs.nginx:
                self.msg = self.msg + [
                    "{0}/{1}/logs/error.log".format(EEVariables.ee_webroot,
                                                    self.app.pargs.site_name)
                ]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile(
                            '{0}/logs/debug.log'.format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log".format(
                                webroot),
                                 encoding='utf-8',
                                 mode='a').close()
                            EEShellExec.cmd_exec(
                                self, "chown {1}: {0}/htdocs/"
                                "wp-content/debug.log"
                                "".format(webroot, EEVariables.ee_php_user))
                    # create symbolic link for debug log
                    EEFileUtils.create_symlink(self, [
                        "{0}/htdocs/wp-content/"
                        "debug.log".format(webroot),
                        '{0}/logs/debug.log'.format(webroot)
                    ])

                    self.msg = self.msg + [
                        "{0}/{1}/logs/debug.log".format(
                            EEVariables.ee_webroot, self.app.pargs.site_name)
                    ]
                else:
                    Log.info(
                        self, "Site is not WordPress site, skipping "
                        "WordPress logs")

        reset_list = []
        for r_list in self.msg:
            reset_list = reset_list + glob.glob(r_list)

        # Clearing content of file
        for r_list in reset_list:
            Log.info(self, "Resetting file {file}".format(file=r_list))
            open(r_list, 'w').close()
Beispiel #29
0
def setupwordpress(self, data):
    ee_domain_name = data['site_name']
    ee_site_webroot = data['webroot']
    prompt_wpprefix = self.app.config.get('wordpress', 'prefix')
    ee_wp_user = self.app.config.get('wordpress', 'user')
    ee_wp_pass = self.app.config.get('wordpress', 'password')
    ee_wp_email = self.app.config.get('wordpress', 'email')
    # Random characters
    ee_random = (''.join(random.sample(string.ascii_uppercase +
                 string.ascii_lowercase + string.digits, 15)))
    ee_wp_prefix = ''
    # ee_wp_user = ''
    # ee_wp_pass = ''

    Log.info(self, "Downloading Wordpress \t\t", end='')
    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    EEShellExec.cmd_exec(self, "wp --allow-root core download")
    Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")

    if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']):
        data = setupdatabase(self, data)
    if prompt_wpprefix == 'True' or prompt_wpprefix == 'true':
        try:
            ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ')
            while not re.match('^[A-Za-z0-9_]*$', ee_wp_prefix):
                Log.warn(self, "table prefix can only "
                         "contain numbers, letters, and underscores")
                ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: '
                                     )
        except EOFError as e:
            Log.debug(self, "{0}".format(e))
            Log.error(self, "Unable to input table prefix")

    if not ee_wp_prefix:
        ee_wp_prefix = 'wp_'

    # Modify wp-config.php & move outside the webroot

    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
    Log.debug(self, "Setting up wp-config file")
    if not data['multisite']:
        Log.debug(self, "Generating wp-config for WordPress Single site")
        Log.debug(self, "bash -c \"php /usr/bin/wp --allow-root "
                  + "core config "
                  + "--dbname=\'{0}\' --dbprefix=\'{1}\' --dbuser=\'{2}\' "
                  "--dbhost=\'{3}\' "
                  .format(data['ee_db_name'], ee_wp_prefix,
                          data['ee_db_user'], data['ee_db_host'])
                  + "--dbpass= "******"--extra-php<<PHP \n {1}\nPHP\""
                  .format(data['ee_db_pass'],
                          "\n\ndefine(\'WP_DEBUG\', false);"))
        EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root "
                             + "core config "
                             + "--dbname=\'{0}\' --dbprefix=\'{1}\' "
                             "--dbuser=\'{2}\' --dbhost=\'{3}\' "
                             .format(data['ee_db_name'], ee_wp_prefix,
                                     data['ee_db_user'], data['ee_db_host'])
                             + "--dbpass=\'{0}\' "
                               "--extra-php<<PHP \n {1}\nPHP\""
                               .format(data['ee_db_pass'],
                                       "\n\ndefine(\'WP_DEBUG\', false);"),
                               log=False
                             ) or Log.error(self,
                                            "Unable to Generate "
                                            "wp-config")
    else:
        Log.debug(self, "Generating wp-config for WordPress multisite")
        Log.debug(self, "bash -c \"php /usr/bin/wp --allow-root "
                  + "core config "
                  + "--dbname=\'{0}\' --dbprefix=\'{1}\' --dbhost=\'{2}\' "
                  .format(data['ee_db_name'], ee_wp_prefix, data['ee_db_host'])
                  + "--dbuser=\'{0}\' --dbpass= "******"--extra-php<<PHP \n {2} {3} {4}\nPHP\""
                  .format(data['ee_db_user'], data['ee_db_pass'],
                          "\ndefine(\'WP_ALLOW_MULTISITE\', "
                          "true);",
                          "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
                          " true);",
                          "\n\ndefine(\'WP_DEBUG\', false);"))
        EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root "
                             + "core config "
                             + "--dbname=\'{0}\' --dbprefix=\'{1}\' "
                             "--dbhost=\'{2}\' "
                             .format(data['ee_db_name'], ee_wp_prefix,
                                     data['ee_db_host'])
                             + "--dbuser=\'{0}\' --dbpass=\'{1}\' "
                               "--extra-php<<PHP \n {2} {3} {4}\nPHP\""
                             .format(data['ee_db_user'], data['ee_db_pass'],
                                     "\ndefine(\'WP_ALLOW_MULTISITE\', "
                                     "true);",
                                     "\ndefine(\'WPMU_ACCEL_REDIRECT\',"
                                     " true);",
                                     "\n\ndefine(\'WP_DEBUG\', false);"),
                             log=False
                             ) or Log.error(self,
                                            "Unable to Generate "
                                            "wp-config")
    EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php',
                       os.path.abspath(os.path.join(os.getcwd(), os.pardir)))

    if not ee_wp_user:
        ee_wp_user = EEVariables.ee_user
        while not ee_wp_user:
            Log.warn(self, "Username can have only alphanumeric"
                     "characters, spaces, underscores, hyphens,"
                     "periods and the @ symbol.")
            try:
                ee_wp_user = input('Enter WordPress username: '******'Enter WordPress email: ')
            except EOFError as e:
                Log.debug(self, "{0}".format(e))
                Log.error(self, "Unable to input WordPress user email")

    try:
        while not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
                           ee_wp_email):
            Log.info(self, "EMail not Valid in config, "
                     "Please provide valid email id")
            ee_wp_email = input("Enter your email: ")
    except EOFError as e:
        Log.debug(self, "{0}".format(e))
        Log.error(self, "Unable to input WordPress user email")

    Log.debug(self, "Setting up WordPress tables")

    if not data['multisite']:
        Log.debug(self, "Creating tables for WordPress Single site")
        Log.debug(self, "php /usr/bin/wp --allow-root core install "
                  "--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' "
                  .format(data['www_domain'], ee_wp_user)
                  + "--admin_password= --admin_email=\'{1}\'"
                  .format(ee_wp_pass, ee_wp_email))
        EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core install "
                             "--url=\'{0}\' --title=\'{0}\' "
                             "--admin_name=\'{1}\' "
                             .format(data['www_domain'], ee_wp_user)
                             + "--admin_password=\'{0}\' --admin_email=\'{1}\'"
                             .format(ee_wp_pass, ee_wp_email),
                             errormsg="Unable to setup WordPress Tables",
                             log=False) or Log.error(self,
                                                     "Unable to setup "
                                                     "WordPress Tables")
    else:
        Log.debug(self, "Creating tables for WordPress multisite")
        Log.debug(self, "php /usr/bin/wp --allow-root "
                  "core multisite-install "
                  "--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' "
                  .format(data['www_domain'], ee_wp_user)
                  + "--admin_password= --admin_email=\'{1}\' "
                  "{subdomains}"
                  .format(ee_wp_pass, ee_wp_email,
                          subdomains='--subdomains'
                          if not data['wpsubdir'] else ''))
        EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root "
                             "core multisite-install "
                             "--url=\'{0}\' --title=\'{0}\' "
                             "--admin_name=\'{1}\' "
                             .format(data['www_domain'], ee_wp_user)
                             + "--admin_password=\'{0}\' "
                             "--admin_email=\'{1}\' "
                             "{subdomains}"
                             .format(ee_wp_pass, ee_wp_email,
                                     subdomains='--subdomains'
                                     if not data['wpsubdir'] else ''),
                             errormsg="Unable to setup WordPress Tables",
                             log=False) or Log.error(self,
                                                     "Unable to setup "
                                                     "WordPress Tables")

    Log.debug(self, "Updating WordPress permalink")
    EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root "
                         "rewrite structure "
                         "/%year%/%monthnum%/%day%/%postname%/",
                         errormsg="Unable to Update WordPress permalink")

    """Install nginx-helper plugin """
    installwp_plugin(self, 'nginx-helper', data)

    """Install Wp Super Cache"""
    if data['wpsc']:
        installwp_plugin(self, 'wp-super-cache', data)

    """Install W3 Total Cache"""
    if data['w3tc'] or data['wpfc']:
        installwp_plugin(self, 'w3-total-cache', data)

    wp_creds = dict(wp_user=ee_wp_user, wp_pass=ee_wp_pass,
                    wp_email=ee_wp_email)

    return(wp_creds)
Beispiel #30
0
    def default(self):
        """Default function of log show"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp)
                and (not self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (self.app.pargs.site_name)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php5/slow.log', 'a').close()
            open('/var/log/php5/fpm.log', 'a').close()
            self.msg = self.msg + [
                '/var/log/php5/slow.log', '/var/log/php5/fpm.log'
            ]
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(
                    self, "Remote MySQL found, EasyEngine is not able to"
                    "show MySQL log file")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(EEVariables.ee_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + [
                    "{0}/{1}/logs/access.log".format(EEVariables.ee_webroot,
                                                     self.app.pargs.site_name)
                ]
            if self.app.pargs.nginx:
                self.msg = self.msg + [
                    "{0}/{1}/logs/error.log".format(EEVariables.ee_webroot,
                                                    self.app.pargs.site_name)
                ]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile(
                            '{0}/logs/debug.log'.format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log".format(
                                webroot),
                                 encoding='utf-8',
                                 mode='a').close()
                            EEShellExec.cmd_exec(
                                self, "chown {1}: {0}/htdocs/"
                                "wp-content/debug.log"
                                "".format(webroot, EEVariables.ee_php_user))
                    # create symbolic link for debug log
                    EEFileUtils.create_symlink(self, [
                        "{0}/htdocs/wp-content/"
                        "debug.log".format(webroot),
                        '{0}/logs/debug.log'.format(webroot)
                    ])

                    self.msg = self.msg + [
                        "{0}/{1}/logs/debug.log".format(
                            EEVariables.ee_webroot, self.app.pargs.site_name)
                    ]
                else:
                    Log.info(
                        self, "Site is not WordPress site, skipping "
                        "WordPress logs")

        watch_list = []
        for w_list in self.msg:
            watch_list = watch_list + glob.glob(w_list)

        logwatch(self, watch_list)
Beispiel #31
0
def updatewpuserpassword(self, ee_domain, ee_site_webroot):

    ee_wp_user = ''
    ee_wp_pass = ''
    EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))

    # Check if ee_domain is wordpress install
    try:
        is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core"
                                     " version")
    except CommandExecutionError as e:
        raise SiteError("is wordpress site? check command failed ")

    # Exit if ee_domain is not wordpress install
    if not is_wp:
        Log.error(self, "{0} does not seem to be a WordPress site"
                  .format(ee_domain))

    try:
        ee_wp_user = input("Provide WordPress user name [admin]: ")
    except Exception as e:
        Log.debug(self, "{0}".format(e))
        Log.error(self, "\nCould not update password")

    if ee_wp_user == "?":
        Log.info(self, "Fetching WordPress user list")
        try:
            EEShellExec.cmd_exec(self, "wp --allow-root user list "
                                 "--fields=user_login | grep -v user_login")
        except CommandExecutionError as e:
            raise SiteError("fetch wp userlist command failed")

    if not ee_wp_user:
        ee_wp_user = '******'

    try:
        is_user_exist = EEShellExec.cmd_exec(self, "wp --allow-root user list "
                                             "--fields=user_login | grep {0}$ "
                                             .format(ee_wp_user))
    except CommandExecutionError as e:
        raise SiteError("if wp user exists check command failed")

    if is_user_exist:
        try:
            ee_wp_pass = getpass.getpass(prompt="Provide password for "
                                         "{0} user: "******"{0}".format(e))
            raise SiteError("failed to read password input ")

        try:
            EEShellExec.cmd_exec(self, "wp --allow-root user update {0}"
                                 "  --user_pass={1}"
                                 .format(ee_wp_user, ee_wp_pass))
        except CommandExecutionError as e:
            raise SiteError("wp user password update command failed")
        Log.info(self, "Password updated successfully")
        if len(ee_wp_pass) < 8:
            Log.warn(self, "Warning: You have provided a "
                     "weak password")
    else:
        Log.error(self, "Invalid WordPress user {0} for {1}."
                  .format(ee_wp_user, ee_domain))