Ejemplo n.º 1
0
    def SetDataDir(self, get):
        if get.datadir[-1] == '/': get.datadir = get.datadir[0:-1]
        if not os.path.exists(get.datadir):
            public.ExecShell('mkdir -p ' + get.datadir)
        mysqlInfo = self.GetMySQLInfo(get)
        if mysqlInfo['datadir'] == get.datadir:
            return public.returnMsg(False, 'DATABASE_MOVE_RE')

        public.ExecShell('/etc/init.d/mysqld stop')
        public.ExecShell('\cp -a -r ' + mysqlInfo['datadir'] + '/* ' +
                         get.datadir + '/')
        public.ExecShell('chown -R mysql.mysql ' + get.datadir)
        public.ExecShell('chmod -R 755 ' + get.datadir)
        public.ExecShell('rm -f ' + get.datadir + '/*.pid')
        public.ExecShell('rm -f ' + get.datadir + '/*.err')

        public.CheckMyCnf()
        myfile = '/etc/my.cnf'
        mycnf = public.readFile(myfile)
        public.writeFile('/etc/my_backup.cnf', mycnf)
        mycnf = mycnf.replace(mysqlInfo['datadir'], get.datadir)
        public.writeFile(myfile, mycnf)
        public.ExecShell('/etc/init.d/mysqld start')
        result = public.ExecShell('ps aux|grep mysqld|grep -v grep')
        if len(result[0]) > 10:
            public.writeFile('data/datadir.pl', get.datadir)
            return public.returnMsg(True, 'DATABASE_MOVE_SUCCESS')
        else:
            public.ExecShell('pkill -9 mysqld')
            public.writeFile(myfile, public.readFile('/etc/my_backup.cnf'))
            public.ExecShell('/etc/init.d/mysqld start')
            return public.returnMsg(False, 'DATABASE_MOVE_ERR')
Ejemplo n.º 2
0
 def SetDataDir(self,get):
     if get.datadir[-1] == '/': get.datadir = get.datadir[0:-1];
     if os.path.exists(get.datadir): os.system('mkdir -p ' + get.datadir);
     mysqlInfo = self.GetMySQLInfo(get);
     if mysqlInfo['datadir'] == get.datadir: return public.returnMsg(False,'DATABASE_MOVE_RE');
     
     os.system('/etc/init.d/mysqld stop');
     os.system('\cp -a -r ' + mysqlInfo['datadir'] + '/* ' + get.datadir + '/');
     os.system('chown -R mysql.mysql ' + get.datadir);
     os.system('chmod -R 755 ' + get.datadir);
     os.system('rm -f ' + get.datadir + '/*.pid');
     os.system('rm -f ' + get.datadir + '/*.err');
     
     public.CheckMyCnf();
     myfile = '/etc/my.cnf';
     mycnf = public.readFile(myfile);
     public.writeFile('/etc/my_backup.cnf',mycnf);
     mycnf = mycnf.replace(mysqlInfo['datadir'],get.datadir);
     public.writeFile(myfile,mycnf);
     os.system('/etc/init.d/mysqld start');
     result = public.ExecShell('/etc/init.d/mysqld status');
     if result[0].find('SUCCESS') != -1:
         public.writeFile('data/datadir.pl',get.datadir);
         return public.returnMsg(True,'DATABASE_MOVE_SUCCESS');
     else:
         os.system('pkill -9 mysqld');
         public.writeFile(myfile,public.readFile('/etc/my_backup.cnf'));
         os.system('/etc/init.d/mysqld start');
         return public.returnMsg(False,'DATABASE_MOVE_ERR');
Ejemplo n.º 3
0
 def GetMySQLInfo(self, get):
     data = {}
     try:
         public.CheckMyCnf()
         myfile = '/etc/my.cnf'
         mycnf = public.readFile(myfile)
         rep = "datadir\s*=\s*(.+)\n"
         data['datadir'] = re.search(rep, mycnf).groups()[0]
         rep = "port\s*=\s*([0-9]+)\s*\n"
         data['port'] = re.search(rep, mycnf).groups()[0]
     except:
         data['datadir'] = '/www/server/data'
         data['port'] = '3306'
     return data
