RedditPP Mascot

RedditPP

r/synology • … • u/dfsaqwe

Starting \ Stopping Container Manager Project script

bash script you can use if you want to schedule a restart of a project. source: gemini ai

#!/bin/bash

# ========================================== # CONFIGURATION # ========================================== # Enter the exact name of your project from Container Manager PROJECT_NAME="vpn" # Time to wait (in seconds) between stop and start commands WAIT_TIME=15 # ==========================================

echo "=== Starting Project Restart Process ===" echo "Target Project: $PROJECT_NAME"

# 1. Fetch project list and parse the object values using jq PROJECT_ID=$(synowebapi --exec api=SYNO.Docker.Project version=1 method=list | jq -r ".data[] | select(.name==\"$PROJECT_NAME\") | .id")

# Check if an ID was successfully found if [ -z "$PROJECT_ID" ] || [ "$PROJECT_ID" == "null" ]; then echo "ERROR: Could not find a Container Manager project named '$PROJECT_NAME'." echo "Please check the spelling and try again." exit 1 fi

echo "Found Project ID: $PROJECT_ID"

# 2. Stop the project (with literal escaped quotes around the ID to prevent error 2104) echo "Stopping project..." STOP_RESULT=$(synowebapi --exec api=SYNO.Docker.Project method="stop" version=1 id="\"$PROJECT_ID\"") echo "Stop response: $STOP_RESULT"

# 3. Wait for processes to clear safely echo "Waiting $WAIT_TIME seconds for containers to spin down..." sleep $WAIT_TIME

# 4. Start the project (with literal escaped quotes around the ID to prevent error 2104) echo "Starting project..." START_RESULT=$(synowebapi --exec api=SYNO.Docker.Project method="start_stream" version=1 id="\"$PROJECT_ID\"") echo "Start response: $START_RESULT"

echo "=== Restart Process Completed ==="

— 0