Esempio n. 1
0
def start(nofork, socket):
    """
    Forks a new prosess, letting the service run as
    a daemon.
    """
    conf = config.pingconf()
    pidfilename = conf.get(
        "pidfile", os.path.join(buildconf.localstatedir, "run", "pping.pid"))

    # Already running?
    try:
        nav.daemon.justme(pidfilename)
    except nav.daemon.AlreadyRunningError:
        otherpid = open(pidfilename, "r").read().strip()
        sys.stderr.write("pping is already running (pid: %s)\n" % otherpid)
        sys.exit(1)
    except nav.daemon.DaemonError as error:
        sys.stderr.write("%s\n" % error)
        sys.exit(1)

    if not nofork:
        logfile_path = conf.get(
            'logfile', os.path.join(buildconf.localstatedir, 'log',
                                    'pping.log'))
        logfile = open(logfile_path, "a")
        nav.daemon.daemonize(pidfilename, stdout=logfile, stderr=logfile)

    my_pinger = Pinger(socket=socket)
    my_pinger.main()
Esempio n. 2
0
def start(nofork):
    """
    Forks a new prosess, letting the service run as
    a daemon.
    """
    conf = config.pingconf()
    pidfilename = conf.get("pidfile","/usr/local/nav/var/run/pping.pid")

    # Already running?
    try:
        nav.daemon.justme(pidfilename)
    except nav.daemon.AlreadyRunningError, e:
        otherpid = file(pidfilename, "r").read().strip()
        sys.stderr.write("pping is already running (pid: %s)\n" % otherpid)
        sys.exit(1)
Esempio n. 3
0
 def __init__(self, **kwargs):
     signal.signal(signal.SIGHUP, self.signalhandler)
     signal.signal(signal.SIGTERM, self.signalhandler)
     self.config = config.pingconf()
     init_generic_logging(stderr=True, read_config=True)
     self._isrunning = 1
     self._looptime = int(self.config.get("checkinterval", 60))
     LOGGER.info("Setting checkinterval=%i", self._looptime)
     self.db = db.db()
     sock = kwargs.get("socket", None)
     self.pinger = megaping.MegaPing(sock)
     self._nrping = int(self.config.get("nrping", 3))
     # To keep status...
     self.netboxmap = {}  # hash netboxid -> netbox
     self.down = []  # list of netboxids down
     self.replies = {}  # hash netboxid -> circbuf
     self.ipToNetboxid = {}
Esempio n. 4
0
    def signalhandler(self, signum, _frame):
        if signum == signal.SIGTERM:
            _logger.critical("Caught SIGTERM. Exiting.")
            sys.exit(0)
        elif signum == signal.SIGINT:
            _logger.critical("Caught SIGINT. Exiting.")
            sys.exit(0)
        elif signum == signal.SIGHUP:
            # reopen the logfile
            conf = config.pingconf()
            _logger.info("Caught SIGHUP. Reopening logfile...")
            logfile = open(conf.logfile, 'a')
            nav.daemon.redirect_std_fds(stdout=logfile, stderr=logfile)

            _logger.info("Reopened logfile: %s", conf.logfile)
        else:
            _logger.critical("Caught %s. Resuming operation.", signum)
Esempio n. 5
0
    def __init__(self, sockets, conf=None):

        # Get config in /etc/pping.conf
        if conf is None:
            try:
                self._conf = config.pingconf()
            except Exception:
                LOGGER.critical(
                    "Failed to open config file. Using default values.")
                self._conf = {}
        else:
            self._conf = conf

        # Delay between each packet is transmitted
        self._delay = float(self._conf.get('delay',
                                           2)) / 1000  # convert from ms
        # Timeout before considering hosts as down
        self._timeout = int(self._conf.get('timeout', 5))
        # Dictionary with all the hosts, populated by set_hosts()
        self._hosts = {}

        packetsize = int(self._conf.get('packetsize', 64))
        if packetsize < 44:
            raise ValueError(("Packetsize (%s) too small to create a proper "
                              "cookie; Must be at least 44.") % packetsize)
        self._packetsize = packetsize
        self._pid = os.getpid() % 65536

        # Global timing of the ppinger
        self._elapsedtime = 0

        # Initialize the sockets
        if sockets is not None:
            self._sock6 = sockets[0]
            self._sock4 = sockets[1]
        else:
            try:
                sockets = make_sockets()
            except Exception:
                LOGGER.error("Tried to create sockets without being root!")

            self._sock6 = sockets[0]
            self._sock4 = sockets[1]
            LOGGER.info("No sockets passed as argument, creating own")
