Skip to content
Snippets Groups Projects
Commit 919e684d authored by Vipul's avatar Vipul
Browse files

Merge branch 'patch-fix-storage-cleanup' into 'main'

Patch fix storage cleanup

See merge request !12
parents 9dc6379a 69e192fe
No related branches found
No related tags found
1 merge request!12Patch fix storage cleanup
#!/bin/bash #!/bin/bash
echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] Starting setup..." echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] Starting setup..."
echo -e "\nStorage profile:\n$(df -h)"
echo -e "\nDocker profile:\n$(sudo docker system df)"
FORCE="$1" FORCE="$1"
...@@ -121,6 +123,7 @@ ensure_dependencies ...@@ -121,6 +123,7 @@ ensure_dependencies
# Variables # Variables
PROJECT_PATH="/home/admin/shepherd-enterprise" PROJECT_PATH="/home/admin/shepherd-enterprise"
GIT_BRANCH="main"
ENV_SHEPHERD_PATH="$PROJECT_PATH/.env.shepherd" ENV_SHEPHERD_PATH="$PROJECT_PATH/.env.shepherd"
ENV_CLIENT_PATH="$PROJECT_PATH/.env.client" ENV_CLIENT_PATH="$PROJECT_PATH/.env.client"
...@@ -135,6 +138,8 @@ CADDYFILE_PATH="$PROJECT_PATH/Caddyfile" ...@@ -135,6 +138,8 @@ CADDYFILE_PATH="$PROJECT_PATH/Caddyfile"
GRAFANADATA_PATH="$PROJECT_PATH/grafanadata" GRAFANADATA_PATH="$PROJECT_PATH/grafanadata"
LOKIDATA_PATH="$PROJECT_PATH/lokidata" LOKIDATA_PATH="$PROJECT_PATH/lokidata"
GIT_PATH="$PROJECT_PATH/.git"
SCRIPT_PATH="$PROJECT_PATH/setup-debian.sh" SCRIPT_PATH="$PROJECT_PATH/setup-debian.sh"
SCRIPT_LOG_PATH="$PROJECT_PATH/cron-logs/setup-debian-cron.log" SCRIPT_LOG_PATH="$PROJECT_PATH/cron-logs/setup-debian-cron.log"
CRON_JOB="0 0 * * * $SCRIPT_PATH >> $SCRIPT_LOG_PATH 2>&1" CRON_JOB="0 0 * * * $SCRIPT_PATH >> $SCRIPT_LOG_PATH 2>&1"
...@@ -157,6 +162,41 @@ VIMACOG_HARD_GEN_EXISTS=$(crontab -l | grep -F "$VIMACOG_HARD_GEN_PATH" | grep - ...@@ -157,6 +162,41 @@ VIMACOG_HARD_GEN_EXISTS=$(crontab -l | grep -F "$VIMACOG_HARD_GEN_PATH" | grep -
VIMACOG_HARD_GEN_LOG_DIR="$PROJECT_PATH/vimacog/hard-gen-logs/" VIMACOG_HARD_GEN_LOG_DIR="$PROJECT_PATH/vimacog/hard-gen-logs/"
VIMACOG_HARD_GEN_BACKUP_DIR="$PROJECT_PATH/vimacog/hard-gen-backup/" VIMACOG_HARD_GEN_BACKUP_DIR="$PROJECT_PATH/vimacog/hard-gen-backup/"
# Note: Cleanup temporary storgae
cleanup_git() {
echo "Initiating git cleanup..."
cd "$PROJECT_PATH" || exit
sudo du -hc $GIT_PATH
sudo git reflog expire --expire=now --expire-unreachable=now --all
sudo git prune --dry-run --verbose --expire=now
echo "Git cleanup complete."
sudo du -hc $GIT_PATH
}
# NOTE: To be removed after one run
cleanup_loki() {
echo "Initiating loki logs cleanup..."
sudo du -hc $LOKIDATA_PATH
sudo rm -rf $LOKIDATA_PATH/*
echo "Loki logs cleanup complete."
sudo du -hc $LOKIDATA_PATH
}
# NOTE: To be removed after one run
cleanup_docker() {
echo "Initiating docker cleanup..."
cd "$PROJECT_PATH" || exit
sudo docker system df
sudo docker compose down
sudo docker system prune -af --volumes
echo "Docker cleanup complete."
sudo docker system df
}
cleanup_git
cleanup_loki
cleanup_docker
# Check for Git updates & pull if updates are available # Check for Git updates & pull if updates are available
# Returns whether to hard run or soft run # Returns whether to hard run or soft run
# Note: Runs always # Note: Runs always
...@@ -164,12 +204,12 @@ setup_git() { ...@@ -164,12 +204,12 @@ setup_git() {
echo "Checking for git updates..." echo "Checking for git updates..."
cd "$PROJECT_PATH" || exit cd "$PROJECT_PATH" || exit
# git config pull.rebase true # git config pull.rebase true
sudo git fetch origin main sudo git fetch -fpPv origin $GIT_BRANCH
if [ "$(git rev-parse HEAD)" != "$(git rev-parse FETCH_HEAD)" ]; then if [ "$(git rev-parse HEAD)" != "$(git rev-parse FETCH_HEAD)" ]; then
# Ignore all local changes(comitted & non-comitted) # Ignore all local changes(comitted & non-comitted)
sudo git reset --hard origin/main sudo git reset --hard origin/$GIT_BRANCH
# TODO: Change this to main branch # TODO: Change this to $GIT_BRANCH branch
sudo git pull origin main --force sudo git pull -fpv origin $GIT_BRANCH
echo "Repository updated. Applying updates..." echo "Repository updated. Applying updates..."
# Ensure the scripts are executable after a potential update # Ensure the scripts are executable after a potential update
sudo chmod +x "$SCRIPT_PATH" sudo chmod +x "$SCRIPT_PATH"
...@@ -337,7 +377,7 @@ setup_docker() { ...@@ -337,7 +377,7 @@ setup_docker() {
if [ "$force_update" = true ]; then if [ "$force_update" = true ]; then
echo "Force updating images..." echo "Force updating images..."
sudo docker compose down sudo docker compose down
sudo docker system prune -af sudo docker system prune -af --volumes
sudo docker compose pull sudo docker compose pull
sudo docker compose --env-file ./.env up -d sudo docker compose --env-file ./.env up -d
else else
...@@ -383,5 +423,7 @@ setup_caddy $FORCE ...@@ -383,5 +423,7 @@ setup_caddy $FORCE
setup_docker $FORCE setup_docker $FORCE
setup_vimacog setup_vimacog
echo -e "\nStorage profile:\n$(df -h)"
echo -e "\nDocker profile:\n$(sudo docker system df)"
echo "Setup complete." echo "Setup complete."
exit 0 exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment