-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure_pull_policy.sh
executable file
·116 lines (85 loc) · 3.44 KB
/
configure_pull_policy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
# Determine toolpath if not set already
relativepath="./" # Define relative path to go from this script to the root level of the tool
if [[ ! -v toolpath ]]; then scriptpath=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ); toolpath=$(realpath --canonicalize-missing ${scriptpath}/${relativepath}); fi
# Load Configuration
source ${toolpath}/config.sh
# Load Functions
source ${toolpath}/functions.sh
# User Name
user=${1}
#user=${1-"podman"}
# Base Directory
basedir=${2}
#basedir=${2-"/home/podman"}
# Set Value ("always" / "missing")
pullpolicy=${3}
#pullpolicy=${3-"missing"}
# Check if pull_policy is valid
if [[ "${pullpolicy}" != "always" ]] && [[ "${pullpolicy}" != "missing" ]]
then
echo "ERROR: pull_policy must be one of: <always>, <missing>. Entered value was <${pullpolicy}>. Aborting."
exit 9
fi
# Save current path
currentpath=$(pwd)
# Get homedir
homedir=$(get_homedir "${user}")
# Get Systemdconfigdir
systemdconfigdir=$(get_systemdconfigdir "${user}")
# Modify all Containers based on Podman Compose file Structure
for containerpath in ${basedir}/compose/*
do
# If it's a directory
if [[ -d "${containerpath}" ]]
then
# Get only container name
container=$(basename ${containerpath})
echo "Reconfigure Pull policy to <${pullpolicy}> for <${container}>"
# Change Directory
cd ${basedir}/compose/${container} || exit
if [[ -f "compose.yml" ]]
then
# Replace pull_policy string
echo "Replace pull_policy in <${basedir}/compose/${container}/compose.yml>"
#sed -Ei "s|^#(\s*)pull_policy\s*?:\s*?\".*\"(.*)$|\1pull_policy: \"${pullpolicy}\"\2|g" compose.yml # This pull_policy is anyways DISABLED so no need to replace it
sed -Ei "s|^(\s*)pull_policy\s*?=\s*?\".*\"(.*)$|\1pull_policy: \"${pullpolicy}\"\2|g" compose.yml # Fix error in previos versions (= -> :)
sed -Ei "s|^(\s*)pull_policy\s*?:\s*?\".*\"(.*)$|\1pull_policy: \"${pullpolicy}\"\2|g" compose.yml # This pull_policy is ENABLED so it MUST be replaced
else
# File does not exist
echo "File <${basedir}/compose/${container}/compose.yml>. No replacement performed."
fi
# Brind Podman Container down
#podman-compose down
fi
done
# Stop all Running Containers based only on Podman Running Status
mapfile -t list < <( podman ps --all --format="{{.Names}}" )
for container in "${list[@]}"
do
# Get compose file location from Container Properties
composedir=$(podman inspect ${container} | jq -r '.[0].Config.Labels."com.docker.compose.project.working_dir"')
# Get systemd service name
service=$(podman inspect ${container} | jq -r '.[0].Config.Labels."PODMAN_SYSTEMD_UNIT"')
echo -e "Run podman-compose down & podman-compose up -d <${container}> which is currently running"
echo -e "\t Compose Directory: ${composedir}"
echo -e "\t Systemd Service: ${service}"
# Disable Service Temporarily
systemd_disable "${user}" "${service}"
# Stop Service
systemd_stop "${user}" "${service}"
# Change Directory
cd ${composedir} || exit
# Bring Container Down
podman-compose down
# Wait a bit
sleep 0.5
# Bring Container Up
podman-compose up -d
# Re-enable Service
systemd_enable "${user}" "${service}"
# Restart Service
systemd_restart "${user}" "${service}"
done
# Re-enable all containers
#source ${toolpath}/configure_podman_service_autostart_all.sh