Пример #1
0
 def start(self):
     if self.is_running():
         raise StatusException, (self.ERROR_ALREADY_STARTED, self.MSG_ERROR_ALREADY_STARTED)
     self.set_running_flag()
     import platform
     if os.sep == ('/') and platform.system() == 'Linux':
         if self.daemon:
             print '%s started as daemon' % self.name
             createDaemon()
         else:
             print '%s suspended to start as daemon' % self.name
     else:
         print '%s started' % self.name
     self.prepare()
     interrupted = False
     while not interrupted and not self.is_closing():
         try:
             self.run()
         except KeyboardInterrupt:
             print 'Interrupted by user'
             interrupted = True
         except:
             print self.logger.error(trackable('Interrupted by exception'))
             interrupted = True
     self.finish()
     self.logger.info('%s stopped' % self.name)
     print '%s stopped' % self.name
     self.unset_running_flag()
Пример #2
0
 def start(self):
     if self.is_running():
         raise StatusException, (self.ERROR_ALREADY_STARTED,
                                 self.MSG_ERROR_ALREADY_STARTED)
     self.set_running_flag()
     import platform
     if os.sep == ('/') and platform.system() == 'Linux':
         if self.daemon:
             print '%s started as daemon' % self.name
             createDaemon()
         else:
             print '%s suspended to start as daemon' % self.name
     else:
         print '%s started' % self.name
     self.prepare()
     interrupted = False
     while not interrupted and not self.is_closing():
         try:
             self.run()
         except KeyboardInterrupt:
             print 'Interrupted by user'
             interrupted = True
         except:
             print self.logger.error(trackable('Interrupted by exception'))
             interrupted = True
     self.finish()
     self.logger.info('%s stopped' % self.name)
     print '%s stopped' % self.name
     self.unset_running_flag()
Пример #3
0
#!/usr/local/bin/python
import SocketServer
import pyDaemon
import os

pyDaemon.createDaemon()

class myUDPHandler(SocketServer.BaseRequestHandler):
	def handle(self):
		print "Port connected. Going to shut down server";
		os.execl("/sbin/shutdown", "/sbin/shutdown", "-p", "now");

if __name__ == "__main__":
	HOST, PORT = "192.168.1.2", 9999
	server = SocketServer.UDPServer((HOST, PORT), myUDPHandler)
	server.serve_forever()