Saturday, December 2, 2023
HomeRuby On RailsManagement Your Dev Processes with Overmind

Management Your Dev Processes with Overmind

Helicopter flying over a city
Picture by Austin Neill on Unsplash

In the event you’re questioning how one can run a number of processes in your mission, look no additional. You got here to the right place the place you’ll learn to rapidly and successfully run all of the providers your mission wants.

Neglect about opening a number of tabs in your terminal and typing out a number of instructions. Right now, you’ll harness the ability of operating every part with a single command.

The Procfile

Welcome to the Procfile file – a spot the place all of your mission’s providers are outlined. The Procfile is a spot the place you outline a number of processes to be run to ensure that your app to perform. Briefly, that is how a Procfile I exploit appears:

internet: bin/rails server -p 3000
css: bin/rails tailwindcss:watch
employee: bundle exec sidekiq

There, we have now three processes outlined:

  1. internet – the Rails internet server. This may be any command that runs your mission predominant logic.
  2. css – the Tailwind improvement server.
  3. employee – the Sidekiq course of that handles scheduled jobs.

You possibly can identify these nonetheless you need, there aren’t any guidelines to this. Use what is smart to you and your crew/coworkers.
The Procfile is normally saved within the root of the mission, and typically, you may have a number of of those. However, for the sake of simplicity, we’ll use only one for now and clarify later how one can use a number of information.

So, what now? How do you run processes after you’ve outlined them within the Procfile? Glad you requested, that is the place Overmind steps in.

Overmind – The Course of Runner

Most people would attain out to the Foreman instrument to run their processes by way of Procfile. Right now, we’ll present a greater technique to do it with a instrument known as Overmind.

Overmind is a instrument written by DarthSim and you may view its code at this GitHub repo. It’s extremely impressed by Foreman we talked about earlier than, however it solves a few issues Foreman (and different instruments) have. The issue with most of different instruments is that processes you wish to handle begin to suppose they’re logging their output right into a file, and that may result in all kinds of issues: extreme lagging and dropping or breaking coloured output. Instruments can even add self-importance data (unneeded timestamps in logs).

Overmind makes use of tmux beneath the hood to convey out some helpful options, so we have to set up that first with:

$ brew set up tmux

$ apt-get set up tmux

🤫 Psst, do you wish to study tmux the straightforward method? Right here’s a Mild Information to Get Began With tmux I wrote that will help you do this.

Nice, now let’s set up Overmind:

brew set up overmind

go set up

Superior, now that we have now Overmind set up, we will transfer to the foundation of our mission and begin all these course of with a single command:

For me, that is how the output appears:

Overmind start command starts processes from Procfile

“overmind begin” command begins processes from Procfile

Proper there, you may see all of the output properly rendered, with the well-known Sidekiq ASCII artwork printed out.

If we rapidly examine that to an output foreman does with foreman begin, we’ll see a unique output:

Foreman start command starts processes from Procfile

“foreman begin” command begins processes from Procfile

The output shouldn’t be as good as with Overmind.

However that’s not all. We did handle to start out processes outlined in Procfile efficiently and see the output, let’s now see the true deal of Overmind, let’s herald extra energy with it!

Mo Powa Babeh

More Power, Baby from Donut's James Pumphrey
Extra Energy, Child from Donut’s James Pumphrey

What makes Overmind nice for me is which you could simply connect with any of the processes that you just’re operating. Yeah, you can have an analogous factor if you happen to opened a few tabs and ran each command by itself, however we’re not right here for that, duh…

Overmind makes use of tmux – a terminal multiplexer beneath the hood. Don’t worry, you gained’t must study one other instrument (besides perhaps two or three instructions). By having tmux beneath the hood, we will simply run overmind join and it’ll shoot us straight right into a tmux session with our processes.

Check out:

Right here’s what I obtained:

Overmind connect launches a tmux session with running processes

“overmind join” launches a tmux session with operating processes

I obtained launched into the primary course of outlined in Procfile – the internet course of. The join function may be very highly effective as a result of it means that you can see the logs of all processes break up into tabs in tmux. You possibly can simply change tabs with Ctrl + b and the variety of a tab. For instance:

  1. Ctrl + b after which 1, switches you to the internet course of,
  2. Ctrl + b after which 2, switches you to the css course of,
  3. and also you get the concept.

Whereas contained in the tmux session with Overmind, it’s also possible to management debug course of if you happen to run a debugger in any of the processes. For instance, I put a debugger assertion in my Rails controller like so:

class PublicController < ApplicationController
  def index

And once I go to the house web page, my internet course of stops till I work together with the debugger. To make the internet course of transfer ahead, I rapidly kind overmind join internet and proceed the debugger.

Overmind connect Rails debugger

Rails debugger and Overmind

And now, to softly exit the session with out killing processes, use the Ctrl + b after which d. Congrats, you simply realized how one can change home windows in tmux and how one can exit a tmux session 👏.

However what if you happen to’re a tmux consumer already and all you do within the terminal is inside tmux? What if you happen to do overmind join inside a tmux session? Let’s discover out

Overmind in tmux

Let’s say you’re already utilizing tmux in your day-to-day endeavors and also you ran overmind join – what now? How do you exit with out killing every part Overmind is operating? First, right here’s how that appears:

Overmind inside tmux

Overmind inside tmux

On the prime, you may see I’ve the overmind window open in tmux. Then, under it, you see three home windows with internet, css, and employee open. The trick right here is to do the double Ctrl + b after which d. So do Ctrl + b Ctrl + b after which d. It will inform the second occasion of tmux (the one ran by Overmind) to detach from the session. Now, you have to be again to the tmux window you had been earlier than operating overmind join like so:

Regular tmux session

Common tmux session

OK, however what else can I do in Overmind? Glad you requested – I’ll present you a few extra options.

Extra Overmind options

You possibly can restart processes simply. Let’s say you made some modifications to the online server that requires you to restart it. Right here’s how one can do it:

You possibly can cease one thing with:

And if all goes improper, simply kill the entire thing with:

Yet one more factor I promised in the beginning – the a number of Procfile scenario. In some groups and initiatives, there are multiple Procfile. Normally, they’re known as Procfile and One serves for manufacturing, different for improvement. Or no matter different mixture you may consider. To have the ability to run Overmind with a file like, you might want to do it like so:

overmind begin --procfile

overmind s -f

Additionally, there are extra choices and options to discover over on the official docs in Overmind’s GitHub repo.
There’s a substitute for Overmind, particularly if you happen to don’t want all these options. It’s known as Hivemind.

Hivemind – Overmind’s little sister

In the event you don’t need all these options and need one thing to run all of the processes, contemplate Hivemind from the identical writer.

You may get it with:

brew set up hivemind

GO111MODULE=on go get -u -f

After that, you may run hivemind and that’s it. In fact, that’s all you get, there aren’t any further options like in Overmind. Right here’s how the output appears:

Hivemind output

Hivemind output

Wrapping Up

Thanks for studying this far, you’ve simply obtained launched to a few ideas:

  • Procfile– a file to outline processes wanted to run your mission
  • foreman– a instrument to run these processes rapidly
  • Overmind – a instrument that higher prints out logs and has superior options that will help you simply handle processes
  • Hivemind – a smaller sibling of Overmind
  • tmux – a terminal multiplexer that may enhance your productiveness regionally and/or distant servers

So I hope you had fun studying. And bear in mind, these are instruments made to make you’re feeling and be extra productive. Strive them out, or don’t, however I do know, if you happen to’re a real terminal junkie, you’re at all times looking out to noticed a keystroke or two.

Till the subsequent one, cheers!



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments