%define dist_tag %(sed -n 's/.*release \\([0-9]*\\)\.\\([0-9]*\\).*[Ss][Pp]\\([0-9]*\\).*/oe\\1\\2sp\\3/p; t; s/.*release \\([0-9]*\\)\.\\([0-9]*\\).*/oe\\1\\2/p' /etc/openEuler-release) %global _unitdir /usr/lib/systemd/system Name: loggpt Version: 1.0.0 Release: 1.%{?dist_tag} Summary: loggpt Service License: MulanPSL-2.0 URL: https://gitee.com/Victeo/AOPS_MCP_Server Source0: %{name}-%{version}.tar.gz %global debug_package %{nil} %global _enable_debug_package 0 BuildRequires: python3-setuptools BuildRequires: python3-pip Requires: python3, systemd # Requires: python3-pandas AutoReq: no AutoProv: no %description loggpt Service packaged as RPM. %prep %setup -q %build mkdir -p %{_builddir}/%{name}-%{version}/wheelhouse # 下载项目依赖包(包括构建依赖) %{__python3} -m pip download \ --only-binary :all: \ -d %{_builddir}/%{name}-%{version}/wheelhouse \ -r requirements.txt \ setuptools wheel pip \ -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple %{__python3} -m pip download \ -d %{_builddir}/%{name}-%{version}/wheelhouse \ torch==2.8.0+cpu --index-url https://mirrors.aliyun.com/pytorch-wheels/cpu/ cd %{_builddir}/%{name}-%{version}/ && tar -zcf wheelhouse.tar.gz wheelhouse rm -rf %{_builddir}/%{name}-%{version}/wheelhouse %install rm -rf %{buildroot} # 创建应用目录 mkdir -p %{buildroot}/opt/%{name} mkdir -p %{buildroot}/opt/%{name}/wheelhouse # 复制wheelhouse离线包 tar -zxf %{_builddir}/%{name}-%{version}/wheelhouse.tar.gz -C %{buildroot}/opt/%{name}/ rm -rf %{_builddir}/%{name}-%{version}/wheelhouse.tar.gz # 复制项目代码(排除不需要的文件) find %{_builddir}/%{name}-%{version} -maxdepth 1 \ ! -name 'wheelhouse' \ ! -name 'build' \ ! -name 'venv' \ -exec cp -r {} %{buildroot}/opt/%{name}/ \; # 复制 systemd 服务文件 mkdir -p %{buildroot}%{_unitdir} install -m 644 loggpt.service %{buildroot}%{_unitdir}/ # 创建可执行文件符号链接 mkdir -p %{buildroot}%{_bindir} ln -s /opt/%{name}/venv/bin/loggpt %{buildroot}%{_bindir}/loggpt %post # 创建虚拟环境 python3 -m venv /opt/%{name}/venv source /opt/%{name}/venv/bin/activate # 首先安装基本构建工具 /opt/%{name}/venv/bin/pip install --no-index --find-links=/opt/%{name}/wheelhouse \ setuptools wheel pip # 安装离线依赖包 /opt/%{name}/venv/bin/pip install --no-index --find-links=/opt/%{name}/wheelhouse \ /opt/%{name}/wheelhouse/* # 安装当前项目 /opt/%{name}/venv/bin/pip install \ --no-index \ --find-links=/opt/%{name}/wheelhouse \ --no-build-isolation \ /opt/%{name} deactivate # 清理wheelhouse节省空间 # rm -rf /opt/%{name}/wheelhouse # 修复shebang路径 find /opt/%{name}/venv/bin -type f -exec \ sed -i "1s|^#!.*|#!/opt/%{name}/venv/bin/python|" {} \; # systemd 配置 %systemd_post loggpt.service %preun # 卸载前停止服务 %systemd_preun loggpt.service %postun # 清理配置 rm -rf /opt/%{name} %systemd_postun_with_restart loggpt.service %files %dir /opt/%{name} /opt/%{name}/* %exclude /opt/%{name}/.git* %license LICENSE %{_bindir}/loggpt %{_unitdir}/loggpt.service %changelog * Tue Sep 16 2025 ShiLei <845621916@qq.com> - 1.0-1 - Initial package