Ejemplo n.º 4
0
    def ServiceAdmin(self, get=None):
        #服务管理

        if get.name == 'mysqld': public.CheckMyCnf()
        ''' 
        if get.name == 'phpmyadmin':
            import ajax
            get.status = 'True';
            ajax.ajax().setPHPMyAdmin(get);
            return public.returnMsg(True,'SYS_EXEC_SUCCESS');
        
        #检查httpd配置文件
        if get.name == 'apache' or get.name == 'httpd':
            get.name = 'httpd';
            if not os.path.exists(self.setupPath+'/apache/bin/apachectl'): return public.returnMsg(True,'SYS_NOT_INSTALL_APACHE');
            vhostPath = self.setupPath + '/panel/vhost/apache'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath);
                public.ExecShell('/etc/init.d/httpd start');
            
            if get.type == 'start': 
                public.ExecShell('/etc/init.d/httpd stop');
                public.ExecShell('pkill -9 httpd');
                
            result = public.ExecShell('ulimit -n 10240 && ' + self.setupPath+'/apache/bin/apachectl -t');
            if result[1].find('Syntax OK') == -1:
                public.WriteLog("TYPE_SOFT",'SYS_EXEC_ERR', (str(result),));
                return public.returnMsg(False,'SYS_CONF_APACHE_ERR',(result[1].replace("\n",'<br>'),));
            
            if get.type == 'restart':
                public.ExecShell('pkill -9 httpd');
                public.ExecShell('/etc/init.d/httpd start');
            
        #检查nginx配置文件
        elif get.name == 'nginx':
            vhostPath = self.setupPath + '/panel/vhost/rewrite'
            if not os.path.exists(vhostPath): public.ExecShell('mkdir ' + vhostPath);
            vhostPath = self.setupPath + '/panel/vhost/nginx'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath);
                public.ExecShell('/etc/init.d/nginx start');
            
            result = public.ExecShell('ulimit -n 10240 && nginx -t -c '+self.setupPath+'/nginx/conf/nginx.conf');
            if result[1].find('perserver') != -1:
                limit = self.setupPath + '/nginx/conf/nginx.conf';
                nginxConf = public.readFile(limit);
                limitConf = "limit_conn_zone $binary_remote_addr zone=perip:10m;\n\t\tlimit_conn_zone $server_name zone=perserver:10m;";
                nginxConf = nginxConf.replace("#limit_conn_zone $binary_remote_addr zone=perip:10m;",limitConf);
                public.writeFile(limit,nginxConf)
                public.ExecShell('/etc/init.d/nginx start');
                return public.returnMsg(True,'SYS_CONF_NGINX_REP');
            
            if result[1].find('proxy') != -1:
                import panelSite
                panelSite.panelSite().CheckProxy(get);
                public.ExecShell('/etc/init.d/nginx start');
                return public.returnMsg(True,'SYS_CONF_NGINX_REP');
            
            #return result
            if result[1].find('successful') == -1:
                public.WriteLog("TYPE_SOFT",'SYS_EXEC_ERR', (str(result),));
                return public.returnMsg(False,'SYS_CONF_NGINX_ERR',(result[1].replace("\n",'<br>'),));
        '''
        #执行
        execStr = "/etc/init.d/" + get.name + " " + get.type
        if execStr == '/etc/init.d/pure-ftpd reload':
            execStr = self.setupPath + '/pure-ftpd/bin/pure-pw mkdb ' + self.setupPath + '/pure-ftpd/etc/pureftpd.pdb'
        if execStr == '/etc/init.d/pure-ftpd start':
            os.system('pkill -9 pure-ftpd')
        if execStr == '/etc/init.d/tomcat reload':
            execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start'
        if execStr == '/etc/init.d/tomcat restart':
            execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start'

        result = os.system(execStr)
        if get.type != 'test':
            public.WriteLog("TYPE_SOFT", 'SYS_EXEC_SUCCESS', (execStr, ))

        if result == 0:
            return public.returnMsg(True, 'SYS_EXEC_SUCCESS')
        else:
            return public.returnMsg(False, 'PAGE_ERR_500_H1')
