Flox environments have a built-in concept of services. Flox environment services are managed by invoking theDocumentation Index
Fetch the complete documentation index at: https://flox.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
flox services
category of sub-commands such as flox services status.
In some scenarios, you may want to register Flox services to be run and managed
by the operating system’s systemd.
For example, systemd can auto-start services when the host is booting
or when a service crashes.
This tutorial shows how to create and use systemd services with Flox
by creating unit files manually.
You will learn how to run a Flox environment service as both a
systemd user unit and a systemd system unit.
Prerequisites
- A Linux system with systemd support. This tutorial was tested on Ubuntu 24.04 and 26.04.
- Flox installed in multi-user mode. This tutorial was tested on Flox 1.11.0.
Constraints
- The systemd service that invokes Flox cannot run as root.
- The service cannot listen on a port with a value less than 1024.
- The UID for the user running the systemd service should be >= 1000 for logs to function properly. See flox#2e789b5 for details.
- Logs may not function properly if the process forks. See flox#9b1e750 for details.
Run a Flox environment service as a systemd user unit
In this section you will set up a Redis service from a FloxHub environment and run it as a systemd user unit.Create the Redis environment locally
Pull theflox/redis environment from FloxHub into your home directory:
Test the environment with Flox services
Before creating the systemd unit, verify that the environment works:Create the systemd user service
Create the systemd user unit file:User unit cleanup
To stop and fully remove the systemd user unit:Run a Flox environment service as a systemd system unit
For services that should run under a dedicated system user rather than your personal account, you can create a system-level systemd unit instead.Create a dedicated Redis user and environment
Create the system unit file
Since theredis user has no login session,
user units will not work.
Create a system unit instead:
NoteEnable lingering is not needed for system units.
System units start at boot automatically.
Load, enable, and start
Verify
NoteKey differences from the user unit approach:
the system unit goes in
/etc/systemd/system/,
uses multi-user.target,
requires sudo,
and no lingering is needed.