exec command, and remote execution improvements!
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 37s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m6s

This commit is contained in:
Your Name
2025-09-13 07:28:00 +12:00
parent 6542590942
commit 117af635a3
3 changed files with 276 additions and 2 deletions

View File

@@ -164,7 +164,16 @@ docker stop "$CONTAINER_NAME" 2>/dev/null || true
```
### status.sh
Reports the service status:
Reports the service status.
**Expected Output Format:**
- Must output a single line with one of these exact status values:
- `Running` - Service is active and operational
- `Stopped` - Service is stopped but configured
- `Error` - Service is in an error state
- `Unknown` - Status cannot be determined
The output is parsed by Dropshell for the `list` command, so it must be exactly one of these values with no additional text.
```bash
#!/bin/bash
@@ -178,6 +187,42 @@ else
fi
```
For more complex status checks:
```bash
#!/bin/bash
source "${AGENT_PATH}/common.sh"
_check_required_env_vars "CONTAINER_NAME"
# Check if container exists
if ! docker ps -a --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}$"; then
echo "Unknown"
exit 0
fi
# Check container state
STATE=$(docker inspect -f '{{.State.Status}}' "$CONTAINER_NAME" 2>/dev/null)
case "$STATE" in
running)
# Additional health check if needed
if docker inspect -f '{{.State.Health.Status}}' "$CONTAINER_NAME" 2>/dev/null | grep -q "unhealthy"; then
echo "Error"
else
echo "Running"
fi
;;
exited|stopped)
echo "Stopped"
;;
restarting|paused)
echo "Error"
;;
*)
echo "Unknown"
;;
esac
```
### logs.sh
Shows container logs:
@@ -365,6 +410,54 @@ else
fi
```
## Docker Compose Templates
When creating templates that use Docker Compose:
### Important: Always Build on Install
When using `docker compose` with custom images (defined with `build:` in your compose file), **always use the `--build` flag** in your `install.sh`:
```bash
# CORRECT - Forces rebuild of images during installation
docker compose up -d --build
# WRONG - May use stale cached images
docker compose up -d
```
This ensures that:
- Custom images are rebuilt with the latest code changes
- No stale images are used from previous installations
- The service always starts with the most recent image version
### Example Docker Compose install.sh
```bash
#!/bin/bash
source "${AGENT_PATH}/common.sh"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
_check_required_env_vars "CONTAINER_NAME"
_check_docker_installed || _die "Docker test failed"
# Stop any existing containers
docker compose down || true
# Start with rebuild to ensure fresh images
docker compose up -d --build || _die "Failed to start services"
echo "Installation of ${CONTAINER_NAME} complete"
```
### Docker Compose Best Practices
1. **Always include `--build`** in install.sh when using custom images
2. **Use `.env` files** for configuration that Docker Compose can read
3. **Define service names** consistently with `CONTAINER_NAME`
4. **Handle cleanup** properly in stop.sh and uninstall.sh using `docker compose down`
5. **Use named volumes** for persistent data that matches Dropshell conventions
## Testing Templates
After creating a template, validate it: