Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make stack kill executed process when running stack build --file-watch --exec "foo" #1765

Open
cdepillabout opened this issue Feb 9, 2016 · 6 comments

Comments

@cdepillabout
Copy link
Member

cdepillabout commented Feb 9, 2016

When I am programming a long running application (like a web api), I'd like to have a feature where the program that has been executed after building is killed when a source code change is found.

For example, I am building an api using Servant and I would like to run it like this:

$ stack build --file-watch --exec "stack exec -- my-api"

Everytime I change one of my source files, it would be nice if stack automatically killed and restarted my-api.

Currently stack just waits until my-api is finished running (which never happens).

@mgsloan
Copy link
Contributor

mgsloan commented Feb 11, 2016

Something like that might be the domain of stack-run. That said, I wouldn't mind having something like stack run, or something similar to yesod devel built into stack. It'd particularly be great if it could optionally run in the interpreter, so that you get blazing fast reloads of the app.

@JoeMShanahan
Copy link

JoeMShanahan commented Jul 12, 2017

Did anyone get started on a PR for this?

@cdepillabout
Copy link
Member Author

cdepillabout commented Jul 12, 2017

@JoeMShanahan I have not.

It would be really nice to have as a feature though.

@5outh
Copy link

5outh commented Apr 5, 2019

You can get this behavior using pkill:

$ stack build --file-watch --exec "bash -c \"pkill my-api; stack exec my-api &\""

@dbaynard
Copy link
Contributor

dbaynard commented Apr 6, 2019

@JoeMShanahan, @cdepillabout please indicate whether that resolves the issue. If so, would one of you kindly add it to the documentation?

If it doesn't resolve the issue, I'll move it to the wishlist.

@cdepillabout
Copy link
Member Author

cdepillabout commented Apr 7, 2019

@dbaynard I haven't tried this, but it looks like it would solve the issue.

Recently, I've been using ghcid to do this:

$ ghcid --command 'stack ghci' --test 'defaultMain' --warnings

ghcid is used to automatically quickly recompile your project by loading it in GHCi. I find that this normally gets recompilation times quicker than just using stack --build --file-watch.

The argument to --test is a Haskell function within your codebase that is run every time all the code compiles correctly. Generally, it should have the type IO (). Since I often work on web apps, it can be used to re-run your web application after every recompilation cycle. This works quite well.

The --warnings flag is used to force the defaultMain function to be run even if there are GHC warnings as a result of recompiling everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants