I'm looking for a way to spin up the rails development server in parallel with the webpack server. The problem is that if I run one of them in the background, when I Ctrl^C
to close everything, one process continues to run in the background and can cause some odd behavior involving the addresses being in use.
I have tried this:
$ rails s & bin/webpack-dev-server
// rails and webpack running in parallel
$ sudo lsof -n -i :3000 -i :3035 | grep LISTEN
ruby 26847 username 13u IPv4 0xa889e9178532bffd 0t0 TCP 127.0.0.1:hbci (LISTEN)
ruby 26847 username 14u IPv6 0xa889e91781b9ae3d 0t0 TCP [::1]:hbci (LISTEN)
node 26848 username 19u IPv4 0xa889e9178e468ffd 0t0 TCP 127.0.0.1:fjsv-gssagt (LISTEN)
But as you can see, when you attempt to kill the process with Ctrl^C
, there are still processes running on the port.
$ sudo lsof -n -i :3000 -i :3035 | grep LISTEN
ruby 26847 username 13u IPv4 0xa889e9178532bffd 0t0 TCP 127.0.0.1:hbci (LISTEN)
ruby 26847 username 14u IPv6 0xa889e91781b9ae3d 0t0 TCP [::1]:hbci (LISTEN)
I know that I could simply run these in separate terminals and kill both processes individually, but I would like to be able to create a yarn script that runs them both using something like yarn start
.
You can install foreman
gem, instructions here.
Then create a Procfile
and add the startup scripts to it.
web: bin/webpack-dev-server
api: rails s
To start the servers run foreman start
.
To kill all processes use Ctrl^C
, if it fails run killall "foreman: master"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With