rejeep / prodigy.el

Manage external services from within Emacs
GNU General Public License v3.0
550 stars 39 forks source link

Flexible services shutdown options #22

Closed yveszoundi closed 10 years ago

yveszoundi commented 10 years ago

I think that it would be useful to have the following features:

Below is an example of what I use with Tomcat. When I stop the service, ideally I want to close the "prodigy-tomcat" buffer automatically. Thus a auto-close-service-buffer-on-stop parameter that defaults to t would be convenient.

(use-package prodigy                                                                                                                          
  :ensure prodigy                                                                                                                             
  :config (progn                                                                                                                              
            (prodigy-define-service                                                                                                           
              :name "Tomcat"                                                                                                                  
              :command "./catalina.sh"                                                                                                        
              :cwd "/Users/yves/Tools/apache-tomcat-7.0.25"                                                                                   
              :path '("/Users/yves/Tools/apache-tomcat-7.0.25/bin")                                                                           
              :port 8080                                                                                                                      
              :stop-signal 'SIGTERM                                                                                                           
              :args '("run")                                                                                                                  
              :tags '(java))))                                                                                                                                                        

Thanks

yveszoundi commented 10 years ago

I'm currently using an advice to auto-close services buffer

(defadvice prodigy-stop-service                                                                                                               
    (after prodigy-stop-service-close-buffer (service) activate )                                                                             
  "Close prodigy service buffer after the stop call."                                                                                         
  (let* ((service-name-downcased (downcase (plist-get service :name)))                                                                        
         (service-buffer-name (concat "*prodigy-" service-name-downcased "*")))                                                               
    (when (get-buffer service-buffer-name)                                                                                                    
      (kill-buffer (get-buffer service-buffer-name))))) 
rejeep commented 10 years ago

I think a global variable (for example prodigy-kill-process-buffer-on-stop) is a good idea. But I also think it makes sense that this can be specified per service, hence override the global setting.

For example:

(prodigy-define-service
  :name "foo"
  :kill-process-buffer-on-stop t
  )

I've been thinking of hooks as well, but that's not just related to stop. That would make sense for start and restart also for example.

(prodigy-define-service
  :name "foo"
  :after-stop (lambda ()
                (kill-buffer ...)
                ))

Another configuration that might be useful is prodigy-erase-process-buffer-on-start, so that if the process have been started before, the contents is cleared.

What do you think?

yveszoundi commented 10 years ago

That sounds perfectly reasonable to me, especially in the early stages of the project.

Issue #3 is kind of related. When providing services definitions, users should be able to provide a way to ensure that the desired action has completed with the expected side-effect, if needed (Tomcat started but not ready yet, WebRick stop initiated but not completed, etc.).

If the signal sent to terminate a program is a SIGKILL, there's no need for extra logic. In most cases, I think that a SIGTERM will be used to allow programs to shutdown gracefully without creating any kind of state/db corruption. Therefore the action should complete successfully prior to calling any hook.

rejeep commented 10 years ago

Closing this issue in favor of https://github.com/rejeep/prodigy.el/issues/24 and https://github.com/rejeep/prodigy.el/issues/25.