Ejemplo n.º 5
0
    def ServiceAdmin(self, get=None):
        #服务管理
        if get.name == 'mysqld':
            public.CheckMyCnf()
            self.__check_mysql_path()
        if get.name.find('webserver') != -1:
            get.name = public.get_webserver()

        if get.name == 'phpmyadmin':
            import ajax
            get.status = 'True'
            ajax.ajax().setPHPMyAdmin(get)
            return public.returnMsg(True, 'SYS_EXEC_SUCCESS')

        if get.name == 'openlitespeed':
            if get.type == 'stop':
                public.ExecShell(
                    'rm -f /tmp/lshttpd/*.sock* && /usr/local/lsws/bin/lswsctrl stop'
                )
            elif get.type == 'start':
                public.ExecShell(
                    'rm -f /tmp/lshttpd/*.sock* && /usr/local/lsws/bin/lswsctrl start'
                )
            else:
                public.ExecShell(
                    'rm -f /tmp/lshttpd/*.sock* && /usr/local/lsws/bin/lswsctrl restart'
                )
            return public.returnMsg(True, 'SYS_EXEC_SUCCESS')

        #检查httpd配置文件
        if get.name == 'apache' or get.name == 'httpd':
            get.name = 'httpd'
            if not os.path.exists(self.setupPath + '/apache/bin/apachectl'):
                return public.returnMsg(True, 'SYS_NOT_INSTALL_APACHE')
            vhostPath = self.setupPath + '/panel/vhost/apache'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath)
                public.ExecShell('/etc/init.d/httpd start')

            if get.type == 'start':
                public.ExecShell('/etc/init.d/httpd stop')
                self.kill_port()

            result = public.ExecShell('ulimit -n 8192 ; ' + self.setupPath +
                                      '/apache/bin/apachectl -t')
            if result[1].find('Syntax OK') == -1:
                public.WriteLog("TYPE_SOFT", 'SYS_EXEC_ERR', (str(result), ))
                return public.returnMsg(False, 'SYS_CONF_APACHE_ERR',
                                        (result[1].replace("\n", '<br>'), ))

            if get.type == 'restart':
                public.ExecShell('pkill -9 httpd')
                public.ExecShell('/etc/init.d/httpd start')
                time.sleep(0.5)

        #检查nginx配置文件
        elif get.name == 'nginx':
            vhostPath = self.setupPath + '/panel/vhost/rewrite'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath)
            vhostPath = self.setupPath + '/panel/vhost/nginx'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath)
                public.ExecShell('/etc/init.d/nginx start')

            result = public.ExecShell('ulimit -n 8192 ; nginx -t -c ' +
                                      self.setupPath +
                                      '/nginx/conf/nginx.conf')
            if result[1].find('perserver') != -1:
                limit = self.setupPath + '/nginx/conf/nginx.conf'
                nginxConf = public.readFile(limit)
                limitConf = "limit_conn_zone $binary_remote_addr zone=perip:10m;\n\t\tlimit_conn_zone $server_name zone=perserver:10m;"
                nginxConf = nginxConf.replace(
                    "#limit_conn_zone $binary_remote_addr zone=perip:10m;",
                    limitConf)
                public.writeFile(limit, nginxConf)
                public.ExecShell('/etc/init.d/nginx start')
                return public.returnMsg(True, 'SYS_CONF_NGINX_REP')

            if result[1].find('proxy') != -1:
                import panelSite
                panelSite.panelSite().CheckProxy(get)
                public.ExecShell('/etc/init.d/nginx start')
                return public.returnMsg(True, 'SYS_CONF_NGINX_REP')

            #return result
            if result[1].find('successful') == -1:
                public.WriteLog("TYPE_SOFT", 'SYS_EXEC_ERR', (str(result), ))
                return public.returnMsg(False, 'SYS_CONF_NGINX_ERR',
                                        (result[1].replace("\n", '<br>'), ))

            if get.type == 'start':
                self.kill_port()
                time.sleep(0.5)
        if get.name == 'redis':
            redis_init = '/etc/init.d/redis'
            if os.path.exists(redis_init):
                init_body = public.ReadFile(redis_init)
                if init_body.find('pkill -9 redis') == -1:
                    public.ExecShell("wget -O " + redis_init + " " +
                                     public.get_url() + '/init/redis.init')
                    public.ExecShell("chmod +x " + redis_init)

        #执行
        execStr = "/etc/init.d/" + get.name + " " + get.type
        if execStr == '/etc/init.d/pure-ftpd reload':
            execStr = self.setupPath + '/pure-ftpd/bin/pure-pw mkdb ' + self.setupPath + '/pure-ftpd/etc/pureftpd.pdb'
        if execStr == '/etc/init.d/pure-ftpd start':
            public.ExecShell('pkill -9 pure-ftpd')
        if execStr == '/etc/init.d/tomcat reload':
            execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start'
        if execStr == '/etc/init.d/tomcat restart':
            execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start'

        if get.name != 'mysqld':
            result = public.ExecShell(execStr)
        else:
            public.ExecShell(execStr)
            result = []
            result.append('')
            result.append('')

        if result[1].find('nginx.pid') != -1:
            public.ExecShell('pkill -9 nginx && sleep 1')
            public.ExecShell('/etc/init.d/nginx start')
        if get.type != 'test':
            public.WriteLog("TYPE_SOFT", 'SYS_EXEC_SUCCESS', (execStr, ))

        if len(result[1]
               ) > 1 and get.name != 'pure-ftpd' and get.name != 'redis':
            return public.returnMsg(
                False,
                '<p>Warning message: <p>' + result[1].replace('\n', '<br>'))
        return public.returnMsg(True, 'SYS_EXEC_SUCCESS')