def RemoveService(self, ServiceName, ServicePath):
     app = ServiceManager(ServiceName)
     count = 0
     if False == app.is_exists():
         self.trigger.emit({'info': '%s服务已删除!' % ServiceName})
         return True
     while True:
         if count > 5:
             self.trigger.emit({'info': '%s服务已标记为删除,请稍后再查看!' % ServiceName})
             return False
         if False == app.is_exists():
             self.trigger.emit({'info': '%s服务已删除!' % ServiceName})
             return True
         cmd = '{0} remove'.format(os.path.join(self.local, ServicePath))
         os.system(cmd)
         time.sleep(5)
         count = count + 1
         self.trigger.emit(
             {'info': '正在删除%s服务,请稍后..........!' % ServiceName})
 def install_service(self, ServiceName, ServicePath):
     count = 0
     app = ServiceManager(ServiceName)
     self.trigger.emit({'info': '正在%s启动服务,请稍后!............' % ServiceName})
     if False == app.is_exists():
         while True:
             if count > 3:
                 self.trigger.emit({'info':
                                    '%s服务安装失败' % ServiceName})  # 发送信号
                 return False
             cmd = '{0} --startup auto install'.format(
                 os.path.join(self.local, ServicePath))
             os.system(cmd)
             if True == app.is_exists():
                 self.trigger.emit({'info':
                                    '%s服务安装成功' % ServiceName})  # 发送信号
                 break
             time.sleep(5)
             count = count + 1
     self.trigger.emit({'info': '%s服务安装成功' % ServiceName
                        })  # 发送信('PythonService 服务安装成功!')
     if 'RUNNING' not in str(app.status()):
         count = 0
         while True:
             if count > 5:
                 self.trigger.emit({'info':
                                    '%s服务启动失败!' % ServiceName})  # 发送信号
                 return False
             app.restart()
             if 'RUNNING' in str(app.status()):
                 self.trigger.emit({'info': '%s服务启动成功!' % ServiceName})
                 return True
             time.sleep(5)
             count = count + 1
             self.trigger.emit(
                 {'info':
                  '%s服务启动失败,第%d次重试!' % (ServiceName, count)})  # 发送信号
     else:
         self.trigger.emit({'info': '%s服务已启动!' % ServiceName})
         return True
Пример #3
0
 def ProceService(self):
     app = ServiceManager(self.ServiceName)
     if False == app.is_exists():
         self.logger.error('%s not exists' % self.ServiceName)
         return
     app_status = str(app.status())
     self.logger.info('%s status is:%s ' % (self.ServiceName, app_status))
     if 'RUNNING' in app_status:
         return
     else:
         self.logger.info('PythonService is death now reboot............')
         result = str(app.restart())
         self.logger.info('restart %s  result:%s' %
                          (self.ServiceName, result))
 def StopService(self, ServiceName):
     app = ServiceManager(ServiceName)
     self.trigger.emit({'info': '正在停止%s服务,请稍后!............' % ServiceName})
     if False == app.is_exists():
         self.trigger.emit({'info': '%s服务已停止!' % ServiceName})
         # self.trigger.emit({'status': False})  # 发送信号
         return False
     if 'STOPPING' not in str(app.status()):
         while True:
             app.stop()
             if 'STOPPED' in str(app.status()):
                 self.trigger.emit({'info': '%s服务已停止!' % ServiceName})
                 return True
             else:
                 time.sleep(2)
     else:
         self.trigger.emit({'info': '%s服务已停止!' % ServiceName})
         return True
 def Get_Server_Status(self):
     app = ServiceManager('PythonService')
     if False == app.is_exists():
         self.statusBar.showMessage('服务未安装!')
         return
     self.statusBar.showMessage('服务的运行状态为:%s' % app.status())