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})
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})