Esempio n. 6
0
    def __init__(self, socket=None, foreground=False):
        if not foreground:
            signal.signal(signal.SIGHUP, self.signalhandler)
        signal.signal(signal.SIGTERM, self.signalhandler)
        signal.signal(signal.SIGINT, self.signalhandler)

        self.config = config.pingconf()
        init_generic_logging(stderr=True, read_config=True)
        self._isrunning = 1
        self._looptime = int(self.config.get("checkinterval", 60))
        _logger.info("Setting checkinterval=%i", self._looptime)
        self.db = db.db()
        self.pinger = megaping.MegaPing(socket)
        self._nrping = int(self.config.get("nrping", 3))
        # To keep status...
        self.netboxmap = {}  # hash netboxid -> netbox
        self.down = []  # list of netboxids down
        self.replies = {}  # hash netboxid -> circbuf
        self.ip_to_netboxid = {}
Esempio n. 7
0
 def __init__(self, **kwargs):
     signal.signal(signal.SIGHUP, self.signalhandler)
     signal.signal(signal.SIGTERM, self.signalhandler)
     self.config=config.pingconf()
     debug.setDebugLevel(int(self.config.get("debuglevel",5)))
     debug.debug("Setting debuglevel=%s "% self.config.get("debuglevel",5))
     self._isrunning=1
     self._looptime=int(self.config.get("checkinterval",60))
     debug.debug("Setting checkinterval=%i" %self._looptime)
     self._debuglevel=0
     self.db=db.db()
     sock = kwargs.get("socket",None)
     self.pinger=megaping.MegaPing(sock)
     self._nrping = int(self.config.get("nrping" ,3))
     # To keep status...
     self.netboxmap = {} # hash netboxid -> netbox
     self.down = []      # list of netboxids down
     self.replies = {}      # hash netboxid -> circbuf
     self.ipToNetboxid = {}
Esempio n. 8
0
    def __init__(self, sockets, conf=None):

        # Get config in /etc/pping.conf
        if conf is None:
            try:
                self._conf = config.pingconf()
            except Exception:
                debug("Failed to open config file. Using default values.", 2)
                self._conf = {}
        else:
            self._conf = conf

        # Delay between each packet is transmitted
        self._delay = float(self._conf.get('delay', 2))/1000  # convert from ms
        # Timeout before considering hosts as down
        self._timeout = int(self._conf.get('timeout', 5))
        # Dictionary with all the hosts, populated by set_hosts()
        self._hosts = {}

        packetsize = int(self._conf.get('packetsize', 64))
        if packetsize < 44:
            raise ValueError(("Packetsize (%s) too small to create a proper "
                              "cookie; Must be at least 44.") % packetsize)
        self._packetsize = packetsize
        self._pid = os.getpid() % 65536

        # Global timing of the ppinger
        self._elapsedtime = 0

        # Initialize the sockets
        if sockets is not None:
            self._sock6 = sockets[0]
            self._sock4 = sockets[1]
        else:
            try:
                sockets = make_sockets()
            except Exception:
                debug("Tried to create sockets without beeing root!")

            self._sock6 = sockets[0]
            self._sock4 = sockets[1]
            debug("No sockets passed as argument, creating own")
Esempio n. 9
0
def start(foreground, socket):
    """
    Starts a new process, letting the service run as a daemon if `foreground`
    is false.
    """
    conf = config.pingconf()
    pidfilename = "pping.pid"

    # Already running?
    try:
        nav.daemon.justme(pidfilename)
    except nav.daemon.AlreadyRunningError as error:
        sys.exit("pping is already running (pid: %s)" % error.pid)
    except nav.daemon.DaemonError as error:
        sys.exit(error)

    if not foreground:
        logfile = open(conf.logfile, "a")
        nav.daemon.daemonize(pidfilename, stdout=logfile, stderr=logfile)
    else:
        nav.daemon.writepidfile(pidfilename)

    my_pinger = Pinger(socket=socket, foreground=foreground)
    my_pinger.main()
Esempio n. 10
0
def setUser():
    conf = config.pingconf()
    username = conf.get("user", "nobody")
    nav.daemon.switchuser(username)
Esempio n. 11
0
def setUser():
    conf = config.pingconf()
    username = conf.get("user", "nobody")
    nav.daemon.switchuser(username)