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
Esempio n. 2
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))