Exemplo n.º 1
0
    def cmd_start(self):
        """
        Starts the daemon for ``app``
        
        The method :meth:`app.before_start()` is called prior to actually daemonizing;
        the method can abort the process by raising ...
        
        The method :meth:`app.before_start()` need not to exist (a validity check is performed).
        """
        if self.pidfile.is_locked():
            pidfile_path = self.pidfile.path
            
            if PIDFileHelper.pidfile_lock_is_stale(self.pidfile):
                self.pidfile.break_lock()
            else:
                ##EXCEPTION##
                self._raise("PID file already locked", 
                            'error_pidfile_locked', {'path':self.pidfile.path})
             
        
        # BEFORE START
        # ============
        abort = self._tryBeforeStart()
        if abort:
            self._raise("daemon aborted by 'before_start'",
                        'error_daemon_aborted', {'cause':'BeforeStart application method'})   

        # START!!!
        # ========
        try:
            self.context.open()
        except Exception,e:
            ##EXCEPTION##
            self._raise("daemon error whilst opening",
                        'error_daemon_open', {'exc':e})
Exemplo n.º 2
0
 def _configPIDFile(self):
     """
     Configures the PID File
     """
     prefix = self._secureGetFromApp('pidfile_pathprefix', 
                                     self._default_pid_filepath_prefix)
     
     # the forward slash / also works under windows
     #  so we can skip os.path.join
     pidfile_path = prefix.rstrip('/') + "/" + self.app.name
     
     self.pidfile = PIDFileHelper.make_pidlockfile(pidfile_path)
     self.context.pidfile = self.pidfile       
Exemplo n.º 3
0
    def cmd_stop(self):
        """
        Stops the daemon for (the currently running) ``app`` but not before calling ``app.stop``
        """
        if not self.pidfile.is_locked():
            pidfile_path = self.pidfile.path
            
            ##EXCEPTION##
            self._raise("PID file not locked / not present",
                        'error_pidfile_not_locked', {'path':pidfile_path})


        if PIDFileHelper.pidfile_lock_is_stale(self.pidfile):
            self.pidfile.break_lock()
        else:
            pid = self.pidfile.read_pid()
            try:
                os.kill(pid, signal.SIGTERM)
            except OSError, exc:
                ##EXCEPTION##
                self._raise("daemon termination fault",
                            'error_daemon_terminate_process', {'pid':pid})