Pangolin Stack Management Script Guide for Update and Restore the Stack

https://asciinema.org/a/QnoybaFPNxmZsIhu1LsY7kbsT

Watch the above Video before deploying the script.

Introduction

Welcome to the guide for using the Pangolin Stack Management Script. This tool helps you manage your Pangolin deployment by providing robust backup, update, and restore capabilities. Whether you’re updating to the latest versions or need to roll back to a previous state, this script makes the process straightforward and safe.

System Requirements

Before you begin using the script, ensure your system meets these requirements:

  • Docker Engine (version 20.10.0 or higher)
  • Docker Compose V2
  • Bash shell environment
  • Standard Unix utilities (grep, sed, awk)
  • At least 1GB of free disk space for backups
  • Read/write permissions in the script’s directory

Installation

Setting up the script is straightforward:

  1. Save the script to your Pangolin project directory:
wget https://gist.githubusercontent.com/hhftechnology/96bc511034a20ae081139bd2306906bf/raw/5bddbbf349920e7df456c5b6b0bdf952d8fe0e11/update-stack.sh -O update-stack.sh
  1. Make it executable:
chmod +x update-stack.sh

Core Features

The script provides two main functions:

  1. Update Mode: Safely updates your services to new versions while creating backups
  2. Restore Mode: Returns your stack to a previous working state

Each operation includes built-in safety checks and comprehensive logging.

Updating Your Stack

To update your Pangolin stack, follow these steps:

  1. Start the update process:
./update-stack.sh update
  1. You’ll see your current versions displayed:
Current versions:
------------------------
Current Pangolin tag: 1.0.0-beta.9
Current Gerbil tag: 1.0.0-beta.3
Current Traefik tag: v3.1
  1. For each service, you can:

    • Press Enter to keep the current version
    • Type a new version number to upgrade/downgrade
  2. Review the summary of changes:

Summary of changes:
------------------------
Pangolin: 1.0.0-beta.9 -> 1.0.0-beta.10
Gerbil: 1.0.0-beta.3 -> 1.0.0-beta.3
Traefik: v3.1 -> v3.2
------------------------
  1. Confirm the changes by typing ‘y’ when prompted

During the update, the script will:

  • Create a timestamped backup
  • Safely stop all services
  • Update the specified versions
  • Restart the stack
  • Verify all services are running properly

Restoring Your Stack

You have two options for restoration:

  1. Restore to the most recent backup:
./update-stack.sh restore
  1. Restore to a specific backup:
./update-stack.sh restore ./backups/20250205_062549

The restoration process:

  1. Validates the backup’s integrity
  2. Gracefully stops current services
  3. Restores configuration files
  4. Restarts the stack with the backup’s settings
  5. Verifies service health

Understanding Backups

Each backup is stored in the ./backups directory with a timestamp format (e.g., 20250205_062549). A backup contains:

  • docker-compose.yml: The complete stack configuration
  • config/: All configuration files
  • update.log: Detailed operation logs
  • old_tags.txt: Record of service versions

Best Practices

To get the most out of the script, follow these guidelines:

Before Updates

  1. Review release notes for the new versions
  2. Test updates in a non-production environment first
  3. Ensure you have enough disk space for backups
  4. Document any custom configurations

During Operations

  1. Never interrupt the script during execution
  2. Monitor the logs for any warnings or errors
  3. Wait for the final verification step to complete

Backup Management

  1. Keep at least three recent backups
  2. Regularly test restore operations
  3. Clean up old backups periodically
  4. Store critical backups in a separate location

Troubleshooting Guide

If you encounter issues, follow these steps:

Update Failed

  1. Check the logs in ./backups/[timestamp]/update.log
  2. Verify Docker has enough resources
  3. Ensure all image versions exist in the registry
  4. Try restoring to the previous state

Restore Failed

  1. Verify the backup directory exists and is complete
  2. Check file permissions
  3. Ensure enough disk space is available
  4. Review service logs: docker compose logs

Common Error Solutions:

# If services won't start
docker compose logs

# If permission errors occur
sudo chown -R $(id -u):$(id -g) ./backups

# If cleanup is needed
docker system prune

Maintenance Tasks

Regular maintenance helps keep your system healthy:

Clean Old Backups

# Remove backups older than 30 days
find ./backups -type d -mtime +30 -exec rm -rf {} +

Remove Unused Images

# Clean up old Docker images
docker image prune -a --filter "until=168h"

Verify Backup Integrity

# List and check recent backups
ls -ltr ./backups/
./update-stack.sh restore ./backups/[timestamp] # Test restore

Logging and Monitoring

The script maintains detailed logs of all operations:

  • Update Logs: ./backups/[timestamp]/update.log
  • Restore Logs: /tmp/restore_[pid].log

Monitor these logs for:

  • Service state changes
  • Error messages
  • Version changes
  • Operation timing

Security Considerations

The script includes several security features:

  1. Validates input parameters
  2. Uses secure file permissions
  3. Implements graceful shutdowns
  4. Maintains operation logs
  5. Verifies service health

Conclusion

This script simplifies managing your Pangolin stack while maintaining system reliability and safety. Regular backups and careful version management will help ensure your deployment remains stable and secure.

For additional help or to report issues, please refer to the project’s documentation or contact support.

Remember: Always test updates in a safe environment first, and maintain good backup practices for peace of mind.

5 Likes

Can I try this or you are still working on it? I’m asking because it’s a very new post. Thanks for the detailed write up and script. @hhf.technoloy

1 Like

i am still working on it. if you want to test is its all yours

I’ll wait till you are happy with it :slight_smile:

1 Like

i have tested it multiple times. Works well for me. I have submitted to the developers to have a look.

1 Like

I can attest to testing the script to do the update and it worked flawlessly. I haven’t tested the restore as of yet, but the updating was flawless.

2 Likes

Getting this error when running this script:

./update-stack.sh: line 37: LOG_FILE: unbound variable