Script for checking and starting Docker containers.
Step 1: Install the User Scripts Plugin
1. Open Unraid Web UI: Go to your Unraid server's web interface.
2. Go to Plugins: Navigate to the "Plugins" tab.
3. Install User Scripts: If you don't have it installed, find and install the User Scripts plugin from the Community Applications.
Step 2: Create Your Script
1. Open User Scripts: After installation, go to the "User Scripts" tab.
2. Add a New Script: Click on "Add Script".
3. Name Your Script: Give it a descriptive name, e.g., Check Docker Containers.
4. Edit the Script: Click on the script name to edit it, and paste your modified script into the editor:
#!/bin/bash
# List of Docker container names or IDs to check
containers=("container1" "container2" "container3")
# Check if Docker is running
if ! systemctl is-active --quiet docker; then
echo "Docker is not running. Please start Docker and try again."
exit 1
fi
# Loop through each specified container and check its status
for container in "${containers[@]}"; do
if ! docker ps -a --format '{{.Names}}' | grep -q "^$container$"; then
echo "Container $container does not exist."
continue
fi
status=$(docker inspect --format='{{.State.Status}}' "$container" 2>/dev/null)
if [ $? -ne 0 ]; then
echo "Failed to inspect container $container. It may not exist."
continue
fi
if [ "$status" != "running" ]; then
echo "Container $container is not running. Attempting to start it."
if docker start "$container"; then
echo "Container $container started successfully."
else
echo "Failed to start container $container."
fi
else
echo "Container $container is running."
fi
done
Step 3: Schedule the Script
1. Set Schedule: In the User Scripts page, set the frequency to "Every 15 minutes".
2. Save the Script: Click "Save Changes" to save the script.
Additional Tips
1. Customize Container Names: Replace container1, container2, and container3 in the script with the actual names or IDs of your Docker containers.
2. Access Logs: You can view logs from the script runs directly in the User Scripts interface.
If you have any questions or need further assistance while setting it up, feel free to ask. I'm here to help!