Ejemplo n.º 1
0
 def searchInstance(instance_name):
     try:
         for instance in InstancesConf():
             if instance.name == instance_name:
                 return instance
         return CommandResultFailure("instance %s not found!" % instance_name)
     except IOError as e:
         return CommandResultFailure(e.message)
Ejemplo n.º 2
0
    def isValidInstanceForStart(self):
        if not 0 <= self.instance.process_num < self.instance.number_of_processes:
            return CommandResultFailure("number %d must be between [0..%d)"
                                        % (self.instance.process_num, self.instance.number_of_processes))
        if not self.instance.auto_start and not self.force:
            return CommandResultFailure("not started, because no-auto-start is set")

        return CommandResultSuccess()
Ejemplo n.º 3
0
 def execute(self):
     try:
         self.szig = SZIG(self.instance.process_name)
     except IOError as e:
         return CommandResultFailure(e.message)
     try:
         return self.services()
     except SZIGError as e:
         return CommandResultFailure("error while communicating through szig: %s" % e.msg)
Ejemplo n.º 4
0
    def execute(self):
        error = self.errorHandling()
        if error != None:
            error.value = self.instance.process_name
            return error

        try:
            reloaded = self.reload()
        except SZIGError as e:
            reloaded = CommandResultFailure("error while communicating through szig: %s" % e.msg)
        if not reloaded:
            reloaded.value = self.instance.process_name
        return reloaded
Ejemplo n.º 5
0
    def execute(self):
        error = self.errorHandling()
        if error != None:
            error.value = self.instance.process_name
            return error

        try:
            reloaded = self.reload()
        except SZIGError as e:
            reloaded = CommandResultFailure("error while communicating through szig: %s" % e.msg)
        if not reloaded:
            reloaded.value = self.instance.process_name
        return reloaded
Ejemplo n.º 6
0
 def errorHandling(self):
     running = self.isRunning(self.instance.process_name)
     if not running:
         return running
     try:
         self.stat_file = open(self.proc_stat_filename, 'r')
     except IOError:
         return CommandResultFailure("Can not open %s" % self.proc_stat_filename)
     try:
         uptime_file = open(self.uptime_filename, 'r')
         uptime_file.close()
     except IOError:
         return CommandResultFailure("Can not open %s" % self.uptime_filename)
Ejemplo n.º 7
0
 def reject(self):
     try:
         result = self.szig.authorize_reject(self.session_id,
                                             self.description)
         return CommandResultSuccess(result)
     except SZIGError as e:
         return CommandResultFailure(e.msg)
Ejemplo n.º 8
0
 def reload(self):
     self.szig.reload()
     if self.szig.reload_result():
         result = CommandResultSuccess("Reload successful")
     else:
         result = CommandResultFailure("Reload failed")
     return result
Ejemplo n.º 9
0
    def start_with_systemd(self):
        try:
            subprocess.check_call(
                ['/bin/systemctl', 'start',
                 self.getSystemdServiceName()])
        except:
            return CommandResultFailure(
                "Error invoking 'systemctl start zorp{}@{}.service'".format(
                    Zorp.Config.config.options.package_suffix,
                    self.instance.name))

        running = self.isRunning(self.instance.process_name)
        if running:
            return CommandResultSuccess(running)
        else:
            return CommandResultFailure('Failed to start')
Ejemplo n.º 10
0
 def killProcess(self, sig):
     self.pid = self.getProcessPid(self.instance.process_name)
     try:
         os.kill(self.pid, sig)
         return CommandResultSuccess()
     except OSError as e:
         return CommandResultFailure(e.message)
Ejemplo n.º 11
0
 def removeProcessPid(self, process):
     try:
         file_path = self._getProcessPidPath(process)
         if os.path.exists(file_path):
             os.remove(file_path)
     except IOError as e:
         return CommandResultFailure(
             "Could not remove pid file '{}'".format(file_path), e.message)
Ejemplo n.º 12
0
 def errorHandling(self):
     running = self.isRunning(self.instance.process_name)
     if not running:
         return running
     try:
         self.szig = SZIG(self.instance.process_name)
     except IOError as e:
         return CommandResultFailure(e.message)
