new: [zato] Add actions to start, stop and restart Zato

This commit is contained in:
Boris Gallet
2024-10-22 16:23:27 +02:00
parent 74c28a1bb6
commit 06c91d245f
4 changed files with 92 additions and 2 deletions

25
zato/actions/restart-zato Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
if [ -z "$SERVICE_DATASTORE" ]; then
echo "This script is meant to be run through 'compose' to work properly." >&2
exit 1
fi
. "$CHARM_PATH/lib/common"
# Combined commands to be run as zato user
local zato_commands="
/opt/zato/current/bin/zato stop /opt/zato/env/qs-1/server1/ &&
cd /opt/zato/env/qs-1 &&
./start-server-fg.sh &
"
# Execute commands as zato user
if ! exec_as_zato_in_container "$zato_commands"; then
printf "Error: Failed to execute zato commands in container '%s'.\n" "$CONTAINER_NAME" >&2
return 1
fi
printf "Zato restarted successfully in container '%s'.\n" "$CONTAINER_NAME" >&2

24
zato/actions/start-zato Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
if [ -z "$SERVICE_DATASTORE" ]; then
echo "This script is meant to be run through 'compose' to work properly." >&2
exit 1
fi
. "$CHARM_PATH/lib/common"
# Combined commands to be run as zato user
local zato_commands="
cd /opt/zato/env/qs-1 &&
./start-server-fg.sh &
"
# Execute commands as zato user
if ! exec_as_zato_in_container "$zato_commands"; then
printf "Error: Failed to execute zato commands in container '%s'.\n" "$CONTAINER_NAME" >&2
return 1
fi
printf "Zato started successfully in container '%s'.\n" "$CONTAINER_NAME" >&2

21
zato/actions/stop-zato Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
if [ -z "$SERVICE_DATASTORE" ]; then
echo "This script is meant to be run through 'compose' to work properly." >&2
exit 1
fi
. "$CHARM_PATH/lib/common"
# Combined commands to be run as zato user
local zato_commands="/opt/zato/current/bin/zato stop /opt/zato/env/qs-1/server1/"
# Execute commands as zato user
if ! exec_as_zato_in_container "$zato_commands"; then
printf "Error: Failed to execute zato commands in container '%s'.\n" "$CONTAINER_NAME" >&2
return 1
fi
printf "Zato stopped successfully in container '%s'.\n" "$CONTAINER_NAME" >&2

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash
generate_or_get_secret() {
local secret_file="$1"
@@ -16,4 +16,24 @@ generate_or_get_secret() {
fi
echo "$secret_value"
}
}
get_container_name(){
containers="$(get_running_containers_for_service "$SERVICE_NAME")"
if [ -z "$containers" ]; then
error "No running containers found for service $SERVICE_NAME"
exit 1
fi
container="$(echo "$containers" | head -n 1)"
echo "$container"
}
# Function to execute all commands sequentially as the zato user inside the Docker container
exec_as_zato_in_container() {
CONTAINER_NAME=$(get_container_name)
local cmd="$1"
if ! docker exec -it "$CONTAINER_NAME" bash -c "su - zato -c '$cmd'"; then
printf "Error: Failed to execute command '%s' as zato user in container '%s'\n" "$cmd" "$CONTAINER_NAME" >&2
return 1
fi
}