|
|
b94b9d |
From 07d283a6e20b8e559257c9694f7e36e155075014 Mon Sep 17 00:00:00 2001
|
|
|
b94b9d |
From: Michele Baldessari <michele@acksyn.org>
|
|
|
b94b9d |
Date: Sun, 22 Jul 2018 17:54:29 +0200
|
|
|
b94b9d |
Subject: [PATCH] Initial podman support
|
|
|
b94b9d |
|
|
|
b94b9d |
Tested with the following container:
|
|
|
b94b9d |
podman container set: test_bundle [docker.io/sdelrio/docker-minimal-nginx]
|
|
|
b94b9d |
test_bundle-podman-0 (ocf::heartbeat:podman): Started nodea
|
|
|
b94b9d |
test_bundle-podman-1 (ocf::heartbeat:podman): Started nodeb
|
|
|
b94b9d |
test_bundle-podman-2 (ocf::heartbeat:podman): Started nodec
|
|
|
b94b9d |
|
|
|
b94b9d |
Tested a couple of stop/start cycles successfully. Needs the
|
|
|
b94b9d |
corresponding pacemaker support https://github.com/ClusterLabs/pacemaker/pull/1564
|
|
|
b94b9d |
---
|
|
|
b94b9d |
doc/man/Makefile.am | 1 +
|
|
|
b94b9d |
heartbeat/Makefile.am | 1 +
|
|
|
b94b9d |
heartbeat/podman | 488 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
b94b9d |
3 files changed, 490 insertions(+)
|
|
|
b94b9d |
create mode 100755 heartbeat/podman
|
|
|
b94b9d |
|
|
|
b94b9d |
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
|
|
|
b94b9d |
index 145e5fd50..0bef88740 100644
|
|
|
b94b9d |
--- a/doc/man/Makefile.am
|
|
|
b94b9d |
+++ b/doc/man/Makefile.am
|
|
|
b94b9d |
@@ -151,6 +151,7 @@ man_MANS = ocf_heartbeat_AoEtarget.7 \
|
|
|
b94b9d |
ocf_heartbeat_pgagent.7 \
|
|
|
b94b9d |
ocf_heartbeat_pgsql.7 \
|
|
|
b94b9d |
ocf_heartbeat_pingd.7 \
|
|
|
b94b9d |
+ ocf_heartbeat_podman.7 \
|
|
|
b94b9d |
ocf_heartbeat_portblock.7 \
|
|
|
b94b9d |
ocf_heartbeat_postfix.7 \
|
|
|
b94b9d |
ocf_heartbeat_pound.7 \
|
|
|
b94b9d |
diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am
|
|
|
b94b9d |
index e7a3a4fac..993bff042 100644
|
|
|
b94b9d |
--- a/heartbeat/Makefile.am
|
|
|
b94b9d |
+++ b/heartbeat/Makefile.am
|
|
|
b94b9d |
@@ -146,6 +146,7 @@ ocf_SCRIPTS = AoEtarget \
|
|
|
b94b9d |
pgagent \
|
|
|
b94b9d |
pgsql \
|
|
|
b94b9d |
pingd \
|
|
|
b94b9d |
+ podman \
|
|
|
b94b9d |
portblock \
|
|
|
b94b9d |
postfix \
|
|
|
b94b9d |
pound \
|
|
|
b94b9d |
diff --git a/heartbeat/podman b/heartbeat/podman
|
|
|
b94b9d |
new file mode 100755
|
|
|
b94b9d |
index 000000000..88475f1df
|
|
|
b94b9d |
--- /dev/null
|
|
|
b94b9d |
+++ b/heartbeat/podman
|
|
|
b94b9d |
@@ -0,0 +1,488 @@
|
|
|
b94b9d |
+#!/bin/sh
|
|
|
b94b9d |
+#
|
|
|
b94b9d |
+# The podman HA resource agent creates and launches a podman container
|
|
|
b94b9d |
+# based off a supplied podman image. Containers managed by this agent
|
|
|
b94b9d |
+# are both created and removed upon the agent's start and stop actions.
|
|
|
b94b9d |
+#
|
|
|
b94b9d |
+# Copyright (c) 2014 David Vossel <davidvossel@gmail.com>
|
|
|
b94b9d |
+# Michele Baldessari <michele@acksyn.org>
|
|
|
b94b9d |
+# All Rights Reserved.
|
|
|
b94b9d |
+#
|
|
|
b94b9d |
+# This program is free software; you can redistribute it and/or modify
|
|
|
b94b9d |
+# it under the terms of version 2 of the GNU General Public License as
|
|
|
b94b9d |
+# published by the Free Software Foundation.
|
|
|
b94b9d |
+#
|
|
|
b94b9d |
+# This program is distributed in the hope that it would be useful, but
|
|
|
b94b9d |
+# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
b94b9d |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
b94b9d |
+#
|
|
|
b94b9d |
+# Further, this software is distributed without any warranty that it is
|
|
|
b94b9d |
+# free of the rightful claim of any third person regarding infringement
|
|
|
b94b9d |
+# or the like. Any license provided herein, whether implied or
|
|
|
b94b9d |
+# otherwise, applies only to this software file. Patent licenses, if
|
|
|
b94b9d |
+# any, provided herein do not apply to combinations of this program with
|
|
|
b94b9d |
+# other software, or any other product whatsoever.
|
|
|
b94b9d |
+#
|
|
|
b94b9d |
+# You should have received a copy of the GNU General Public License
|
|
|
b94b9d |
+# along with this program; if not, write the Free Software Foundation,
|
|
|
b94b9d |
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
|
|
b94b9d |
+#
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+#######################################################################
|
|
|
b94b9d |
+# Initialization:
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
|
|
|
b94b9d |
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+#######################################################################
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+meta_data()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ cat <
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<resource-agent name="podman">
|
|
|
b94b9d |
+<version>1.0</version>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+The podman HA resource agent creates and launches a podman container
|
|
|
b94b9d |
+based off a supplied podman image. Containers managed by this agent
|
|
|
b94b9d |
+are both created and removed upon the agent's start and stop actions.
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">Podman container resource agent.</shortdesc>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<parameters>
|
|
|
b94b9d |
+<parameter name="image" required="1" unique="0">
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+The podman image to base this container off of.
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">podman image</shortdesc>
|
|
|
b94b9d |
+<content type="string"/>
|
|
|
b94b9d |
+</parameter>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<parameter name="name" required="0" unique="0">
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+The name to give the created container. By default this will
|
|
|
b94b9d |
+be that resource's instance name.
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">podman container name</shortdesc>
|
|
|
b94b9d |
+<content type="string"/>
|
|
|
b94b9d |
+</parameter>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<parameter name="allow_pull" unique="0">
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+Allow the image to be pulled from the configured podman registry when
|
|
|
b94b9d |
+the image does not exist locally. NOTE, this can drastically increase
|
|
|
b94b9d |
+the time required to start the container if the image repository is
|
|
|
b94b9d |
+pulled over the network.
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">Allow pulling non-local images</shortdesc>
|
|
|
b94b9d |
+<content type="boolean"/>
|
|
|
b94b9d |
+</parameter>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<parameter name="run_opts" required="0" unique="0">
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+Add options to be appended to the 'podman run' command which is used
|
|
|
b94b9d |
+when creating the container during the start action. This option allows
|
|
|
b94b9d |
+users to do things such as setting a custom entry point and injecting
|
|
|
b94b9d |
+environment variables into the newly created container. Note the '-d'
|
|
|
b94b9d |
+option is supplied regardless of this value to force containers to run
|
|
|
b94b9d |
+in the background.
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+NOTE: Do not explicitly specify the --name argument in the run_opts. This
|
|
|
b94b9d |
+agent will set --name using either the resource's instance or the name
|
|
|
b94b9d |
+provided in the 'name' argument of this agent.
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">run options</shortdesc>
|
|
|
b94b9d |
+<content type="string"/>
|
|
|
b94b9d |
+</parameter>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<parameter name="run_cmd" required="0" unique="0">
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+Specify a command to launch within the container once
|
|
|
b94b9d |
+it has initialized.
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">run command</shortdesc>
|
|
|
b94b9d |
+<content type="string"/>
|
|
|
b94b9d |
+</parameter>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<parameter name="mount_points" required="0" unique="0">
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+A comma separated list of directories that the container is expecting to use.
|
|
|
b94b9d |
+The agent will ensure they exist by running 'mkdir -p'
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">Required mount points</shortdesc>
|
|
|
b94b9d |
+<content type="string"/>
|
|
|
b94b9d |
+</parameter>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<parameter name="monitor_cmd" required="0" unique="0">
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+Specify the full path of a command to launch within the container to check
|
|
|
b94b9d |
+the health of the container. This command must return 0 to indicate that
|
|
|
b94b9d |
+the container is healthy. A non-zero return code will indicate that the
|
|
|
b94b9d |
+container has failed and should be recovered.
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+If 'podman exec' is supported, it is used to execute the command. If not,
|
|
|
b94b9d |
+nsenter is used.
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+Note: Using this method for monitoring processes inside a container
|
|
|
b94b9d |
+is not recommended, as containerd tries to track processes running
|
|
|
b94b9d |
+inside the container and does not deal well with many short-lived
|
|
|
b94b9d |
+processes being spawned. Ensure that your container monitors its
|
|
|
b94b9d |
+own processes and terminates on fatal error rather than invoking
|
|
|
b94b9d |
+a command from the outside.
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">monitor command</shortdesc>
|
|
|
b94b9d |
+<content type="string"/>
|
|
|
b94b9d |
+</parameter>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<parameter name="force_kill" required="0" unique="0">
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+Kill a container immediately rather than waiting for it to gracefully
|
|
|
b94b9d |
+shutdown
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">force kill</shortdesc>
|
|
|
b94b9d |
+<content type="boolean"/>
|
|
|
b94b9d |
+</parameter>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<parameter name="reuse" required="0" unique="0">
|
|
|
b94b9d |
+<longdesc lang="en">
|
|
|
b94b9d |
+Allow the container to be reused after stopping the container. By default
|
|
|
b94b9d |
+containers are removed after stop. With the reuse option containers
|
|
|
b94b9d |
+will persist after the container stops.
|
|
|
b94b9d |
+</longdesc>
|
|
|
b94b9d |
+<shortdesc lang="en">reuse container</shortdesc>
|
|
|
b94b9d |
+<content type="boolean"/>
|
|
|
b94b9d |
+</parameter>
|
|
|
b94b9d |
+</parameters>
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+<actions>
|
|
|
b94b9d |
+<action name="start" timeout="90s" />
|
|
|
b94b9d |
+<action name="stop" timeout="90s" />
|
|
|
b94b9d |
+<action name="monitor" timeout="30s" interval="30s" depth="0" />
|
|
|
b94b9d |
+<action name="meta-data" timeout="5s" />
|
|
|
b94b9d |
+<action name="validate-all" timeout="30s" />
|
|
|
b94b9d |
+</actions>
|
|
|
b94b9d |
+</resource-agent>
|
|
|
b94b9d |
+END
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+#######################################################################
|
|
|
b94b9d |
+REQUIRE_IMAGE_PULL=0
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+podman_usage()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ cat <
|
|
|
b94b9d |
+usage: $0 {start|stop|monitor|validate-all|meta-data}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+Expects to have a fully populated OCF RA-compliant environment set.
|
|
|
b94b9d |
+END
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+monitor_cmd_exec()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ local rc=$OCF_SUCCESS
|
|
|
b94b9d |
+ local out
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ -z "$OCF_RESKEY_monitor_cmd" ]; then
|
|
|
b94b9d |
+ return $rc
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if podman exec --help >/dev/null 2>&1; then
|
|
|
b94b9d |
+ out=$(podman exec ${CONTAINER} $OCF_RESKEY_monitor_cmd 2>&1)
|
|
|
b94b9d |
+ rc=$?
|
|
|
b94b9d |
+ else
|
|
|
b94b9d |
+ out=$(echo "$OCF_RESKEY_monitor_cmd" | nsenter --target $(podman inspect --format {{.State.Pid}} ${CONTAINER}) --mount --uts --ipc --net --pid 2>&1)
|
|
|
b94b9d |
+ rc=$?
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ $rc -eq 127 ]; then
|
|
|
b94b9d |
+ ocf_log err "monitor cmd failed (rc=$rc), output: $out"
|
|
|
b94b9d |
+ ocf_exit_reason "monitor_cmd, ${OCF_RESKEY_monitor_cmd} , not found within container."
|
|
|
b94b9d |
+ # there is no recovering from this, exit immediately
|
|
|
b94b9d |
+ exit $OCF_ERR_ARGS
|
|
|
b94b9d |
+ elif [ $rc -ne 0 ]; then
|
|
|
b94b9d |
+ ocf_exit_reason "monitor cmd failed (rc=$rc), output: $out"
|
|
|
b94b9d |
+ rc=$OCF_ERR_GENERIC
|
|
|
b94b9d |
+ else
|
|
|
b94b9d |
+ ocf_log debug "monitor cmd passed: exit code = $rc"
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ return $rc
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+container_exists()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ podman inspect --format {{.State.Running}} $CONTAINER | egrep '(true|false)' >/dev/null 2>&1
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+remove_container()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ if ocf_is_true "$OCF_RESKEY_reuse"; then
|
|
|
b94b9d |
+ # never remove the container if we have reuse enabled.
|
|
|
b94b9d |
+ return 0
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ container_exists
|
|
|
b94b9d |
+ if [ $? -ne 0 ]; then
|
|
|
b94b9d |
+ # don't attempt to remove a container that doesn't exist
|
|
|
b94b9d |
+ return 0
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+ ocf_log notice "Cleaning up inactive container, ${CONTAINER}."
|
|
|
b94b9d |
+ ocf_run podman rm $CONTAINER
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+podman_simple_status()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ local val
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ container_exists
|
|
|
b94b9d |
+ if [ $? -ne 0 ]; then
|
|
|
b94b9d |
+ return $OCF_NOT_RUNNING
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ # retrieve the 'Running' attribute for the container
|
|
|
b94b9d |
+ val=$(podman inspect --format {{.State.Running}} $CONTAINER 2>/dev/null)
|
|
|
b94b9d |
+ if [ $? -ne 0 ]; then
|
|
|
b94b9d |
+ #not running as a result of container not being found
|
|
|
b94b9d |
+ return $OCF_NOT_RUNNING
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if ocf_is_true "$val"; then
|
|
|
b94b9d |
+ # container exists and is running
|
|
|
b94b9d |
+ return $OCF_SUCCESS
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ return $OCF_NOT_RUNNING
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+podman_monitor()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ local rc=0
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ podman_simple_status
|
|
|
b94b9d |
+ rc=$?
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ $rc -ne 0 ]; then
|
|
|
b94b9d |
+ return $rc
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ monitor_cmd_exec
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+podman_create_mounts() {
|
|
|
b94b9d |
+ oldIFS="$IFS"
|
|
|
b94b9d |
+ IFS=","
|
|
|
b94b9d |
+ for directory in $OCF_RESKEY_mount_points; do
|
|
|
b94b9d |
+ mkdir -p "$directory"
|
|
|
b94b9d |
+ done
|
|
|
b94b9d |
+ IFS="$oldIFS"
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+podman_start()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ podman_create_mounts
|
|
|
b94b9d |
+ local run_opts="-d --name=${CONTAINER}"
|
|
|
b94b9d |
+ # check to see if the container has already started
|
|
|
b94b9d |
+ podman_simple_status
|
|
|
b94b9d |
+ if [ $? -eq $OCF_SUCCESS ]; then
|
|
|
b94b9d |
+ return $OCF_SUCCESS
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ -n "$OCF_RESKEY_run_opts" ]; then
|
|
|
b94b9d |
+ run_opts="$run_opts $OCF_RESKEY_run_opts"
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ $REQUIRE_IMAGE_PULL -eq 1 ]; then
|
|
|
b94b9d |
+ ocf_log notice "Beginning pull of image, ${OCF_RESKEY_image}"
|
|
|
b94b9d |
+ podman pull "${OCF_RESKEY_image}"
|
|
|
b94b9d |
+ if [ $? -ne 0 ]; then
|
|
|
b94b9d |
+ ocf_exit_reason "failed to pull image ${OCF_RESKEY_image}"
|
|
|
b94b9d |
+ return $OCF_ERR_GENERIC
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if ocf_is_true "$OCF_RESKEY_reuse" && container_exists; then
|
|
|
b94b9d |
+ ocf_log info "starting existing container $CONTAINER."
|
|
|
b94b9d |
+ ocf_run podman start $CONTAINER
|
|
|
b94b9d |
+ else
|
|
|
b94b9d |
+ # make sure any previous container matching our container name is cleaned up first.
|
|
|
b94b9d |
+ # we already know at this point it wouldn't be running
|
|
|
b94b9d |
+ remove_container
|
|
|
b94b9d |
+ ocf_log info "running container $CONTAINER for the first time"
|
|
|
b94b9d |
+ ocf_run podman run $run_opts $OCF_RESKEY_image $OCF_RESKEY_run_cmd
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ $? -ne 0 ]; then
|
|
|
b94b9d |
+ ocf_exit_reason "podman failed to launch container"
|
|
|
b94b9d |
+ return $OCF_ERR_GENERIC
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ # wait for monitor to pass before declaring that the container is started
|
|
|
b94b9d |
+ while true; do
|
|
|
b94b9d |
+ podman_simple_status
|
|
|
b94b9d |
+ if [ $? -ne $OCF_SUCCESS ]; then
|
|
|
b94b9d |
+ ocf_exit_reason "Newly created podman container exited after start"
|
|
|
b94b9d |
+ return $OCF_ERR_GENERIC
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ monitor_cmd_exec
|
|
|
b94b9d |
+ if [ $? -eq $OCF_SUCCESS ]; then
|
|
|
b94b9d |
+ ocf_log notice "Container $CONTAINER started successfully"
|
|
|
b94b9d |
+ return $OCF_SUCCESS
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ ocf_exit_reason "waiting on monitor_cmd to pass after start"
|
|
|
b94b9d |
+ sleep 1
|
|
|
b94b9d |
+ done
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+podman_stop()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ local timeout=60
|
|
|
b94b9d |
+ podman_simple_status
|
|
|
b94b9d |
+ if [ $? -eq $OCF_NOT_RUNNING ]; then
|
|
|
b94b9d |
+ remove_container
|
|
|
b94b9d |
+ return $OCF_SUCCESS
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then
|
|
|
b94b9d |
+ timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000) -10 ))
|
|
|
b94b9d |
+ if [ $timeout -lt 10 ]; then
|
|
|
b94b9d |
+ timeout=10
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if ocf_is_true "$OCF_RESKEY_force_kill"; then
|
|
|
b94b9d |
+ ocf_run podman kill $CONTAINER
|
|
|
b94b9d |
+ else
|
|
|
b94b9d |
+ ocf_log debug "waiting $timeout second[s] before killing container"
|
|
|
b94b9d |
+ ocf_run podman stop -t=$timeout $CONTAINER
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ $? -ne 0 ]; then
|
|
|
b94b9d |
+ ocf_exit_reason "Failed to stop container, ${CONTAINER}, based on image, ${OCF_RESKEY_image}."
|
|
|
b94b9d |
+ return $OCF_ERR_GENERIC
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ remove_container
|
|
|
b94b9d |
+ if [ $? -ne 0 ]; then
|
|
|
b94b9d |
+ ocf_exit_reason "Failed to remove stopped container, ${CONTAINER}, based on image, ${OCF_RESKEY_image}."
|
|
|
b94b9d |
+ return $OCF_ERR_GENERIC
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ return $OCF_SUCCESS
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+image_exists()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ # if no tag was specified, use default "latest"
|
|
|
b94b9d |
+ local COLON_FOUND=0
|
|
|
b94b9d |
+ local SLASH_FOUND=0
|
|
|
b94b9d |
+ local SERVER_NAME=""
|
|
|
b94b9d |
+ local IMAGE_NAME="${OCF_RESKEY_image}"
|
|
|
b94b9d |
+ local IMAGE_TAG="latest"
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ SLASH_FOUND="$(echo "${OCF_RESKEY_image}" | grep -o '/' | grep -c .)"
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ ${SLASH_FOUND} -ge 1 ]; then
|
|
|
b94b9d |
+ SERVER_NAME="$(echo ${IMAGE_NAME} | cut -d / -f 1-${SLASH_FOUND})"
|
|
|
b94b9d |
+ IMAGE_NAME="$(echo ${IMAGE_NAME} | awk -F'/' '{print $NF}')"
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ COLON_FOUND="$(echo "${IMAGE_NAME}" | grep -o ':' | grep -c .)"
|
|
|
b94b9d |
+ if [ ${COLON_FOUND} -ge 1 ]; then
|
|
|
b94b9d |
+ IMAGE_TAG="$(echo ${IMAGE_NAME} | awk -F':' '{print $NF}')"
|
|
|
b94b9d |
+ IMAGE_NAME="$(echo ${IMAGE_NAME} | cut -d : -f 1-${COLON_FOUND})"
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ # IMAGE_NAME might be following formats:
|
|
|
b94b9d |
+ # - image
|
|
|
b94b9d |
+ # - repository:port/image
|
|
|
b94b9d |
+ # - docker.io/image (some distro will display "docker.io/" as prefix)
|
|
|
b94b9d |
+ podman images | awk '{print $1 ":" $2}' | egrep -q -s "^(docker.io\/|${SERVER_NAME}\/)?${IMAGE_NAME}:${IMAGE_TAG}\$"
|
|
|
b94b9d |
+ if [ $? -eq 0 ]; then
|
|
|
b94b9d |
+ # image found
|
|
|
b94b9d |
+ return 0
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if ocf_is_true "$OCF_RESKEY_allow_pull"; then
|
|
|
b94b9d |
+ REQUIRE_IMAGE_PULL=1
|
|
|
b94b9d |
+ ocf_log notice "Image (${OCF_RESKEY_image}) does not exist locally but will be pulled during start"
|
|
|
b94b9d |
+ return 0
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+ # image not found.
|
|
|
b94b9d |
+ return 1
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+podman_validate()
|
|
|
b94b9d |
+{
|
|
|
b94b9d |
+ check_binary podman
|
|
|
b94b9d |
+ if [ -z "$OCF_RESKEY_image" ]; then
|
|
|
b94b9d |
+ ocf_exit_reason "'image' option is required"
|
|
|
b94b9d |
+ exit $OCF_ERR_CONFIGURED
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ if [ -n "$OCF_RESKEY_monitor_cmd" ]; then
|
|
|
b94b9d |
+ podman exec --help >/dev/null 2>&1
|
|
|
b94b9d |
+ if [ ! $? ]; then
|
|
|
b94b9d |
+ ocf_log info "checking for nsenter, which is required when 'monitor_cmd' is specified"
|
|
|
b94b9d |
+ check_binary nsenter
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ image_exists
|
|
|
b94b9d |
+ if [ $? -ne 0 ]; then
|
|
|
b94b9d |
+ ocf_exit_reason "base image, ${OCF_RESKEY_image}, could not be found."
|
|
|
b94b9d |
+ exit $OCF_ERR_CONFIGURED
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+ return $OCF_SUCCESS
|
|
|
b94b9d |
+}
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+# TODO :
|
|
|
b94b9d |
+# When a user starts plural clones in a node in globally-unique, a user cannot appoint plural name parameters.
|
|
|
b94b9d |
+# When a user appoints reuse, the resource agent cannot connect plural clones with a container.
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+if ocf_is_true "$OCF_RESKEY_CRM_meta_globally_unique"; then
|
|
|
b94b9d |
+ if [ -n "$OCF_RESKEY_name" ]; then
|
|
|
b94b9d |
+ if [ -n "$OCF_RESKEY_CRM_meta_clone_node_max" ] && [ "$OCF_RESKEY_CRM_meta_clone_node_max" -ne 1 ]
|
|
|
b94b9d |
+ then
|
|
|
b94b9d |
+ ocf_exit_reason "Cannot make plural clones from the same name parameter."
|
|
|
b94b9d |
+ exit $OCF_ERR_CONFIGURED
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+ if [ -n "$OCF_RESKEY_CRM_meta_master_node_max" ] && [ "$OCF_RESKEY_CRM_meta_master_node_max" -ne 1 ]
|
|
|
b94b9d |
+ then
|
|
|
b94b9d |
+ ocf_exit_reason "Cannot make plural master from the same name parameter."
|
|
|
b94b9d |
+ exit $OCF_ERR_CONFIGURED
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+ fi
|
|
|
b94b9d |
+ : ${OCF_RESKEY_name=`echo ${OCF_RESOURCE_INSTANCE} | tr ':' '-'`}
|
|
|
b94b9d |
+else
|
|
|
b94b9d |
+ : ${OCF_RESKEY_name=${OCF_RESOURCE_INSTANCE}}
|
|
|
b94b9d |
+fi
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+CONTAINER=$OCF_RESKEY_name
|
|
|
b94b9d |
+
|
|
|
b94b9d |
+case $__OCF_ACTION in
|
|
|
b94b9d |
+meta-data) meta_data
|
|
|
b94b9d |
+ exit $OCF_SUCCESS;;
|
|
|
b94b9d |
+start)
|
|
|
b94b9d |
+ podman_validate
|
|
|
b94b9d |
+ podman_start;;
|
|
|
b94b9d |
+stop) podman_stop;;
|
|
|
b94b9d |
+monitor) podman_monitor;;
|
|
|
b94b9d |
+validate-all) podman_validate;;
|
|
|
b94b9d |
+usage|help) podman_usage
|
|
|
b94b9d |
+ exit $OCF_SUCCESS
|
|
|
b94b9d |
+ ;;
|
|
|
b94b9d |
+*) podman_usage
|
|
|
b94b9d |
+ exit $OCF_ERR_UNIMPLEMENTED
|
|
|
b94b9d |
+ ;;
|
|
|
b94b9d |
+esac
|
|
|
b94b9d |
+rc=$?
|
|
|
b94b9d |
+ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
|
|
|
b94b9d |
+exit $rc
|