Ejemplo n.º 13
0
 def callAlgorithmToAllInstances(algorithm):
     result = []
     try:
         for instance in InstancesConf():
             result += InstanceHandler.executeAlgorithmOnInstanceProcesses(instance, algorithm)
         return result
     except BaseException as e:
         return CommandResultFailure(e.message)
Ejemplo n.º 14
0
    def execute(self):
        error = self.errorHandling()
        if error != None:
            return error

        try:
            return self.status()
        except SZIGError as e:
            return CommandResultFailure("error while communicating through szig: %s" % e.msg)
Ejemplo n.º 15
0
 def errorHandling(self):
     running = self.isRunning(self.instance.process_name)
     if not running:
         return running
     pid = self.getProcessPid(self.instance.process_name)
     try:
         self.procinfo_file = open("/proc/%s/stat" % pid, 'r')
     except IOError:
         return CommandResultFailure("Can not open /proc/%s/stat" % pid)
Ejemplo n.º 16
0
    def getProcessPid(self, process):
        try:
            file_name = self.pidfiledir  + '/zorp-' + process + '.pid'
            pid_file = open(file_name)
            pid = int(pid_file.read())
            pid_file.close()
        except IOError as e:
            return CommandResultFailure("Can not open %s" % file_name, e.message)

        return pid
Ejemplo n.º 17
0
    def execute(self):
        self.status = GUIStatus(self.instance.process_name)
        error = self.errorHandling()
        if error != None:
            return error

        try:
            return self.gui_status()
        except SZIGError as e:
            return CommandResultFailure("error while communicating through szig: %s" % e.msg)
Ejemplo n.º 18
0
    def execute(self):
        error = self.errorHandling()
        if error != None:
            return error

        try:
            result = self.szig.stop_session(self.session_id)
            return CommandResultSuccess(result)
        except SZIGError as e:
            return CommandResultFailure(
                'Error while communicating through szig: ' + e.msg)
Ejemplo n.º 19
0
    def errorHandling(self):
        running = self.isRunning(self.instance.process_name)
        if not running:
            # Ignore not running process
            return CommandResultSuccess(running.msg)

        try:
            self.szig = SZIG(self.instance.process_name)
        except IOError as e:
            return CommandResultFailure(e.message)
        return None
Ejemplo n.º 20
0
    def getProcessPid(self, process):
        try:
            file_path = self._getProcessPidPath(process)
            pid_file = open(file_path)
            pid = int(pid_file.read())
            pid_file.close()
        except IOError as e:
            return CommandResultFailure(
                "'Can not open pid file '{}'".format(file_path), e.message)

        return pid
Ejemplo n.º 21
0
    def execute(self):
        error = self.errorHandling()
        if error != None:
            return error

        try:
            actual_value = self.getLevel().value
            if self.mode == self.GET:
                return self.getLevel()
            elif self.mode == self.SET and self.value >= 0 and self.value <= 10:
                return self.setLevel(self.value)
            elif self.mode == self.INCREMENT and actual_value < 10:
                return self.setLevel(actual_value + 1)
            elif self.mode == self.DECREMENT and actual_value > 0:
                return self.setLevel(actual_value - 1)
            else:
                return CommandResultFailure('Log level is out of range')
        except SZIGError as e:
            return CommandResultFailure(
                'Error while communicating through szig: ' + e.msg)
Ejemplo n.º 22
0
    def execute(self):
        error = self.errorHandling()
        if error != None:
            return error

        try:
            if self.value != None:
                return self.setDeadlockcheck(self.value)
            else:
                return self.getDeadlockcheck()
        except SZIGError as e:
            return CommandResultFailure("error while communicating through szig: %s" % e.msg)
Ejemplo n.º 23
0
 def start(self):
     args = self.assembleStartCommand()
     try:
         subprocess.Popen(args, stderr=open("/dev/null", 'w'))
     except OSError:
         pass
     self.waitTilTimoutToStart()
     running = self.isRunning(self.instance.process_name)
     if running:
         return CommandResultSuccess(running)
     else:
         return  CommandResultFailure("did not start in time")
