DEV Community

Akshay Khot
Akshay Khot

Posted on • Originally published at akshaykhot.com

3 1

Launching Multiple Processes with a Single Command in Rails

An application doesn't exist in isolation. Usually, it depends on other processes to work correctly, such as a database, JavaScript / CSS compilers, Redis, etc.

So far, whenever I started the Rails app, I launched these supporting processes in multiple terminal windows. This week, I learned a new way to do this using a single command using the Foreman gem, which has saved me a lot of time.

Here's a simple way to achieve this, inspired by the tailwindcss-rails gem.

Step 1: Create an executable dev file in the bin/ directory

cd bin
touch dev
chmod 755 bin/dev
Enter fullscreen mode Exit fullscreen mode

Step 2: Add Foreman script to your bin/dev file

#!/usr/bin/env bash

if ! command -v foreman &> /dev/null
then
  echo "Installing foreman..."
  gem install foreman
fi

foreman start -f Procfile.dev
Enter fullscreen mode Exit fullscreen mode

Step 3: Add the procfile

web: bin/rails server -p 3000
css: bin/rails tailwindcss:watch
js: ..
mysql: ..
redis: ..
Enter fullscreen mode Exit fullscreen mode

Now all you have to do is run the bin/dev command from the root of your rails application, and Foreman takes care of starting the processes listed in the Procfile.

I hope that helps.

Top comments (2)

Collapse
 
aquadrehz profile image
AquaDrehz

Nice quickstart thanks!

Collapse
 
software_writer profile image
Akshay Khot

Thanks, glad it helped!

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay