Skip to content

LiteLLM Docker Compose System Integration

This document explains the usage and logic of the deploy-litellm-systemd.sh script, which installs and configures a systemd unit to automatically start a Docker Compose stack for LiteLLM on system boot.

Download file here


๐Ÿ“„ Script Overview

The script performs the following:

  1. Validates necessary paths, binaries, and user presence.
  2. Generates a systemd unit file for Docker Compose-based service.
  3. Enables the unit for autostart on boot.
  4. Uses qcuser as the execution user for the service.
  5. Must be configured by root or sudo user.

๐Ÿงน Prerequisites

Ensure the following:

  • Docker is installed and available at /usr/bin/docker
  • The Docker Compose project is located at: /home/qcuser/litellm/
  • The qcuser user exists and owns the project folder
  • Systemd is present (all Debian/Ubuntu systems have it)

๐Ÿ“ Directory Structure

Expected directory layout:

/home/qcuser/litellm/
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ other-compose-files.yml (optional)

โš™๏ธ Script Content and Explanation

#!/bin/bash
set -e
  • set -e: Exit immediately if any command fails.

๐Ÿ”ง Configuration Variables

SERVICE_NAME="litellm-root.service"
SERVICE_PATH="/etc/systemd/system/$SERVICE_NAME"
COMPOSE_DIR="/home/qcuser/litellm"
DOCKER_COMPOSE_BIN="/usr/bin/docker"

Defines systemd service name, its path, working directory, and the Docker binary location.


โœ… Checks

if [ ! -d "$COMPOSE_DIR" ]; then ...
  • Verifies the Docker Compose project directory exists.
  • Checks if qcuser exists.
  • Confirms Docker binary is accessible.

โš ๏ธ Overwrite Confirmation

if [ -f "$SERVICE_PATH" ]; then ...
  • If the unit already exists, prompts the user before overwriting it.

๐Ÿ“„ systemd Unit Creation

Creates a unit file with docker compose up -d as the ExecStart and docker compose down as the ExecStop.

[Unit]
Description=LiteLLM Docker Compose Autostart
After=network.target docker.service
Requires=docker.service

[Service]
Type=oneshot
WorkingDirectory=/home/qcuser/litellm
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
RemainAfterExit=true
User=qcuser
Group=qcuser

[Install]
WantedBy=multi-user.target

๐Ÿ”„ Enable and Reload systemd

sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"

Reloads systemd configuration and enables the unit for autostart.


๐Ÿš€ Final Output

Systemd unit litellm-root.service is ready and enabled for autostart.
Current running containers will not be affected.

Confirms that the unit is ready and won't interrupt currently running containers.


๐Ÿฅช Usage

To start the service:

sudo systemctl start litellm-root.service

To stop the service:

sudo systemctl stop litellm-root.service

To check status:

systemctl status litellm-root.service

To view logs:

journalctl -u litellm-root.service

Changelog

Date Author Message
2026-02-25 aresnikowa Merge remote-tracking branch 'origin/master'