Blog
Flox 1.3: Simplified Service Management with Flox
Steve Swoyer | 22 August 2024
Flox makes it easy to install and run virtually any kind of service in a dev environment.
Need a local nginx
reverse proxy? Or a Redis caching layer to mimic the one in your production environment? How about a local PostgreSQL or Kafka instance? Just fire up a terminal and flox install
them.
With the new service management capabilities shipping in Flox 1.3.0, this story gets even better!
Starting and stopping services is now a cinch, because Flox takes care of all the background setup and teardown tasks for you. So instead of authoring logic to watchdog your services, you can just define the ones you need Flox to manage in a software manifest.
But rather than telling you, let’s show you—by walking you through a couple of concrete examples.
You’ll not only learn how service management works, but also how it makes Flox’s simple, intuitive approach to creating and sharing reproducible dev environments that much simpler.
A turn-key local LLM
Flox’s Ollama example environment makes it easy to run Llama, Mixtral, and other powerful LLMs locally.
But our initial version of this environment shipped without service management, which was still being built into Flox at the time. So achieving this behavior required authoring chunks of monitoring and control logic for the environment’s separate [hook]
and [profile]
sections. Here’s an excerpt from [hook]
:
Using service management, you can achieve the same result—an ollama serve
that starts when you flox activate
your environment and terminates when you exit—with just a fraction of the logic. To wit:
That’s it. That’s all you’ve gotta do. For existing users, the biggest change is primarily one of muscle memory: to start your service(s) at activation, you’ve got to use the flox activate -s
command-line flag. (That’s short for --start-services
.)
You can check the status of your service(s) by using the new flox services status
command:
With service management, ollama serve
automatically shuts down when you exit your environment, but you can also stop it manually—or start it back up again—should you need to:
That is service management in a nutshell.
But while a turn-key, ephemeral Ollama service is cool, a similar option for PostgreSQL would be amazing. So let’s pivot to Flox’s service management-enabled PostgreSQL example environment!
An on-when-you-need-it, off-when-you-don’t PostgreSQL environment
Between them, Flox’s Graham Hudgins and Ross Turk created a kinda cool PostgreSQL example environment to showcase service management. For this use case, they didn’t even need to replace any “prior art” in the form of service setup/teardown scripting logic. And that’s a good thing! After all, authoring logic that (a) autostarts a PostgreSQL instance, (b) spins up a background (watchdog) task to monitor its operation and (c) reliably shut it down is slightly more complicated than authoring shell traps.
Using this environment is as easy as pulling it from FloxHub and dusting off one’s SQL knowledge:
Beneath this surface sheen of simplicity, there’s a lot of scaffolding built into this service-enabled environment. Let’s take a look at its components.
First, there’s the obligatory install section:
Next, the requisite services
entry:
We use the [vars]
section in the environment’s manifest.toml
to define a local user and database, and configure PostgreSQL so it listens on a local port.
Note: Instead of hardcoding PGUSER
and PGPASS
in your environment’s manifest.toml
, you could instead opt to retrieve them from a secrets manager like 1Password at runtime. Flox activation hooks give you an easy way to securely inject PGUSER, PGPASS, and other secrets into the environment when they’re needed.
The [hook] section performs setup and configuration tasks that don’t involve starting and monitoring the PostgreSQL service, like specifying data directories and initializing a new database instance using initdb
, if one doesn't already exist.
If you forget to flox activate -s
then you can manually start your services within an activated environment:
Even though I started postgresql
manually, as soon as I quit my environment, it ceases to exist. Flox automatically cleans it up.
You can use service management in Flox to build as many services as you need into your environments, without authoring logic to set them up or tear them down. Plus, Flox environments are easy to work with, especially in the local context, because you get direct access to your system’s settings and resources.
Think of this article as Service Managment (SM) 101. For SM 202, we’ll be showcasing a Floxified retrieval-augmented generation (RAG) stack. You won’t wanna miss that!
One giant leap for reproducible software development
Service management is a great demonstration of how rapidly Flox is maturing. Just six months ago, you couldn’t install as many different software packages and versions. You didn’t have a reproducible way to use software that wasn’t already in Flox Catalog in your projects. And you couldn’t easily share Flox environments with your team members.
Flox got a whole lot more powerful in just a few months!
How powerful will Flox be six months from now? Why wait to find out? Flox is free to use and it’s great for everything from quick-and-dirty proofs-of-concept on your local system to reproducible runtimes in CI and production. Plus, you can get started in fewer than five minutes.
Download Flox today and put it to the test!