From ef73ed4291fca1a7b68bbc9bbeb5239c744e6b01 Mon Sep 17 00:00:00 2001 From: yangdx Date: Sun, 19 Jan 2025 12:53:13 +0800 Subject: [PATCH] Install Lightrag as a Linux Service (sample files and installation guide) --- lightrag/api/README.md | 33 +++++++++++++++++++++++++- lightrag/api/lightrag.service.example | 17 +++++++++++++ lightrag/api/start_lightrag.sh.example | 4 ++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 lightrag/api/lightrag.service.example create mode 100644 lightrag/api/start_lightrag.sh.example diff --git a/lightrag/api/README.md b/lightrag/api/README.md index 362e94e1..e0c835c6 100644 --- a/lightrag/api/README.md +++ b/lightrag/api/README.md @@ -342,7 +342,7 @@ curl http://localhost:9621/api/tags Handle chat completion requests -``` +```shell curl -N -X POST http://localhost:9621/api/chat -H "Content-Type: application/json" -d \ '{"model":"lightrag:latest","messages":[{"role":"user","content":"猪八戒是谁"}],"stream":true}' ``` @@ -424,3 +424,34 @@ This intelligent caching mechanism: - Only new documents in the input directory will be processed - This optimization significantly reduces startup time for subsequent runs - The working directory (`--working-dir`) stores the vectorized documents database + +## Install Lightrag as a Linux Service + +Create your service file: `lightrag.sevice`. Modified the following lines from `lightrag.sevice.example` + +```text +Description=LightRAG Ollama Service +WorkingDirectory= +ExecStart=/lightrag/api/start_lightrag.sh +``` + +Create your service startup script: `start_lightrag.sh`. Change you python virtual environment activation method as need: + +```shell +#!/bin/bash + +# python virtual environment activation +source /home/netman/lightrag-xyj/venv/bin/activate +# start lightrag api server +lightrag-server +``` + +Install lightrag.service in Linux. Sample commands in Ubuntu server look like: + +```shell +sudo cp lightrag-server.service /etc/systemd/system/ +sudo systemctl daemon-reload +sudo systemctl start lightrag-server.service +sudo systemctl status lightrag-server.service +sudo systemctl enable lightrag-server.service +``` diff --git a/lightrag/api/lightrag.service.example b/lightrag/api/lightrag.service.example new file mode 100644 index 00000000..5113ddde --- /dev/null +++ b/lightrag/api/lightrag.service.example @@ -0,0 +1,17 @@ +[Unit] +Description=LightRAG XYJ Ollama Service +After=network.target + +[Service] +Type=simple +User=netman +# Memory settings +MemoryHigh=8G +MemoryMax=12G +WorkingDirectory=/home/netman/lightrag-xyj +ExecStart=/home/netman/lightrag-xyj/lightrag/api/start_lightrag_server.sh +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target diff --git a/lightrag/api/start_lightrag.sh.example b/lightrag/api/start_lightrag.sh.example new file mode 100644 index 00000000..89c814fb --- /dev/null +++ b/lightrag/api/start_lightrag.sh.example @@ -0,0 +1,4 @@ +#!/bin/bash + +source /home/netman/lightrag-xyj/venv/bin/activate +lightrag-server