Updated pm-task.
This commit is contained in:
55
pm-task
55
pm-task
@@ -67,17 +67,21 @@ build_containers() {
|
||||
fi
|
||||
|
||||
# Check if nginx container is running before reloading
|
||||
if docker ps --format '{{.Names}}' | grep -q '^nginx$'; then
|
||||
docker exec -d nginx service nginx reload
|
||||
else
|
||||
echo "Warning: nginx container is not running, skipping reload"
|
||||
fi
|
||||
reload_nginx
|
||||
else
|
||||
echo "Error: Cannot build (neither compose.yaml, docker-compose.yml nor docker-compose.yaml is found)."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to reload nginx
|
||||
reload_nginx() {
|
||||
if docker ps --format '{{.Names}}' | grep -q '^nginx$'; then
|
||||
docker exec -d nginx service nginx reload
|
||||
else
|
||||
echo "Warning: nginx container is not running, skipping reload"
|
||||
}
|
||||
|
||||
# Function to show menu and select directory
|
||||
show_menu() {
|
||||
echo ""
|
||||
@@ -85,13 +89,13 @@ show_menu() {
|
||||
echo "Workspace: $WORKSPACE"
|
||||
echo ""
|
||||
|
||||
# Validate workspace directory exists
|
||||
# Validate workspace directory exists
|
||||
if [ ! -d "$WORKSPACE" ]; then
|
||||
echo "Error: Workspace directory '$WORKSPACE' does not exist."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get list of subdirectories (excluding dot directories)
|
||||
# Get list of subdirectories (excluding dot directories)
|
||||
mapfile -t dirs < <(find "$WORKSPACE" -mindepth 1 -maxdepth 1 -type d ! -name '.*' 2>/dev/null | sort)
|
||||
|
||||
if [ ${#dirs[@]} -eq 0 ]; then
|
||||
@@ -107,7 +111,7 @@ show_menu() {
|
||||
|
||||
read -p "Select a project (1-${#dirs[@]}): " choice
|
||||
|
||||
# If user pressed Enter without selection, show workspace contents
|
||||
# If user pressed Enter without selection, show workspace contents
|
||||
if [ -z "$choice" ]; then
|
||||
echo "Entering Docker/Podman Projects Workspace"
|
||||
cd "$WORKSPACE" || return 1
|
||||
@@ -124,7 +128,8 @@ show_menu() {
|
||||
|
||||
echo ""
|
||||
echo "=== Contents of $(basename "$selected_dir") ==="
|
||||
ls -lah "$selected_dir"
|
||||
cd "$selected_dir" || return 1
|
||||
ls -lah
|
||||
}
|
||||
|
||||
# Function to restart containers
|
||||
@@ -194,6 +199,18 @@ run_shell() {
|
||||
docker exec -it "$(basename $PWD)" bash
|
||||
}
|
||||
|
||||
# Function to upgrade containers
|
||||
upgrade_containers() {
|
||||
check_compose_file || return 1
|
||||
|
||||
echo "Pulling latest images..."
|
||||
docker compose pull
|
||||
|
||||
echo "Upgrading containers..."
|
||||
docker compose up -d --remove-orphans --force-recreate
|
||||
echo "Done!"
|
||||
}
|
||||
|
||||
# Main script
|
||||
main() {
|
||||
load_config
|
||||
@@ -206,13 +223,15 @@ main() {
|
||||
echo "Tasks:"
|
||||
echo " (none) - Show menu and list container projects"
|
||||
echo " restart - Restart container(s)"
|
||||
echo " start - Start container(s)"
|
||||
echo " stop - Stop container(s)"
|
||||
echo " start/up - Start container(s)"
|
||||
echo " stop/down - Stop container(s)"
|
||||
echo " ps - Watch running containers"
|
||||
echo " stats - Container statistics"
|
||||
echo " logs/log - Follow container logs"
|
||||
echo " sh/bash/shell - Exec into container bash shell"
|
||||
echo " build/rebuild - Build containers and reload nginx"
|
||||
echo " build/rebuild - Build containers and reload nginx"
|
||||
echo " reload - Reload nginx service"
|
||||
echo " upgrade - Pull latest images and upgrade containers"
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -220,10 +239,10 @@ main() {
|
||||
restart)
|
||||
restart_containers
|
||||
;;
|
||||
start)
|
||||
start|up)
|
||||
start_containers
|
||||
;;
|
||||
stop)
|
||||
stop|down)
|
||||
stop_containers
|
||||
;;
|
||||
ps)
|
||||
@@ -241,7 +260,13 @@ main() {
|
||||
sh|bash|shell)
|
||||
run_shell
|
||||
;;
|
||||
"")
|
||||
reload)
|
||||
reload_nginx
|
||||
;;
|
||||
upgrade)
|
||||
upgrade_containers
|
||||
;;
|
||||
"")
|
||||
show_menu
|
||||
;;
|
||||
*)
|
||||
|
||||
Reference in New Issue
Block a user