rejeep / prodigy.el

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

Auto start #38

Open rejeep opened 10 years ago

rejeep commented 10 years ago

This is an idea about adding a new property called :auto-start. If that is set to true, the service will automatically start when it's defined.

For example:

(prodigy-define-service
  :name "Rails App"
  :command "bundle"
  :args '("exec" "rails" "server")
  :cwd "/path/to/my/project"
  :auto-start t)
zeltak commented 7 years ago

any progress on that? so currently after each emacs restart i need to issue M-x prodigy, and go to the process and issue M-x prodigy-start?

tosmi commented 6 years ago

i would be great if you could merge #106. i moving my systemd/launchd stuff over to prodigy and auto start would be really helpful.

thanks

isamert commented 2 years ago

I wrote the following snippet for adding a primitive auto-start feature that fits my needs, if anyone is interested:

(defun isamert/prodigy-autostart ()
  "Start all services with the `:auto-start' set to non-nil if they
are not already started."
  (interactive)
  (prodigy-with-refresh
   (--each
       prodigy-services
     (when (and (plist-get it :auto-start)
                (not (prodigy-service-started-p it)))
       (prodigy-start-service it)))))

(add-hook
 'after-init-hook
 #'isamert/prodigy-autostart)

You need to add :auto-start t to service definitions as described in the first comment. You can also call isamert/prodigy-autostart anytime if you want to start services that are marked :auto-start manually if you want.

isamert commented 2 years ago

Now that I think of this, I can prepare a PR with the following function (and with some documentation regarding to it)

(defun prodigy-autostart ()
  "Start all services with the `:auto-start' set to non-nil if they
are not already started."
  (interactive)
  (prodigy-with-refresh
   (--each
       prodigy-services
     (when (and (plist-get it :auto-start)
                (not (prodigy-service-started-p it)))
       (prodigy-start-service it)))))

and we can advise users to add this function to a some hook they see fit to get a basic auto-start feature going (and maybe we can advertise the after-init-hook at the documentation for this purpose like I did on the previous comment). Would you be interested in an PR like this @rejeep @DamienCassou? Maybe I can work on a more complex and complete solution in the future but I believe this cuts it for the most cases.

Fuco1 commented 2 years ago

The PR #106 did a lot of work on this including tests and documentation. The basic logic is similar to yours but there's some additional settings etc. I say we should finish that one. Would you like to pick it up and test if it covers your use-case?

isamert commented 2 years ago

I saw that PR and I even tried to patch my local prodigy copy with it but it failed as some file names are changed etc. Then I saw that it's from 4 years ago and thought it's probably easier to define a function like the one above and call it a day instead of trying to rebase it with the current master. I may look into cleaning that PR but I don't know when I would pick this task up.