init
This commit is contained in:
commit
11f8b25dcf
61
reload-container.sh
Executable file
61
reload-container.sh
Executable file
|
@ -0,0 +1,61 @@
|
|||
#/bin/bash
|
||||
|
||||
# Reload a podman pod and recreate the systemd service.
|
||||
|
||||
# - You have to trust scripts you run with this script.
|
||||
# - The compose script has to create a pod with the same name as the folder.
|
||||
# - You need to handle starting the container afterwards yourself
|
||||
|
||||
pod_name=$1
|
||||
# do not include / at the end
|
||||
compose_dir="$HOME/compose/$pod_name"
|
||||
script_location="$compose_dir/compose.sh"
|
||||
# do not include / at the end
|
||||
systemd_folder="$HOME/.config/systemd/user"
|
||||
|
||||
if [ -z "$pod_name" ]
|
||||
then
|
||||
echo "No argument provided"
|
||||
fi
|
||||
|
||||
if [ ! -f $script_location ]
|
||||
then
|
||||
echo "The startup script for this pod does not exist ($script_location)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# list of all containers in a pod
|
||||
pods=$(podman ps -a --filter "pod=$pod_name" --format "{{.Names}}")
|
||||
|
||||
echo "---[ Stopping and removing the pod ]---"
|
||||
|
||||
podman pod stop $pod_name
|
||||
podman pod rm $pod_name
|
||||
|
||||
echo "---[ Deleting Systemd files ]---"
|
||||
|
||||
# remove global pod systemd file
|
||||
rm "$systemd_folder/pod-$pod_name"
|
||||
|
||||
# convert to array
|
||||
readarray -t containers_list <<< "$pods"
|
||||
|
||||
# iterate through containers to delete systemd files
|
||||
for container in "${containers_list[@]:1}"
|
||||
do
|
||||
echo "Removing systemd file of $container"
|
||||
rm "$systemd_folder/container-$container"
|
||||
done
|
||||
|
||||
echo "---[ Creating pod ]---"
|
||||
|
||||
pushd $compose_dir
|
||||
. $script_location
|
||||
popd
|
||||
|
||||
echo "---[ Creating systemd files ]---"
|
||||
|
||||
# create systemd service
|
||||
pushd $systemd_folder
|
||||
podman generate systemd -f -n $pod_name
|
||||
popd
|
Loading…
Reference in a new issue