Updated pm-task.
This commit is contained in:
45
pm-task
45
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 ""
|
||||
@@ -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 " 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,6 +260,12 @@ main() {
|
||||
sh|bash|shell)
|
||||
run_shell
|
||||
;;
|
||||
reload)
|
||||
reload_nginx
|
||||
;;
|
||||
upgrade)
|
||||
upgrade_containers
|
||||
;;
|
||||
"")
|
||||
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`
|
||||
- `restart` : Runs `docker compose down`, `sleep 1`, and `docker compose up` commands
|
||||
- `start` : Runs `docker compose up` command
|
||||
- `stop` : Runs `docker compose down` command
|
||||
- `start` / `up` : Runs `docker compose up` command
|
||||
- `stop` / `down` : Runs `docker compose down` command
|
||||
- `ps` : Runs `watch docker ps` to monitor running containers
|
||||
- `stats` : Runs `docker stats` to monitor container resource usage
|
||||
- `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
|
||||
- `reload` : Reloads the nginx service if the container is running
|
||||
- `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
|
||||
Reference in New Issue
Block a user