#!/bin/bash echo -n "defining container service '$1'... " image_repo=$1 shift image_name=$(echo "${image_repo}" | tr '/' ' ' | awk '{print $NF;}') image_tag="latest" data_container_name="${image_name}-data" dependencies="" volumes="" published_ports="" misc_args="" command_args=() while [ "$#" -gt 0 ]; do case "$1" in --tag) shift; tag_name="$1"; shift image_tag="${tag_name}" ;; --dependency) shift; dep_name="$1"; shift dependencies="${dependencies} ${dep_name}" ;; --volume) shift; volume_arg="$1"; shift volumes="${volumes} ${volume_arg}" ;; --publish-all-ports) shift publishing_all_ports=1 ;; --before-start) shift; before_start_script="$1"; shift ;; --cmd-arg) shift; command_args+=($1); shift ;; *) misc_arg="$1"; shift misc_args="${misc_args} ${misc_arg}" ;; esac done stopping_stanza="stopping docker" for dep_name in ${dependencies}; do stopping_stanza="${stopping_stanza} or stopping ${dep_name}" done data_container_volume_args="" for volume_mapping in ${volumes}; do data_container_volume_args="${data_container_volume_args} --volume=\"${volume_mapping}\"" done service_name="${image_name}" cat >"/etc/rsyslog.d/92-${service_name}.conf" <"/etc/init/${service_name}.conf" </dev/null || : ${before_start_script} mkdir -p /run/docker/upstart-service-containers run_id=\$(docker-utils make-ref 5) echo "${service_name}" > '/run/docker/upstart-service-containers/${service_name}' end script post-stop script container_name="\$(cat '/run/docker/upstart-service-containers/${service_name}')" docker stop "\${container_name}" || : docker rm "\${container_name}" || : rm '/run/docker/upstart-service-containers/${service_name}' end script script . /etc/environment.local container_name="\$(cat '/run/docker/upstart-service-containers/${service_name}')" echo "discovering links for container \${container_name}:" link_args="\$(docker-utils container-links-for -w ${dependencies})" echo "starting container: \${container_name} (from ${image_repo}:${image_tag})..." if [ -n "${publishing_all_ports}" ]; then published_port_args="" published_ports="\$(docker inspect --format='{{.Config.ExposedPorts}}' "${image_repo}:${image_tag}" | sed -e 's/[^0-9]/ /g')" for port in \${published_ports}; do published_port_args="\${published_port_args} --publish=\"\${port}:\${port}\"" done fi running_container_id=\$(docker run -d \ --name="\${container_name}" \ --volumes-from="${data_container_name}" \ -e "BEXNG_TARGET_SYSTEM=\${DOMAIN}" \ \${published_port_args} \ \${link_args} \ ${misc_args} \ "${image_repo}:${image_tag}" \ ${command_args[@]} \ ) exec docker attach --sig-proxy=true "\${running_container_id}" | logger -t "${service_name}" end script EOF echo "defined."