コード例 #1
0
    def _startsensor(self):
        """ starts the Iyri sensor """
        flags = bits.bitmask_list(_STATE_FLAGS_, self._state)
        if flags['store'] and not flags['iyri']:
            # do we have a password
            if not self._pwd:
                pwd = self._getpwd()
                if pwd is None:
                    self.logwrite("Password entry canceled. Cannot continue",
                                  gui.LOG_WARN)
                    return
                self._pwd = pwd

            # start the sensor
            try:
                self.logwrite("Starting Iyri...", gui.LOG_NOTE)
                cmdline.service('iyrid', self._pwd)
                time.sleep(0.5)
                if not cmdline.runningservice(wraith.IYRIPID):
                    raise RuntimeError('unknown')
            except RuntimeError as e:
                self.logwrite("Error starting Iyri: {0}".format(e),
                              gui.LOG_ERR)
            else:
                self.logwrite("Iyri Started")
                self._setstate(_STATE_IYRI_)
コード例 #2
0
    def _create(self):
        # read in conf file, exit on error
        msgs = [(time.strftime('%H:%M:%S'),
                 "Wraith v{0}".format(wraith.__version__), gui.LOG_NOERR)]
        self._conf = readconf()
        if 'err' in self._conf:
            msgs.append(
                (time.strftime('%H:%M:%S'),
                 "Invalid configuration file: {0}".format(self._conf['err']),
                 gui.LOG_ERR))
            return

        # determine if postgresql is running
        if cmdline.runningprocess('postgres'):
            # update self, msg and connect
            msgs.append((time.strftime('%H:%M:%S'), "PostgreSQL running",
                         gui.LOG_NOERR))
            if not self._pwd: self._bSQL = True
            self._setstate(_STATE_STORE_)
            (self._conn, ret) = cmdline.psqlconnect(self._conf['store'])
            if not self._conn is None:
                self._setstate(_STATE_CONN_)
                msgs.append((time.strftime('%H:%M:%S'), "Connected to DB",
                             gui.LOG_NOERR))
            else:
                msgs.append(
                    (time.strftime('%H:%M:%S'),
                     "DB connect failed: {0}".format(ret), gui.LOG_ERR))
                return
        else:
            msgs.append((time.strftime('%H:%M:%S'), "PostgreSQL not running",
                         gui.LOG_WARN))
            msgs.append((time.strftime('%H:%M:%S'), "Not connected to DB",
                         gui.LOG_WARN))

        # Iyri running?
        if cmdline.runningservice(wraith.IYRIPID):
            msgs.append(
                (time.strftime('%H:%M:%S'), "Iyri running", gui.LOG_NOERR))
            self._setstate(_STATE_IYRI_)
        else:
            msgs.append(
                (time.strftime('%H:%M:%S'), "Iyri not running", gui.LOG_WARN))

        # set initial state to initialized
        self._setstate(_STATE_INIT_)

        # show log, write messages & display any saved panels
        self.viewlog()
        self.getpanel("log", True).delayedwrite(msgs)
        if os.path.exists('default.ts'): self.guiload('default.ts')

        # check if something outside this program stopped a service
        self.after(500, self._poll)
コード例 #3
0
 def _chkiyri(self):
     self._sv.set("Checking Iyri...")
     self._pb.step(2.0)
     if not cmdline.runningservice(wraith.IYRIPID):
         self._sv.set("Starting Iyri")
         if not startiyri(pwd):
             # because Iyri can sometimes take a while, we will run
             # this several times
             i = 5
             while not cmdline.runningservice(wraith.IYRIPID):
                 i -= 1
                 if i == 0: break
                 time.sleep(0.5)
         if cmdline.runningservice(wraith.IYRIPID):
             self._sv.set("Iyri started")
         else:
             self._sv.set("Failed to start Iyri")
     else:
         self._sv.set("Iyri already running")
     self._bfinished = True
コード例 #4
0
def stopiyri(pwd):
    """
     stop Iyri sensor. pwd: Sudo password
     :param pwd: sudo password
     :returns: whether iyri stopped or not
    """
    try:
        cmdline.service('iyrid', pwd, False)
        while cmdline.runningservice(wraith.IYRIPID):
            time.sleep(1.0)
    except RuntimeError as e:
        return False
    else:
        return True
コード例 #5
0
    def _updatestate(self):
        """ reevaluates internal state """
        # state of Iyri
        if cmdline.runningservice(wraith.IYRIPID): self._setstate(_STATE_IYRI_)
        else: self._setstate(_STATE_IYRI_, False)

        # state of postgres i.e. store
        if cmdline.runningprocess('postgres'): self._setstate(_STATE_STORE_)
        else: self._setstate(_STATE_STORE_, False)

        # state of our connection - should figure out a way to determine if
        # connection is still 'alive'
        if self._conn: self._setstate(_STATE_CONN_)
        else: self._setstate(_STATE_CONN_, False)
コード例 #6
0
def startiyri(pwd):
    """
     start Iyri sensor.
     :param pwd: sudo password
     :returns: whether iyri started or not
    """
    try:
        cmdline.service('iyrid', pwd)
        time.sleep(1.0)
        if not cmdline.runningservice(wraith.IYRIPID): raise RuntimeError
    except RuntimeError:
        return False
    else:
        return True
コード例 #7
0
    if sopts is not None and stop == True: ap.error("Cannot start and stop")

    # stop services - assumes no gui
    if stop:
        # verify pwd has been set
        i = 2
        usr = getpass.getuser()
        pwd = getpass.unix_getpass(prompt="Password [for {0}]:".format(usr))
        while not cmdline.testsudopwd(pwd):
            pwd = getpass.unix_getpass(prompt="Incorrect password, try again:")
            i -= 1
            if i == 0: ap.error("Three incorrect password attempts")

        # stop Iyri, then PostgreSQL
        sd = sn = sp = True
        if cmdline.runningservice(wraith.IYRIPID):
            ret = 'ok' if stopiyri(pwd) else 'fail'
            print "Stopping Iyri\t\t\t\t[{0}]".format(ret)
        else:
            print "Iyri not running"
        if cmdline.runningprocess('postgres') and not exclude:
            ret = 'ok' if stoppsql(pwd) else 'fail'
            print "Stopping PostgreSQL\t\t\t[{0}]".format(ret)
        else:
            print "PostgreSQL not running"
        sys.exit(0)

    # start specified services
    if sopts == 'nogui':
        # verify pwd is present
        i = 2