예제 #1
0
    def exit(self):
        try:
            pf = file(CONF.get_pid_file(), 'r')
            pid = int(pf.read().strip())
            pf.close()

            LOG.info("--- Daemon STOP [fail to check rest server] ---")

            try:
                LOG.info('PID = ' + str(pid))
                os.killpg(pid, SIGTERM)
            except OSError, err:
                err = str(err)
                if err.find("No such process") > 0:
                    if os.path.exists(self.pidfile):
                        os.remove(self.pidfile)
        except:
            LOG.exception()
예제 #2
0
# Copyright (c) 2017 by Telcoware
# All Rights Reserved.
# SONA Monitoring Solutions.

import sys
import time

import monitor.watchdog as watchdog
import api.rest_server as REST_SVR
from api.config import CONF
from api.sona_log import LOG
from api.watcherdb import DB
from daemon import Daemon
from datetime import datetime

PIDFILE = CONF.get_pid_file()


class SonaWatchD(Daemon):
    def run(self):

        # DB initiation
        DB.db_initiation()

        # Start RESTful server
        try:
            REST_SVR.rest_server_start()
        except:
            print 'Rest Server failed to start'
            LOG.exception()
            sys.exit(1)
예제 #3
0
                    conn.close()
                    LOG.exception()


if __name__ == "__main__":

    # change to script directory for relative CONFIG_FILE path
    os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
     
    CONF.init()
    LOG.init(CONF.base()['log_file_name'])
    history_log = USER_LOG()
    history_log.set_log('event_history.log', CONF.base()['log_rotate_time'], CONF.base()['log_backup_count'])
    alarm_event.set_history_log(history_log)

    daemon = SimpleFabricWatchD(CONF.get_pid_file())

    if len(sys.argv) == 2:

        if 'start' == sys.argv[1]:
            daemon.start()

        elif 'stop' == sys.argv[1]:
            print "Stopping ..."
            alarm_event.push_event('SimpleFabricWatchd', 'PROC', 'down', 'up', [], str(datetime.now()), True)
            daemon.stop()

        elif 'restart' == sys.argv[1]:
            print "Restaring ..."
            alarm_event.push_event('SimpleFabricWatchd', 'PROC', 'restart', 'up', [], str(datetime.now()), False)
            daemon.restart()