Пример #1
0
    def serverShutDown(self, reason = ''):
        """When asked to shutdown the server by root
        """

        logging.warning("Server shutdown requested")

        """ On envoit un message à tous les clients """

        if reason != '':
            reason = "(%s) " % reason

        for p in self.allNickNames.values():
            p.clientSendErrorMessage(
                msg = "### Server is now going down %s... ###" % reason)
            p.close()

        self.close()
        # !!!!DIRTY HACK ALERT!!!!
        # we have to find another way to do this
        # os._exit is indeed a very dirty hack and should not be used at all.
        # indeed i suck and don't understand much of what i do
        # the previous comment and its poor english was graciously 
        # brougth to you by lekma
        # indeed (i am so f***ing tired and it's only 20:13)
        os._exit(0)
Пример #2
0
    def stop(self, pid, restart, msg = None):

        logging.info("Stopping Palabre...")
        if not pid:
            if self.daemon:
                sys.stderr.write("Could not stop, Palabre is not running (pid file '%s' is missing).\n" % self.pidfile)
            logging.warning("Could not stop, Palabre is not running (pid file '%s' is missing)." % self.pidfile)
            if not restart:
                logging.shutdown()
                logfile.close()
                sys.exit(1)
        else:
            ## There should be a better way, but i'm too lazy to search... but
            ## i'm sure there's a better way
            
            # if we're not a daemon we should clean up before committing suicide
            if not self.daemon:
                os.remove(self.pidfile)
                logging.shutdown()
                logfile.close()
            try:
                #global topServer
                #topServer.notifyStop()
                #time.sleep(1)
                print "sending signal..."
                os.kill(pid, signal.SIGUSR1)
                #os.system("kill -USR1 %d" % pid)

                print "signal sent"
                while True:
                    print "in the signal loop", pid
                    os.kill(pid,SIGTERM)
                    os.kill(pid,signal.SIGKILL)
                    time.sleep(1)
            except OSError, e:
                if e.strerror.find("No such process") >= 0:
                    os.remove(self.pidfile)
                    if not restart:
                        logging.info("...stopped.")
                        logging.shutdown()
                        logfile.close()
                        sys.exit(0)
                else:
                    logging.error("%s" % e.strerror)
                    logging.shutdown()
                    logfile.close()
                    sys.exit(1)
            except Exception, e:
                    logging.error("%s" % e.strerror)
                    logging.shutdown()
                    logfile.close()
                    sys.exit(1)
Пример #3
0
    def start(self, msg = None):

        logging.info("Starting Palabre...")

        if not __debug__ and os.path.exists(self.pidfile):

            if self.daemon:
                sys.stderr.write("Could not start, Palabre is already running (pid file '%s' exists).\n" % self.pidfile)
            logging.warning("Could not start, Palabre is already running (pid file '%s' exists)." % self.pidfile)
            logging.shutdown()
            logfile.close()
            sys.exit(1)
        else:
            if self.daemon:
                # Do first fork.
                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.umask(0) 
                os.setsid() 
                
                # Do second fork.
                try: 
                    pid = os.fork() 
                    if pid > 0:
                        # Exit second parent.
                        sys.exit(0)
                except OSError, e: 
                    sys.stderr.write("fork #2 failed: (%d) %s\n" % (e.errno, e.strerror))
                    sys.exit(1)