Ejemplo n.º 24
0
    def execute(self):
        error = self.errorHandling()
        if error != None:
            return error

        try:
            if self.behaviour:
                return self.accept()
            else:
                return self.reject()
        except SZIGError as e:
            return CommandResultFailure("error while communicating through szig: %s" % e.msg)
Ejemplo n.º 25
0
 def searchInstance(instance_name):
     instances = []
     try:
         manually_started_instances = ZorpHandler.findManullyStartedInstances(
         )
         for manually_started_instance in manually_started_instances:
             if manually_started_instance.name == instance_name:
                 instances.append(manually_started_instance)
         for instance in InstancesConf():
             if instance.name == instance_name:
                 instances.append(instance)
         if instances:
             return instances
         else:
             return [
                 CommandResultFailure(
                     "Instance {0} not found!".format(instance_name),
                     instance_name)
             ]
     except IOError as e:
         return [CommandResultFailure(e.message)]
Ejemplo n.º 26
0
    def isRunning(self, process):
        """
        Opening the right pidfile in the pidfile dir,
        checking if there is a running process with that pid,
        returning True if there is.

        FIXME: Delete pid file if there is no runnig processes with that pid
        """

        pid = self.getProcessPid(process)
        if not pid:
            if pid.value == "Permission denied":
                return CommandResultFailure(pid.value)
            else:
                return CommandResultFailure("Process not running")

        try:
            open('/proc/' + str(pid) + '/status')
        except IOError:
            return CommandResultFailure("Invalid pid file no running process with pid %d!" % pid)

        return CommandResultSuccess("running")
Ejemplo n.º 27
0
    def stop(self):
        sig = signal.SIGKILL if self.force else signal.SIGTERM
        isKilled = self.killProcess(sig)
        if not isKilled:
            return isKilled

        self.waitTilTimeoutToStop()
        if self.isRunning(self.instance.process_name):
            return CommandResultFailure(
                "did not exit in time (pid='%d', signo='%d', timeout='%d')" %
                (self.pid, sig, self.stop_timout))
        else:
            return CommandResultSuccess("stopped")
Ejemplo n.º 28
0
 def errorHandling(self):
     running = self.isRunning(self.instance.process_name)
     if not running:
         self.status.pid = "missing"
         self.status.running = "missing"
         self.status.threads_running = "missing"
         self.status.thread_number = "missing"
         self.status.thread_rate_avg1 = "missing"
         self.status.thread_rate_avg5 = "missing"
         self.status.thread_rate_avg15 = "missing"
         return self.status
     try:
         self.szig = SZIG(self.instance.process_name)
     except IOError as e:
         return CommandResultFailure(e.message)
Ejemplo n.º 29
0
    def start(self):
        args = self.assembleStartCommand()

        environment = None

        try:
            start_process = subprocess.Popen(args, env=environment)
        except OSError:
            pass
        self.waitTilTimoutToStart(start_process)

        running = self.isRunning(self.instance.process_name)
        if running:
            return CommandResultSuccess(running)
        else:
            return CommandResultFailure('Did not start in time')
Ejemplo n.º 30
0
 def callAlgorithmToAllInstances(algorithm):
     result = []
     try:
         manually_started_instances = ZorpHandler.findManullyStartedInstances(
         )
         for manually_started_instance in manually_started_instances:
             result.extend(
                 InstanceHandler.executeAlgorithmOnInstanceProcesses(
                     manually_started_instance, algorithm))
         for instance in InstancesConf():
             result.extend(
                 InstanceHandler.executeAlgorithmOnInstanceProcesses(
                     instance, algorithm))
         return result
     except Exception as e:
         return [CommandResultFailure(e.message)]
Ejemplo n.º 31
0
    def execute(self):
        def _prepend_instance_name(tree):
            return {self.instance.process_name : tree}

        error = self.errorHandling()
        if error != None:
            return error

        try:
            if self.root:
                szig_dict = _prepend_instance_name({self.root : self.walk(self.root)})
            else:
                szig_dict = _prepend_instance_name(self.walk(self.root))

            return CommandResultSuccess("", szig_dict)
        except SZIGError as e:
            return CommandResultFailure("error while communicating through szig: %s" % e.msg)