Systemd service

You can run Chroma as a systemd service which wil allow you to automatically start Chroma on boot and restart it if it crashes.

Docker Compose

The following is an examples systemd service for running Chroma using Docker Compose.

Create a file /etc/systemd/system/chroma.service with the following content:

Example assumptions

The below example assumes Debian-based system with docker-ce installed.

  1. [Unit]
  2. Description = Chroma Service
  3. After = network.target docker.service
  4. Requires = docker.service
  5. [Service]
  6. Type = forking
  7. User = root
  8. Group = root
  9. WorkingDirectory = /home/admin/chroma
  10. ExecStart = /usr/bin/docker compose up -d
  11. ExecStop = /usr/bin/docker compose down
  12. RemainAfterExit = true
  13. [Install]
  14. WantedBy = multi-user.target

Replace WorkingDirectory with the path to your docker compose is. You may also need to replace /usr/bin/docker with the path to your docker binary.

Alternatively you can install directly from a gist:

  1. wget https://gist.githubusercontent.com/tazarov/9c46966de0b32a4962dcc79dce8b2646/raw/7cf8c471f33fba8a51d6f808f9b1af6ca1b0923c/chroma-docker.service \
  2. -O /etc/systemd/system/chroma.service

Loading, enabling and starting the service:

  1. sudo systemctl daemon-reload
  2. sudo systemctl enable chroma
  3. sudo systemctl start chroma

Type=forking

In the above example, we use Type=forking because Docker Compose runs in the background (-d). If you are using a different command that runs in the foreground, you may need to use Type=simple instead.

Chroma CLI

The following is an examples systemd service for running Chroma using the Chroma CLI.

Create a file /etc/systemd/system/chroma.service with the following content:

Example assumptions

The below example assumes that Chroma is installed in Python site-packages package.

  1. [Unit]
  2. Description = Chroma Service
  3. After = network.target
  4. [Service]
  5. Type = simple
  6. User = root
  7. Group = root
  8. WorkingDirectory = /chroma
  9. ExecStart=/usr/local/bin/chroma run --host 127.0.0.1 --port 8000 --path /chroma/data --log-path /var/log/chroma.log
  10. [Install]
  11. WantedBy = multi-user.target

Replace the WorkingDirectory, /chroma/data and /var/log/chroma.log with the appropriate paths.

Safe Config

The above example service listens and localhost which may not work if you are looking to expose Chroma to outside world. Adjust the --host and --port flags as needed.

Alternatively you can install from a gist:

  1. wget https://gist.githubusercontent.com/tazarov/5e10ce892c06757d8188a8a34cd6d26d/raw/327a9d0b07afeb0b0cb77453aa9171fdd190984f/chroma-cli.service \
  2. -O /etc/systemd/system/chroma.service

Loading, enabling and starting the service:

  1. sudo systemctl daemon-reload
  2. sudo systemctl enable chroma
  3. sudo systemctl start chroma

Type=simple

In the above example, we use Type=simple because the Chroma CLI runs in the foreground. If you are using a different command that runs in the background, you may need to use Type=forking instead.

May 16, 2024