Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start the rails server in parallel with the webpack server so that I can kill both at the same time?

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.

like image 647
Benjamin Hargett Avatar asked Apr 09 '19 15:04

Benjamin Hargett


1 Answers

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".

like image 87
Aminu Kano Avatar answered Oct 19 '22 23:10

Aminu Kano