Ejemplo n.º 1
0
        table.update(
            {
                'stationName': pdata['message']['stationName'],
                'itemName': pdata['message']['itemName']
            },
            pdata['message'],
            upsert=True)

    @staticmethod
    def notify_dropped_frame(data, reason):
        logger.warning('A data frame was dropped because ' + reason)
        logger.debug('Frame contents: ' + data)


app = Feeder()

logger = logging.getLogger('FeederDaemonLog')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler = logging.FileHandler('/var/log/feeder/feeder.log')
handler.setFormatter(formatter)
logger.addHandler(handler)

runner = runner.DaemonRunner(app)
runner.daemon_context.files_preserve = [handler.stream]
runner.daemon_context.uid = uinfo.pw_uid
runner.daemon_context.gid = uinfo.pw_gid
runner.do_action()
Ejemplo n.º 2
0
        self.pidfile_timeout  = config.getint('daemon', 'pidfile_timeout')

    def run(self):
        try:
            # We need to import post_server here to resolve file descriptor issue
            # http://stackoverflow.com/questions/20636678/paramiko-inside-python-daemon-causes-ioerror?rq=1
            os.chdir(path)
            from bin import post_server
            post_server.main()
        except SystemExit:
            logger.info("post_hook system stopped.")
            print "post_hook system stopped."


if __name__ == '__main__':
    if len(sys.argv) == 2:
        try:
            post_hook = post_hook()
            runner = daemon.runner.DaemonRunner(post_hook)

            runner.daemon_context.files_preserve=[logger.handlers[0].stream]
            runner.do_action()
        except:
            logger.error("Daemon error", exc_info=True)
            print "Daemon stopped"
    else:
        print "Usage: %s start|stop|restart" % sys.argv[0]
        sys.exit(1)
else:
    print "This cannot be included in another program"
Ejemplo n.º 3
0
        self.pidfile_path    = os.path.realpath('core.pid')     
        self.pidfile_timeout = 5                                
        self.sched           = apscheduler.scheduler.Scheduler()
        self.sched.standalone = True                            
                                                                
    def run(self):                                              
        """Main daemon loop"""                                  
        try:                                                                                                     
            @self.sched.interval_schedule(seconds=5)            
            def running():                                      
                print "Running..."
                
            self.sched.start()  
                                                                
        except:                                                 
            self.sched.shutdown()                               
            print "Unexpected error:", sys.exc_info()           
            sys.exit(1)                                         
                                                                
if __name__ == "__main__":                                      
    if len(sys.argv) == 2:                                      
        core   = Core()                                         
        runner = daemon.runner.DaemonRunner(core)               
                                                                
        runner.do_action() # start|stop|restart as sys.argv[1]  
    else:                                                       
        print "Usage: %s start|stop|restart" % sys.argv[0]      
        sys.exit(1)                                             
else:                                                           
    print "Core daemon can't be included in another program."   
    sys.exit(1)