From 9bf5f1bf7a4eed4b7a26082911818faea5203499 Mon Sep 17 00:00:00 2001 From: "Mauro Rosero P." Date: Fri, 21 Mar 2025 20:08:22 -0500 Subject: [PATCH] [ADDED] Scripts ollama_up.sh y ollama_down.sh para gestionar servicio Ollama (IA local) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Creados scripts para iniciar y detener el servicio Ollama con podman-compose - Actualizada la configuraci贸n para usar la imagen oficial desde docker.io - Implementada compatibilidad con docker y podman - A帽adida documentaci贸n en README.md 馃 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CLAUDE.md | 2 +- README.md | 2 + bin/ansible/includes/load_messages.yaml | 8 +- bin/ansible/includes/sops_credentials.yaml | 8 +- bin/ansible/messages/MESG-ES.yaml | 30 +++--- bin/ansible/pritunl_users.yaml | 10 +- bin/ollama/podman-compose.yml | 12 +++ bin/ollama_down.sh | 94 +++++++++++++++++ bin/ollama_up.sh | 115 +++++++++++++++++++++ bin/vpn_users.sh | 1 + 10 files changed, 254 insertions(+), 28 deletions(-) create mode 100644 bin/ollama/podman-compose.yml create mode 100755 bin/ollama_down.sh create mode 100755 bin/ollama_up.sh diff --git a/CLAUDE.md b/CLAUDE.md index a99f239..84ce2aa 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,7 +31,7 @@ - Use `bin/config/bash.header` how example to bash comment header - For new projects created by Claude Code, use author: "Cortana Rosero One " - Include reference indicating generation by Claude Code and the version used -- Example header comment: +- Example header comment for Cortana: ``` # [Author] Cortana Rosero One # [Generated] Created by Claude Code (claude-3-7-sonnet-20250219) diff --git a/README.md b/README.md index f48db90..494b63b 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ bin/update.sh | `bin/sora_enable.sh` | Activa el alias 'sora' para Aider permanentemente | | `bin/sora_disable.sh` | Desactiva el alias 'sora' para Aider | | `bin/ai_token.sh` | Gestiona tokens de m煤ltiples proveedores de IA v铆a SOPS | +| `bin/ollama_up.sh` | Inicia el servicio Ollama (IA local) con podman-compose | +| `bin/ollama_down.sh` | Detiene el servicio Ollama (IA local) | ### Herramientas para Editores de C贸digo diff --git a/bin/ansible/includes/load_messages.yaml b/bin/ansible/includes/load_messages.yaml index 4a83b86..b150e16 100644 --- a/bin/ansible/includes/load_messages.yaml +++ b/bin/ansible/includes/load_messages.yaml @@ -1,11 +1,11 @@ --- -# Include: includes/load_messages.yaml +# Apps: MRDevs Tools +# Include: bin/ansible/includes/load_messages.yaml # Description: load messages languages # Author: Mauro Rosero P. # Email: mauro@rosero.one (mauro.rosero@gmail.com) -# Organization: ROSERO ONE -# Created: Ene 04, 2025 12:00:00 -# Updated: 2025-01-05 00:00:00 +# Created: 2025-01-04 12:00:00 +# Modified: 2025-01-05 00:00:00 - name: Include language vars messages file ansible.builtin.include_vars: diff --git a/bin/ansible/includes/sops_credentials.yaml b/bin/ansible/includes/sops_credentials.yaml index 26817bf..9465289 100644 --- a/bin/ansible/includes/sops_credentials.yaml +++ b/bin/ansible/includes/sops_credentials.yaml @@ -1,11 +1,11 @@ --- -# Include: includes/sops_credentials.yaml +# Apps: MRDevs Tools +# Include: bin/ansible/includes/sops_credentials.yaml # Description: Get sops secure encrypted credentials # Author: Mauro Rosero P. # Email: mauro@rosero.one (mauro.rosero@gmail.com) -# Organization: ROSERO ONE -# Created: Ene 04, 2025 12:00:00 -# Updated: 2025-01-05 00:00:00 +# Created: 2025-01-04 12:00:00 +# Modified: 2025-01-05 00:00:00 - name: Get if credential access exists ansible.builtin.stat: diff --git a/bin/ansible/messages/MESG-ES.yaml b/bin/ansible/messages/MESG-ES.yaml index 109f212..abb1b49 100644 --- a/bin/ansible/messages/MESG-ES.yaml +++ b/bin/ansible/messages/MESG-ES.yaml @@ -5,16 +5,20 @@ # Global Definitions & Parameters # Created 2024-03-14-00:12:00 # Updated 2024-06-01-00:41:00 - - console: - info: - hello: "{{ info }}Bienvenido, esto es una prueba" - warn: - hello: "{{ warn }}Bienvenido, esto es una prueba" - error: - hello: "{{ fail }}Bienvenido, esto es una prueba" - no_credentials: "{{ fail }}Archivo de credenciales sops no definido!" - credentials_fail: "{{ fail }}Archivo de credenciales es incorrecto!" - no_pritunl_user: "{{ fail }}USUARIO PRITUNL VPN no fue definido!" - no_pritunl_email: "{{ fail }}Correo electr贸nico de USUARIO PRITUNL VPN no fue definido!" - no_pritunl_action: "{{ fail }}Acci贸n para gesti贸n de USUARIO PRITUNL VPN es invalida!" + + info: "INFO" + warn: "ALERTA" + fail: "ERROR" + + console: + info: + hello: "{{ info }}Bienvenido, esto es una prueba" + warn: + hello: "{{ warn }}Bienvenido, esto es una prueba" + error: + hello: "{{ fail }}Bienvenido, esto es una prueba" + no_credentials: "{{ fail }}Archivo de credenciales sops no definido!" + credentials_fail: "{{ fail }}Archivo de credenciales es incorrecto!" + no_pritunl_user: "{{ fail }}USUARIO PRITUNL VPN no fue definido!" + no_pritunl_email: "{{ fail }}Correo electr贸nico de USUARIO PRITUNL VPN no fue definido!" + no_pritunl_action: "{{ fail }}Acci贸n para gesti贸n de USUARIO PRITUNL VPN es invalida!" diff --git a/bin/ansible/pritunl_users.yaml b/bin/ansible/pritunl_users.yaml index 166ac98..69225ad 100644 --- a/bin/ansible/pritunl_users.yaml +++ b/bin/ansible/pritunl_users.yaml @@ -1,13 +1,11 @@ --- -# Devops Ansible Script -# Playbook: pritunl_users.yaml +# Apps: MRDevs Tools +# Playbook: bin/ansible/pritunl_users.yaml # Description: Add, enable, disable or remove pritunl vpn users # Author: Mauro Rosero P. # Email: mauro@rosero.one (mauro.rosero@gmail.com) -# Organization: ROSERO ONE -# Created: Ene 04, 2025 12:00:00 -# Updated: 2025-01-05 00:00:00 - +# Created: 2025-01-04 12:00:00 +# Modified: 2025-01-05 00:00:00 - name: PLAYBOOK - {{ playbook_program | upper }} ({{ playbook_description | upper }}) hosts: [localhost] diff --git a/bin/ollama/podman-compose.yml b/bin/ollama/podman-compose.yml new file mode 100644 index 0000000..905184b --- /dev/null +++ b/bin/ollama/podman-compose.yml @@ -0,0 +1,12 @@ +version: "3.8" + +services: + ollama: + image: docker.io/ollama/ollama:latest + container_name: ollama + privileged: true + ports: + - "11434:11434" + volumes: + - ../../data:/root/.ollama + restart: unless-stopped diff --git a/bin/ollama_down.sh b/bin/ollama_down.sh new file mode 100755 index 0000000..e3af4f6 --- /dev/null +++ b/bin/ollama_down.sh @@ -0,0 +1,94 @@ +#!/bin/bash +#Script : ollama_down.sh +#Apps : MRDEVS TOOLS +#Description : Detener ollama (IA) en modo local +#Author : Mauro Rosero P茅rez +#Company Email : mauro@rosero.one +#Personal Email : mauro.rosero@gmail.com +#Created : 2025/03/21 19:27:08 +#Modified : 2025/03/21 19:27:08 +#Version : 1.2.0 +#============================================================================== +# Derechos de Autor [2025] [Mauro Rosero P. ] +#============================================================================== +# Este programa es software libre: usted puede redistribuirlo y/o modificarlo +# bajo los t茅rminos de la Licencia P煤blica Affero General de GNU tal como +# lo publica la Free Software Foundation, ya sea la versi贸n 3 de la licencia, +# o (a su elecci贸n) cualquier versi贸n posterior. +# +# Este programa se distribuye con la esperanza de que sea 煤til, +# pero SIN NINGUNA GARANT脥A; sin siquiera la garant铆a impl铆cita de +# COMERCIABILIDAD o IDONEIDAD PARA UN PROP脫SITO PARTICULAR. Consulte la +# Licencia P煤blica Affero General de GNU para obtener m谩s detalles. +# +# Deber铆a haber recibido una copia de la Licencia P煤blica Affero General +# junto con este programa. Si no la recibi贸, consulte . + +# Configuraci贸n inicial +# Usar DEVELOPER_DIR de base.lib +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BIN_BASE="bin" +BIN_LIBS="lib" +BIN_MESG="msg" +BIN_CFGS="config" + +# Leer DEVSPATH desde el archivo de configuraci贸n o usar "devs" por defecto +if [ -f "$SCRIPT_DIR/config/devspath.dat" ]; then + DEVSPATH=$(cat "$SCRIPT_DIR/$BIN_CFGS/devspath.dat") +else + DEVSPATH="devs" +fi + +BIN_HOME="$HOME/$DEVSPATH" +BIN_PATH=$BIN_HOME/$BIN_BASE +VERSION=$(cat "$BIN_HOME/$BIN_BASE/$BIN_CFGS/version") + +# CHECK SHELL LANGUAGE +BIN_LANG=${LANG:0:2} + +set -e + +# Importar bibliotecas necesarias +source "${BIN_HOME}/${BIN_BASE}/${BIN_LIBS}/base.lib" + +# Cargar mensajes en el idioma del sistema o espa帽ol por defecto +load_messages "${BIN_HOME}/${BIN_BASE}" "${BIN_MESG}" "${BIN_LANG}" "head" +title="${head_000} ${head_002}" + +# Change to the directory containing the compose file +cd "${BIN_HOME}/${BIN_BASE}/ollama" + +# Check if we should use podman or docker (prefer podman) +if command -v podman >/dev/null 2>&1; then + CONTAINER_CMD="podman" +elif command -v docker >/dev/null 2>&1; then + CONTAINER_CMD="docker" +else + echo "Error: Neither podman nor docker is installed" + exit 1 +fi + +# Check if compose command exists +if command -v ${CONTAINER_CMD}-compose >/dev/null 2>&1; then + COMPOSE_CMD="${CONTAINER_CMD}-compose" +elif command -v podman-compose >/dev/null 2>&1; then + COMPOSE_CMD="podman-compose" +elif command -v docker-compose >/dev/null 2>&1; then + COMPOSE_CMD="docker-compose" +else + echo "Error: No compose command found (podman-compose or docker-compose)" + exit 1 +fi + +echo "Using ${COMPOSE_CMD} to stop Ollama service..." + +# Try to stop with compose first +${COMPOSE_CMD} down || echo "Warning: Issue with ${COMPOSE_CMD} down command" + +# If the container is still running, try to stop it directly +if ${CONTAINER_CMD} container exists ollama 2>/dev/null && ${CONTAINER_CMD} ps | grep -q ollama; then + echo "Stopping ollama container directly..." + ${CONTAINER_CMD} stop ollama +fi + +echo "${head_002} Ollama service stopped successfully" diff --git a/bin/ollama_up.sh b/bin/ollama_up.sh new file mode 100755 index 0000000..8cab80c --- /dev/null +++ b/bin/ollama_up.sh @@ -0,0 +1,115 @@ +#!/bin/bash +#Script : ollama_up.sh +#Apps : MRDEVS TOOLS +#Description : Ejecutar ollama (IA) en modo local +#Author : Mauro Rosero P茅rez +#Company Email : mauro@rosero.one +#Personal Email : mauro.rosero@gmail.com +#Created : 2025/03/21 19:27:08 +#Modified : 2025/03/21 19:27:08 +#Version : 1.2.0 +#============================================================================== +# Derechos de Autor [2025] [Mauro Rosero P. ] +#============================================================================== +# Este programa es software libre: usted puede redistribuirlo y/o modificarlo +# bajo los t茅rminos de la Licencia P煤blica Affero General de GNU tal como +# lo publica la Free Software Foundation, ya sea la versi贸n 3 de la licencia, +# o (a su elecci贸n) cualquier versi贸n posterior. +# +# Este programa se distribuye con la esperanza de que sea 煤til, +# pero SIN NINGUNA GARANT脥A; sin siquiera la garant铆a impl铆cita de +# COMERCIABILIDAD o IDONEIDAD PARA UN PROP脫SITO PARTICULAR. Consulte la +# Licencia P煤blica Affero General de GNU para obtener m谩s detalles. +# +# Deber铆a haber recibido una copia de la Licencia P煤blica Affero General +# junto con este programa. Si no la recibi贸, consulte . + +# Configuraci贸n inicial +# Usar DEVELOPER_DIR de base.lib +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BIN_BASE="bin" +BIN_LIBS="lib" +BIN_MESG="msg" +BIN_CFGS="config" + +# Leer DEVSPATH desde el archivo de configuraci贸n o usar "devs" por defecto +if [ -f "$SCRIPT_DIR/config/devspath.dat" ]; then + DEVSPATH=$(cat "$SCRIPT_DIR/$BIN_CFGS/devspath.dat") +else + DEVSPATH="devs" +fi + +BIN_HOME="$HOME/$DEVSPATH" +BIN_PATH=$BIN_HOME/$BIN_BASE +VERSION=$(cat "$BIN_HOME/$BIN_BASE/$BIN_CFGS/version") + +# CHECK SHELL LANGUAGE +BIN_LANG=${LANG:0:2} + +set -e + +# Importar bibliotecas necesarias +source "${BIN_HOME}/${BIN_BASE}/${BIN_LIBS}/base.lib" + +# Cargar mensajes en el idioma del sistema o espa帽ol por defecto +load_messages "${BIN_HOME}/${BIN_BASE}" "${BIN_MESG}" "${BIN_LANG}" "head" +title="${head_000} ${head_002}" + +# Change to the directory containing the compose file +cd "${BIN_HOME}/${BIN_BASE}/ollama" + +# Check if we should use podman or docker (prefer podman) +if command -v podman >/dev/null 2>&1; then + CONTAINER_CMD="podman" +elif command -v docker >/dev/null 2>&1; then + CONTAINER_CMD="docker" +else + echo "Error: Neither podman nor docker is installed" + exit 1 +fi + +# Check if compose command exists +if command -v ${CONTAINER_CMD}-compose >/dev/null 2>&1; then + COMPOSE_CMD="${CONTAINER_CMD}-compose" +elif command -v podman-compose >/dev/null 2>&1; then + COMPOSE_CMD="podman-compose" +elif command -v docker-compose >/dev/null 2>&1; then + COMPOSE_CMD="docker-compose" +else + echo "Error: No compose command found (podman-compose or docker-compose)" + exit 1 +fi + +echo "Using ${COMPOSE_CMD} to start Ollama service..." + +# Fix relative path in volume mount if needed +if grep -q "../../data:/root/.ollama" "${BIN_HOME}/${BIN_BASE}/ollama/podman-compose.yml"; then + # Create data directory if it doesn't exist + mkdir -p "${BIN_HOME}/data" + + # Start Ollama service with compose + ${COMPOSE_CMD} -f podman-compose.yml up -d +else + ${COMPOSE_CMD} up -d +fi + +# Verify container is running +if ! ${CONTAINER_CMD} container exists ollama 2>/dev/null || ! ${CONTAINER_CMD} ps | grep -q ollama; then + echo "Warning: Container may not be running properly. Trying direct container command..." + + # Try to start it directly if it exists + if ${CONTAINER_CMD} container exists ollama 2>/dev/null; then + echo "Starting existing ollama container..." + ${CONTAINER_CMD} start ollama + else + echo "Creating ollama container directly..." + ${CONTAINER_CMD} run -d --name ollama \ + --privileged \ + -p 11434:11434 \ + -v "${BIN_HOME}/data:/root/.ollama" \ + --restart unless-stopped \ + docker.io/ollama/ollama:latest + fi +fi + +echo "${head_002} Ollama service started successfully" diff --git a/bin/vpn_users.sh b/bin/vpn_users.sh index fdce4c7..62b6617 100755 --- a/bin/vpn_users.sh +++ b/bin/vpn_users.sh @@ -34,6 +34,7 @@ BIN_BASE="bin" BIN_LIBS="lib" BIN_MESG="msg" BIN_CFGS="config" +BIN_ANSIBLE="ansible" # Leer DEVSPATH desde el archivo de configuraci贸n o usar "devs" por defecto if [ -f "$SCRIPT_DIR/$BIN_CFGS/devspath.dat" ]; then