コード例 #1
0
    def start(self):
        logging.info("brickd started")

        self.usb_notifier = USBNotifier()

        if gudev_imported:
            self.gudev_client = gudev.Client(["usb"])
            self.gudev_client.connect("uevent", self.notify_udev)

        reactor.listenTCP(config.PORT, BrickProtocolFactory())
        try:
            reactor.run(installSignalHandlers=True)
        except KeyboardInterrupt:
            reactor.stop()
コード例 #2
0
 def start(self):
     logging.info("brickd started")
     
     self.usb_notifier = USBNotifier()
     
     if gudev_imported:
         self.gudev_client = gudev.Client(["usb"])
         self.gudev_client.connect("uevent", self.notify_udev)
         
     reactor.listenTCP(config.PORT, BrickProtocolFactory())
     try:
         reactor.run(installSignalHandlers = True)
     except KeyboardInterrupt:
         reactor.stop()
コード例 #3
0
    def SvcDoRun(self):
        logging.getLogger().addHandler(BrickLoggingHandler())
        logging.info("brickd started")

#        for non service test purposes only
#        signal.signal(signal.SIGINT, lambda s, f: exit_brickd(s, f, reactor)) 
#        signal.signal(signal.SIGTERM, lambda s, f: exit_brickd(s, f, reactor)) 
        
        self.usb_notifier = USBNotifier()
        reactor.listenTCP(config.PORT, BrickProtocolFactory())
        
        try:
            reactor.run(installSignalHandlers = True)
        except KeyboardInterrupt:
            reactor.stop()

        win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
コード例 #4
0
class BrickdLinux:
    def __init__(self, stdin='/dev/null', stdout=LOGFILE, stderr=LOGFILE):
        self.stdin = stdin
        self.stdout = stdout
        self.stderr = stderr
        
        if glib2reactor_installed:
            r = glib2reactor
        else:
            r = reactor
        
        signal.signal(signal.SIGINT, lambda s, f: exit_brickd(s, f, r)) 
        signal.signal(signal.SIGTERM, lambda s, f: exit_brickd(s, f, r)) 
        
    def start(self):
        logging.info("brickd started")
        
        self.usb_notifier = USBNotifier()
        
        if gudev_imported:
            self.gudev_client = gudev.Client(["usb"])
            self.gudev_client.connect("uevent", self.notify_udev)
            
        reactor.listenTCP(config.PORT, BrickProtocolFactory())
        try:
            reactor.run(installSignalHandlers = True)
        except KeyboardInterrupt:
            reactor.stop()
    
    def notify_udev(self, client, action, device):
        if action == "add":
            logging.info("New USB device")
            self.usb_notifier.notify_added()
        elif action == "remove":
            logging.info("Removed USB device")
            self.usb_notifier.notify_removed()

    # based on http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
    def daemonize(self):   
        """
        do the UNIX double-fork magic, see Stevens' "Advanced 
        Programming in the UNIX Environment" for details (ISBN 0201563177)
        http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
        """
        try: 
            pid = os.fork() 
            if pid > 0:
                # exit first parent
                sys.exit(0) 
        except OSError, e: 
            sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
            sys.exit(1)
    
        # decouple from parent environment
        os.chdir("/") 
        os.setsid() 
        os.umask(0) 
    
        # do second fork
        try: 
            pid = os.fork() 
            if pid > 0:
                open(PIDFILE, 'w').write("%d" % pid)
                # exit from second parent
                sys.exit(0) 
        except OSError, e: 
            sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
            sys.exit(1) 
コード例 #5
0
class BrickdLinux:
    def __init__(self, stdin='/dev/null', stdout=LOGFILE, stderr=LOGFILE):
        self.stdin = stdin
        self.stdout = stdout
        self.stderr = stderr

        if glib2reactor_installed:
            r = glib2reactor
        else:
            r = reactor

        signal.signal(signal.SIGINT, lambda s, f: exit_brickd(s, f, r))
        signal.signal(signal.SIGTERM, lambda s, f: exit_brickd(s, f, r))

    def start(self):
        logging.info("brickd started")

        self.usb_notifier = USBNotifier()

        if gudev_imported:
            self.gudev_client = gudev.Client(["usb"])
            self.gudev_client.connect("uevent", self.notify_udev)

        reactor.listenTCP(config.PORT, BrickProtocolFactory())
        try:
            reactor.run(installSignalHandlers=True)
        except KeyboardInterrupt:
            reactor.stop()

    def notify_udev(self, client, action, device):
        if action == "add":
            logging.info("New USB device")
            self.usb_notifier.notify_added()
        elif action == "remove":
            logging.info("Removed USB device")
            self.usb_notifier.notify_removed()

    # based on http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
    def daemonize(self):
        """
        do the UNIX double-fork magic, see Stevens' "Advanced 
        Programming in the UNIX Environment" for details (ISBN 0201563177)
        http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
        """
        try:
            pid = os.fork()
            if pid > 0:
                # exit first parent
                sys.exit(0)
        except OSError, e:
            sys.stderr.write("fork #1 failed: %d (%s)\n" %
                             (e.errno, e.strerror))
            sys.exit(1)

        # decouple from parent environment
        os.chdir("/")
        os.setsid()
        os.umask(0)

        # do second fork
        try:
            pid = os.fork()
            if pid > 0:
                open(PIDFILE, 'w').write("%d" % pid)
                # exit from second parent
                sys.exit(0)
        except OSError, e:
            sys.stderr.write("fork #2 failed: %d (%s)\n" %
                             (e.errno, e.strerror))
            sys.exit(1)