-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure_podman_service_autostart_all.sh
executable file
·89 lines (69 loc) · 2.31 KB
/
configure_podman_service_autostart_all.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
#!/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
# Setting
setting=${1-"enable"}
# User
user=${2-""}
if [[ -z "${user}" ]]
then
user=$(whoami)
fi
# Get homedir
homedir=$(get_homedir "${user}")
# Get Systemdconfigdir
systemdconfigdir=$(get_systemdconfigdir "${user}")
# Validation
if [ "${setting}" != "enable" ] && [ "${setting}" != "disable" ]
then
echo "Setting must be one of the following: <enable> or <disable>. Aborting."
exit 9
fi
if [ "${setting}" == "enable" ]
then
# List running Containers
mapfile -t list < <( podman ps --all --format="{{.Names}}" )
for container in "${list[@]}"
do
# Echo
echo "Generate & Enable & Start Systemd Autostart Service for <${container}>"
# Enable Autostart Container Service
enable_autostart_container "${container}" "${user}"
done
else
# List running Containers
mapfile -t list < <( podman ps --all --format="{{.Names}}" )
for container in "${list[@]}"
do
# Echo
echo "Disable & Stop & Remove Systemd Autostart Service for <${container}>"
# Disable Autostart Container Service
disable_autostart_container "${container}" "${user}"
done
# List (remaing) Systemd Services
mapfile -t list < <( ls -1 ${systemdconfigdir}/container-* )
# Stop These Services which might be deprecated anyways
for servicepath in "${list[@]}"
do
# Need only the basename
service=$(basename ${servicepath})
# Extract Container Name from Service File
#container=$(get_container_from_systemd_file "${servicefile}")
#
# Disable Autostart Container Service
#echo "Disable & Stop & Remove Systemd Autostart Service <${service}>"
# Disable Service
systemd_disable "${user}" "${service}"
# Stop Service
systemd_stop "${user}" "${service}"
# Remove Service
systemd_delete "${user}" "${service}"
# Reload Systemd Daemon
systemd_reload "${user}"
done
fi