+custom services

This commit is contained in:
m3tam3re
2025-03-13 13:42:25 +01:00
parent aa1e617e3a
commit c4bff08f72
5 changed files with 44 additions and 133 deletions

View File

@ -10,7 +10,7 @@ import? "/etc/self-host-playbook/tiers/premium.just"
gum style \
--foreground 212 --border double --border-foreground 212 \
--align center --width 50 --margin "1 2" --padding "1 2" \
"🚀 DevOps Control Center 🚀"
"🚀 Self-Hosting Playbook Command Center 🚀"
}
# Function to create menu items with icons and descriptions
@ -20,6 +20,7 @@ import? "/etc/self-host-playbook/tiers/premium.just"
echo "💾 Disk Usage - Show docker disk usage"
echo "🔄 Restart - Restart a specific container"
echo "🐳 Update Docker - Update Docker containers"
echo "🌐 Add custom service"
echo "❌ Exit"
}
@ -58,7 +59,9 @@ import? "/etc/self-host-playbook/tiers/premium.just"
"🐳 Update Docker"*)
just update-containers
;;
"❌ Exit")
"🌐 Add custom"*)
just add-custom-service
;; "❌ Exit")
echo "Goodbye! 👋" | gum style --foreground 212
exit 0
;;

View File

@ -1,101 +1,14 @@
status:
#!/usr/bin/env bash
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "📊 Running Containers"
docker ps --format "table {{"{{.Names}}\t{{.Status}}"}}" | gum table
@/etc/self-host-playbook/scripts/status.sh
# Interactive logs viewer with gum
logs:
#!/usr/bin/env bash
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "📝 Docker Logs Viewer"
# Get running container names
containers=($(docker ps --format "{{"{{.Names}}"}}"))
if [ ${#containers[@]} -eq 0 ]; then
gum style --foreground 1 "⚠️ No running containers found"
exit 1
fi
# Select container using gum choose
container=$(printf "%s\n" "${containers[@]}" | gum choose --header "Select a container:" --cursor.foreground 212)
if [ -z "$container" ]; then
exit 0
fi
# Select number of lines using gum choose
lines=$(gum choose --header "Select number of log lines:" --cursor.foreground 212 \
"5 lines" "10 lines" "25 lines" "50 lines" "100 lines" "200 lines")
if [ -z "$lines" ]; then
exit 0
fi
# Extract number from selection
lines=${lines%% *}
# Show spinner while fetching logs
gum spin --spinner dot --title "Fetching logs..." -- sleep 1
# Show logs
docker logs "$container" 2>&1 | tail -n "$lines" | gum pager
@/etc/self-host-playbook/scripts/logs.sh
docker-disk:
#!/usr/bin/env bash
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "💾 Docker Disk Usage"
docker system df | gum table
@/etc/self-host-playbook/scripts/docker-disk.sh
docker-restart:
#!/usr/bin/env bash
containers=($(docker ps --format "{{"{{.Names}}"}}"))
if [ ${#containers[@]} -eq 0 ]; then
gum style --foreground 1 "⚠️ No running containers found"
exit 1
fi
container=$(printf "%s\n" "${containers[@]}" | gum choose --header "Select a container to restart:" --cursor.foreground 212)
if [ -n "$container" ]; then
gum spin --spinner dot --title "Restarting $container..." -- docker restart "$container"
gum style --foreground 212 "✅ Container $container restarted successfully!"
fi
@/etc/self-host-playbook/scripts/docker-restart.sh
update-containers:
#!/usr/bin/env bash
set -e # Exit on error
CONTAINERS=($(docker ps --format "{{"{{.Names}}"}}"))
echo "Will update these containers:"
printf '%s\n' "${CONTAINERS[@]}" | gum table && \
gum confirm "Continue?" || exit 0
# First collect all image information
declare -A CONTAINER_IMAGES
echo "Collecting image information..."
for container in "${CONTAINERS[@]}"; do
FULL_IMAGE=$(docker inspect "$container" --format '{{"{{.Config.Image}}"}}')
CONTAINER_IMAGES[$container]=$(echo "$FULL_IMAGE" | sed 's/@sha256.*$//')
echo "$container -> ${CONTAINER_IMAGES[$container]}"
done
echo "Stopping containers..." && \
for container in "${CONTAINERS[@]}"; do
echo "Stopping $container..."
sudo systemctl stop "docker-$container.service"
done
echo "Pulling new images..." && \
for container in "${CONTAINERS[@]}"; do
IMAGE="${CONTAINER_IMAGES[$container]}"
echo -e "\n📥 Pulling $IMAGE for $container..." | gum style --foreground 99
if ! docker pull "$IMAGE" --quiet=false; then
echo "❌ Failed to pull $IMAGE" | gum style --foreground 196
exit 1
fi
echo "------------------------"
done
echo "Starting containers..." && \
for container in "${CONTAINERS[@]}"; do
echo "Starting $container..."
sudo systemctl start "docker-$container.service"
done && \
gum style --foreground 212 "✅ Containers updated successfully!"
@/etc/self-host-playbook/scripts/update-containers.sh

View File

@ -0,0 +1,2 @@
add-custom-service:
@/etc/self-host-playbook/scripts/add-custom-service.sh