Esempio n. 1
0
def startServer(brand, name):
    try:
        server1 = Server.getServer(brand, name)
        command.createCommand(server1.host, server1.ssh_port, "service " + server1.type + " start", type="SSH").execute()
        return None
    except Exception as e:
        logging.debug(e)
        raise Exception("startServer: " + str(e))
Esempio n. 2
0
def runScript(script_id, host_id):
    s = Script.getScript(script_id)
    h = Host.getHost(host_id)
    filename = "/tmp/script_" + str(script_id)
    with open(filename, "wb") as file:
        file.write(s.content)
    try:
        command.createCommand(filename, h.ip, h.ssh_port, filename, type="SCP").execute()
        command.createCommand(h.ip, h.ssh_port, "sh " + filename, type="SSH").execute()
        return "success"
    except:
        return "false"
Esempio n. 3
0
def restartServer(brand, name):
    try:
        server1 = Server.getServer(brand, name)
        command.createCommand(server1.host, server1.ssh_port, "service " + server1.type + " restart", type="SSH").execute()
        if (env.config.getboolean("SERVER_RELOAD_SYNC")):
            if checkServer(brand, name):
                return None
            else:
                raise Exception("server not sync")
        else:
            return None
    except Exception as e:
        logging.debug(e)
        raise Exception("restartServer: " + str(e))
Esempio n. 4
0
def importExcel2SQLite3(file, dbname, tablename):
    if not os.path.isdir(os.path.dirname(file) + "/temp/"):
        os.mkdir(os.path.dirname(file) + "/temp/")
        
    csvfile = os.path.dirname(file) + "/temp/" + os.path.basename(file).split(".")[0] + ".csv"
    utils.Excel2CSV(file, csvfile)
    sql = "\".mode csv\" \".import {0} {1}\""
    return createCommand(dbname, sql.format(csvfile, tablename), type="SQLite3_Win32").execute()
Esempio n. 5
0
 def _action(self):
     AbstractAction._action(self)
     # 写入状态到本地和缓存
     self.appdeploy.setAppStatus()
     # 同步packaged 模块目录到各个服务器上    
     # 读取rsync同步结果,如果出现jar,或其他配置文件更新,则重启server
     outdata = command.createCommand(
             self.temp_dir + "/" + self.app_name, self.host, self.app_home, type="RSYNC").execute()
         # subprocess.call(cmd,shell=True)
         # 是否需要reload服务器
     if (env.config.getboolean("SERVER_DEFALUT_RELOAD") or self.checkfileUpdate(outdata, self.ftypes)):
         command.createCommand(self.host, self.ssh_port, "service " + self.server_type + " restart", type="SSH").execute()
         if env.config.getboolean("SERVER_RELOAD_SYNC") and self.port > 0:
             if not utils.check_port(self.host, self.port):
                 raise Exception("server not sync")
             else:
                 logging.debug("server sync")
Esempio n. 6
0
 def _action(self):
     AbstractAction._action(self)
     # 更新本地模块的svn版本
     svn_info = SVNHelper.updateSVN(self.master_svn, self.master_rev)
     m_rev = svn_info.get("Last Changed Rev")
     m_url = svn_info.get("URL")
     self.app.master_rev = m_rev
     self.app.master_url = m_url
     logging.info("Last Changed Rev:" + m_rev)
     # 同步本地模块的svn版本到临时目录
     command.createCommand(self.master_svn, None, self.temp_dir + "/" + self.app_name, type="RSYNC").execute()
                        
     if self.config_svn:
         # 更新本地模块配置的svn版本
         svn_info = SVNHelper.updateSVN(self.config_svn, self.config_rev)
         c_rev = svn_info.get("Last Changed Rev")
         c_url = svn_info.get("URL")
         self.app.config_url = c_url
         self.app.config_rev = c_rev
         logging.info("Last Changed Rev:" + c_rev)               
         # 覆盖临时目录的模块配置
         command.createCommand(self.config_svn + "/*", self.temp_dir + "/" + self.app_name + "/", type="COPY").execute()
Esempio n. 7
0
 def getAppStatus(self):
     # revision = RedisHelper.get(key)
     revision = None
     if (revision):  # 查找缓存
         return utils.loadRet(revision)[2]
     else:
         # 远程读取只读取第一台服务器的信息
         server = self.servers[0]
         path = server.webapp_home + "/" + self.app.getConfig("CONTEXT") + "/" + env.config.get("APP_VERSION_FILE")
         status = {}
         try:
             stdoutdata = command.createCommand(server.host, server.ssh_port, "cat " + path, type="SSH").execute()
             if stdoutdata:
                 status = utils.loadRet(stdoutdata.decode())[2]
                 # 写入缓存以便下次读取
                 # RedisHelper.set(key, formatJsonRet(data=status))
         except Exception as e:
             logging.debug(e)
             logging.debug("getAppStatus Error")
         return status
Esempio n. 8
0
def executeSQL(dbname, file):
    return createCommand(dbname, file, type="SQLite3_Win32").execute()