spring
spring copied to clipboard
Kill a process when spring stop
This question is related to this issue and this question.
I'm looking for a way to kill Ember, or any process, when spring is stopped. Is it possible. Do you have an idea?
allowing to overwrite pre-boot steps like start & stop might solve that ... maybe some config/spring-preboot.rb could be supported where you can go crazy and make stop do all kinds of things ...
Monkey patching? No cleaner way?
Use Signal.trap("TERM") { exec('touch /tmp/test123') } seems to works when spring is stopped. I don't know if their can be conflicts.
I think I can you only one Signal.trap in the whole app so it's not a good way to go. Monkey Patching does not work because Spring is loaded after the initializers (I think) and methods I'm trying to create are overwritten. Any clue?
FYI You can trap a signal and then call the previous trap:
https://github.com/grosser/parallel/blob/master/lib/parallel.rb#L158-L171
but not something I'd recommend ...
some pre-boot configuration file would be nice to be able to control start/stop etc behavior ...
On Thu, Aug 27, 2015 at 4:20 AM, Guirec Corbel [email protected] wrote:
I think I can you only one Signal.trap in the whole app so it's not a good way to go. Monkey Patching does not work because Spring is loaded after the initializers (I think) and methods I'm trying to create are overwritten. Any clue?
— Reply to this email directly or view it on GitHub https://github.com/rails/spring/issues/424#issuecomment-135392199.
I agree but I don't know how to do. I have to do something when spring stops so I have to know when it stop and interact with EmberCLI. I don't see a solution to stop a process when spring is stopped. Do you have a clue?
@grosser, the only think I see is to do a callback function Spring.after_stop or Spring.after_kill. If you agree, I will do a pull request.
https://github.com/rails/spring/pull/426 would allow you to do:
Spring::Client::Stop.prepend(Module.new do
def call(args)
super
# do something else
end
end)
does that look good ?
It does not work. Spring::Client is undefined so I required it and it's never triggered.
did you put it in config/spring_preboot.rb and use gem installed from the branch ? (rake install)
I did not. Now, it installed it properly. The code is called for each run even if I did not spring stop.
Sorry, I was wrong. It seems to work. I have some verifications to do before to close this issue.
Once you verified I'll merge the PR and release a new version :)
On Thu, Sep 3, 2015 at 5:10 PM, Guirec Corbel [email protected] wrote:
Sorry, I was wrong. It seems to work. I have some verifications to do before to close this issue.
— Reply to this email directly or view it on GitHub https://github.com/rails/spring/issues/424#issuecomment-137605826.
I only have two problems but about EmberCLI-Rails. First, EmberCLI[:frontend] is undefined on spring_preboot.rb. I suppose all gems are not loaded.
The second problem, too linked to EmberCLI-Rails I think, is than there is 3 processes launched. The PID stored in the app is the first one and I need to kill the second one. I have to work to resolve this issue.
can you ps -ef | grep foobar and then get the pids to kill them ?
but the preboot.rb looks like it helps / should I merge it ?
On Thu, Sep 3, 2015 at 5:47 PM, Guirec Corbel [email protected] wrote:
I only have two problems but about EmberCLI-Rails. First, EmberCLI[:frontend] is undefined on spring_preboot.rb. I suppose all gems are not loaded.
The second problem, too linked to EmberCLI-Rails I think, is than there is 3 processes launched. The PID stored in the app is the first one and I need to kill the second one. I have to work to resolve this issue.
— Reply to this email directly or view it on GitHub https://github.com/rails/spring/issues/424#issuecomment-137612523.
With ps -ef | grep ember, I can have other processes not related.
preboot.rb will help for sure. You can merge it.