File docker-container-start of Package docker-container-starter

#!/bin/bash

if [[ -z "${UID}" ]]; then
	logger -p error "Environment variable UID must be set."
	exit 255
fi
if [[ -z "${GID}" ]]; then
	logger -p error "Environment variable GID must be set."
	exit 255
fi
if [[ -z "${NAME}" ]]; then
	logger -p error "Environment variable NAME must be set."
	exit 255
fi
if [[ -z "${HOSTNAME}" ]]; then
	logger -p error "Environment variable HOSTNAME must be set."
	exit 255
fi
if [[ -z "${URL}" ]]; then
	logger -p error "Environment variable URL must be set."
	exit 255
fi
if [[ -z "${TAG}" ]]; then
	logger -p error "Environment variable TAG must be set."
	exit 255
fi
if [[ -z "${CPUS}" ]]; then
	logger -p error "Environment variable CPU must be set."
	exit 255
fi
if [[ -z "${CPU_SHARES}" ]]; then
	logger -p error "Environment variable CPU_SHARES must be set."
	exit 255
fi
if [[ -z "${MAX_MEMORY}" ]]; then
	logger -p error "Environment variable MAX_MEMORY must be set."
	exit 255
fi

if [[ -z "${CID_FILE}" ]]; then
	logger -p error "Environment variable CID_FILE must be set."
	exit 255
fi
if [[ ! -d "$(dirname "${CID_FILE}")" ]]; then
	logger -p error "Directory \"$(dirname "${CID_FILE}")\" does not exists or is not accesable."
	exit 255
fi
if [[ -f "${CID_FILE}" ]]; then
	logger -p error "Container ID file already exists, make sure the container is not running and that file removed before starting this container."
	exit 255
fi

if [[ -z "${ENVIRNMENT_FILE}" ]]; then
	logger -p error "Environment variable ENVIRNMENT_FILE must be set."
	exit 255
fi
if [[ ! -f "${ENVIRNMENT_FILE}" ]]; then
	logger -p error "Environment variable file \"${ENVIRNMENT_FILE}\" does not exists or is not accesable."
	exit 255
fi

if [[ -z "${MOUNTCONFIG_FILE}" ]]; then
	logger -p error "Environment variable MOUNTCONFIG_FILE must be set."
	exit 255
fi
if [[ ! -f "${MOUNTCONFIG_FILE}" ]]; then
	logger -p error "Environment variable file \"${MOUNTCONFIG_FILE}\" does not exists or is not accesable."
	exit 255
fi

source "${MOUNTCONFIG_FILE}"

for dir in $MOUNT_SOURCE_DIRS; do
	if [[ ! -d "${dir}" ]]; then
		logger -p error "Directory \"${dir}\" does not exists or is not accesable."
		exit 255
	fi
done

/usr/bin/docker run --detach --rm --user ${UID}:${GID} --name ${NAME} --network none --hostname ${HOSTNAME} --cidfile ${CID_FILE} --cpuset-cpus ${CPUS} --cpu-shares ${CPU_SHARES} --memory ${MAX_MEMORY} --env-file ${ENVIRNMENT_FILE} "${MOUNTS[@]}" ${URL}:${TAG}

exit $?
openSUSE Build Service is sponsored by