Updated pm-task.
This commit is contained in:
45
pm-task
45
pm-task
@@ -67,17 +67,21 @@ build_containers() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if nginx container is running before reloading
|
# Check if nginx container is running before reloading
|
||||||
if docker ps --format '{{.Names}}' | grep -q '^nginx$'; then
|
reload_nginx
|
||||||
docker exec -d nginx service nginx reload
|
|
||||||
else
|
|
||||||
echo "Warning: nginx container is not running, skipping reload"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "Error: Cannot build (neither compose.yaml, docker-compose.yml nor docker-compose.yaml is found)."
|
echo "Error: Cannot build (neither compose.yaml, docker-compose.yml nor docker-compose.yaml is found)."
|
||||||
return 1
|
return 1
|
||||||
fi
|
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
|
# Function to show menu and select directory
|
||||||
show_menu() {
|
show_menu() {
|
||||||
echo ""
|
echo ""
|
||||||
@@ -124,7 +128,8 @@ show_menu() {
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Contents of $(basename "$selected_dir") ==="
|
echo "=== Contents of $(basename "$selected_dir") ==="
|
||||||
ls -lah "$selected_dir"
|
cd "$selected_dir" || return 1
|
||||||
|
ls -lah
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to restart containers
|
# Function to restart containers
|
||||||
@@ -194,6 +199,18 @@ run_shell() {
|
|||||||
docker exec -it "$(basename $PWD)" bash
|
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 script
|
||||||
main() {
|
main() {
|
||||||
load_config
|
load_config
|
||||||
@@ -206,13 +223,15 @@ main() {
|
|||||||
echo "Tasks:"
|
echo "Tasks:"
|
||||||
echo " (none) - Show menu and list container projects"
|
echo " (none) - Show menu and list container projects"
|
||||||
echo " restart - Restart container(s)"
|
echo " restart - Restart container(s)"
|
||||||
echo " start - Start container(s)"
|
echo " start/up - Start container(s)"
|
||||||
echo " stop - Stop container(s)"
|
echo " stop/down - Stop container(s)"
|
||||||
echo " ps - Watch running containers"
|
echo " ps - Watch running containers"
|
||||||
echo " stats - Container statistics"
|
echo " stats - Container statistics"
|
||||||
echo " logs/log - Follow container logs"
|
echo " logs/log - Follow container logs"
|
||||||
echo " sh/bash/shell - Exec into container bash shell"
|
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
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -220,10 +239,10 @@ main() {
|
|||||||
restart)
|
restart)
|
||||||
restart_containers
|
restart_containers
|
||||||
;;
|
;;
|
||||||
start)
|
start|up)
|
||||||
start_containers
|
start_containers
|
||||||
;;
|
;;
|
||||||
stop)
|
stop|down)
|
||||||
stop_containers
|
stop_containers
|
||||||
;;
|
;;
|
||||||
ps)
|
ps)
|
||||||
@@ -241,6 +260,12 @@ main() {
|
|||||||
sh|bash|shell)
|
sh|bash|shell)
|
||||||
run_shell
|
run_shell
|
||||||
;;
|
;;
|
||||||
|
reload)
|
||||||
|
reload_nginx
|
||||||
|
;;
|
||||||
|
upgrade)
|
||||||
|
upgrade_containers
|
||||||
|
;;
|
||||||
"")
|
"")
|
||||||
show_menu
|
show_menu
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -16,11 +16,13 @@ Tasks are defined in the first argument.
|
|||||||
|
|
||||||
- `(none)` : Shows a numbered list menu of all subdirectories under the workspace directory, navigates to the selected directory, and runs `ls -lah`
|
- `(none)` : Shows a numbered list menu of all subdirectories under the workspace directory, navigates to the selected directory, and runs `ls -lah`
|
||||||
- `restart` : Runs `docker compose down`, `sleep 1`, and `docker compose up` commands
|
- `restart` : Runs `docker compose down`, `sleep 1`, and `docker compose up` commands
|
||||||
- `start` : Runs `docker compose up` command
|
- `start` / `up` : Runs `docker compose up` command
|
||||||
- `stop` : Runs `docker compose down` command
|
- `stop` / `down` : Runs `docker compose down` command
|
||||||
- `ps` : Runs `watch docker ps` to monitor running containers
|
- `ps` : Runs `watch docker ps` to monitor running containers
|
||||||
- `stats` : Runs `docker stats` to monitor container resource usage
|
- `stats` : Runs `docker stats` to monitor container resource usage
|
||||||
- `logs` / `log` : Runs `docker logs -f <container_name>` to follow container logs
|
- `logs` / `log` : Runs `docker logs -f <container_name>` to follow container logs
|
||||||
- `sh` / `bash` / `shell` : Runs `docker exec -it <container_name> bash` to access container shell
|
- `sh` / `bash` / `shell` : Runs `docker exec -it <container_name> bash` to access container shell
|
||||||
|
- `reload` : Reloads the nginx service if the container is running
|
||||||
- `build` / `rebuild` : Builds containers with `docker compose build`, optionally restarts containers, and reloads nginx
|
- `build` / `rebuild` : Builds containers with `docker compose build`, optionally restarts containers, and reloads nginx
|
||||||
|
- `upgrade` : Pulls latest images and upgrades containers with `docker compose up -d --remove-orphans --force-recreate`
|
||||||
- `--help` : Displays available tasks and usage information
|
- `--help` : Displays available tasks and usage information
|
||||||
Reference in New Issue
Block a user