summaryrefslogtreecommitdiff
path: root/clientobsserver/dobsserver.sh
diff options
context:
space:
mode:
Diffstat (limited to 'clientobsserver/dobsserver.sh')
-rwxr-xr-xclientobsserver/dobsserver.sh366
1 files changed, 366 insertions, 0 deletions
diff --git a/clientobsserver/dobsserver.sh b/clientobsserver/dobsserver.sh
new file mode 100755
index 0000000..0149974
--- /dev/null
+++ b/clientobsserver/dobsserver.sh
@@ -0,0 +1,366 @@
+#! /bin/sh
+#===============================================================================
+# Tizen OBS Server shell script
+# 12/15/2014 0.1
+#
+# Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
+# Author onstudy@samsung.com
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#===============================================================================
+
+home="$( cd "$( dirname "$0" )" && pwd )"
+. $home/config.conf
+
+set -e
+#-------------------------------------------------------------------------------
+images=$IMAGES:$TAG
+container=$CONTAINER
+
+echo "IMAGES:"$images
+echo "CONTAINER:"$container
+
+if [ ! -z "$PORTS" ]
+then
+ for I in $PORTS; do
+ service_port=$I
+ if [ ! -z $(echo "$service_port" | grep ':') ]
+ then
+ if [ -z "$ports_cmd" ]
+ then
+ ports_cmd=$(echo "-p ${service_port} ")
+ else
+ ports_cmd=$(echo $ports_cmd"-p ${service_port} ")
+ fi
+ else
+ if [ -z "$ports_cmd" ]
+ then
+ ports_cmd=$(echo "-p ${service_port}:${service_port} ")
+ else
+ ports_cmd=$(echo $ports_cmd"-p ${service_port}:${service_port} ")
+ fi
+ fi
+ done
+fi
+echo "PORT:"$ports_cmd
+
+if [ ! -z "$ENVLIST" ]
+then
+ envlist_cmd=$(echo "--env-file $ENVLIST")
+fi
+echo "ENV LIST:"$envlist_cmd
+
+if [ ! -z "$VOLUMES" ]
+then
+ for vol in $VOLUMES; do
+ if [ -z "$volumes_cmd" ]
+ then
+ volumes_cmd=$(echo "-v /etc/localtime:/etc/localtime:ro -v $vol ")
+ else
+ volumes_cmd=$(echo $volumes_cmd "-v $vol ")
+ fi
+ done
+fi
+echo "VOLUMES:"$volumes_cmd
+if [ ! -z "$HOSTNAME" ]
+then
+ hostname_cmd=$(echo "-h $HOSTNAME")
+fi
+echo "HOST NAME:"$hostname_cmd
+
+if [ "$PRIVILEGED" = 'yes' ]
+then
+ privileged_cmd=$(echo "--privileged")
+fi
+echo "PRIVILEGED:"$privileged_cmd
+
+if [ "$AUTOSTART" = 'always' ]
+then
+ autostart_cmd=$(echo "--restart=always")
+elif [ "$AUTOSTART" = 'on-failure^' ]
+then
+ autostart_cmd=$(echo "--restart=on-failure:10")
+fi
+echo "AUTOSTART:"$autostart_cmd
+
+if [ ! -z "$LINK_IMAGES" ]
+then
+ for link in $LINK_IMAGES; do
+ if [ -z "$links_cmd" ]
+ then
+ links_cmd=$(echo "--link $link ")
+ else
+ links_cmd=$(echo $links_cmd "--link $link ")
+ fi
+ done
+fi
+echo "LINKS:"$links_cmd
+
+if [ ! -z "$VOLUMES_IMAGES" ]
+then
+ for volumes_images in $VOLUMES_IMAGES; do
+ if [ -z "$volumes_images_cmd" ]
+ then
+ volumes_images_cmd=$(echo "--volumes-from $volumes_images ")
+ else
+ volumes_images_cmd=$(echo $volumes_images_cmd "--volumes-from $volumes_images ")
+ fi
+ done
+fi
+echo "VOLUMES-FROM:"$volumes_images_cmd
+
+if [ ! -z "$ADD_HOSTS" ]
+then
+ for hostserver in $ADD_HOSTS; do
+ if [ -z "$add_hosts_cmd" ]
+ then
+ add_hosts_cmd=$(echo "--add-host=$hostserver ")
+ else
+ add_hosts_cmd=$(echo $add_hosts_cmd "--add-host=$hostserver ")
+ fi
+ done
+fi
+echo "ADD_HOST:"$add_hosts_cmd
+
+if [ ! -z "$CAP_ADD" ]
+then
+ for capadd in $CAP_ADD; do
+ if [ -z "$capadds_cmd" ]
+ then
+ capadds_cmd=$(echo "--cap-add=$capadd ")
+ else
+ capadds_cmd=$(echo $capadds_cmd "--cap-add=$capadd ")
+ fi
+ done
+fi
+echo "CAP_ADD:"$capadds_cmd
+
+if [ ! -z "$SECURITY_ADD" ];
+then
+ for securityadd in $SECURITY_ADD; do
+ if [ -z "$securitys_cmd" ];
+ then
+ securitys_cmd=$(echo "--security-opt=$securityadd ")
+ else
+ securitys_cmd=$(echo $securitys_cmd "--security-opt=$securityadd ")
+ fi
+ done
+fi
+echo "SECURITY_ADD:"$securitys_cmd
+
+#-------------------------------------------------------------------------------
+attach(){
+ echo "Attaching docker containers:"
+ docker exec -it $container script /dev/null -c /bin/bash || true
+}
+#-------------------------------------------------------------------------------
+status(){
+ echo "Status docker containers:"
+ docker ps | grep "$container" || true
+}
+#-------------------------------------------------------------------------------
+stop(){
+ echo "Stopping docker containers:"
+ docker stop $container || true
+ docker ps | grep "$container" || true
+}
+#-------------------------------------------------------------------------------
+start(){
+ echo "Starting ${container}:"
+ echo " docker run -d --name $container \
+ $hostname_cmd \
+ $privileged_cmd \
+ $links_cmd \
+ $ports_cmd \
+ $envlist_cmd \
+ $volumes_cmd \
+ $volumes_images_cmd \
+ $add_hosts_cmd \
+ $capadds_cmd \
+ $securitys_cmd \
+ $images
+ "
+ if [ ! -z "$links_cmd" ]
+ then
+ for link in $LINK_IMAGES; do
+ link_sh=$(echo "$link" | cut -d ':' -f1)
+ if [ -z "$(docker ps | grep "$link_sh" | awk '{print $NF}')" ]
+ then
+ echo "Please you must be run the" "$link_sh"" before the" "$container"
+ exit
+ fi
+ done
+ fi
+ for run_container in $(docker ps -a | grep "$container" | awk '{print $NF}'); do
+ if [ "$run_container" = "$container" ];
+ then
+ docker start $container
+ docker ps | grep "$container" || true
+ exit
+ fi
+ done
+ docker run -d --name $container \
+ $hostname_cmd \
+ $privileged_cmd \
+ $links_cmd \
+ $ports_cmd \
+ $envlist_cmd \
+ $volumes_cmd \
+ $volumes_images_cmd \
+ $add_hosts_cmd \
+ $capadds_cmd \
+ $securitys_cmd \
+ $images
+
+ docker ps | grep "$container" || true
+}
+
+#-------------------------------------------------------------------------------
+kill(){
+ echo "Killing docker containers:"
+ docker kill $container || true
+}
+#-------------------------------------------------------------------------------
+rm(){
+ echo "Removing stopped containers:"
+ docker rm $container || true
+}
+#-------------------------------------------------------------------------------
+logs(){
+ echo "Show logs of a container"
+ docker logs $container || true
+}
+#-------------------------------------------------------------------------------
+cp(){
+ echo "Copy files/folders from a container's filesystem"
+ echo "docker cp $container:$1 $2 || true"
+ docker cp $container:$1 $2 || true
+}
+#-------------------------------------------------------------------------------
+pull(){
+ echo "Pull an image or a repository from a Docker registry server"
+ docker pull $images || true
+}
+#-------------------------------------------------------------------------------
+inspect(){
+ echo "Return low-level information on a containe"
+ docker inspect $container || true
+}
+#-------------------------------------------------------------------------------
+top(){
+ echo "Lookup the running processes of a container"
+ docker top $container || true
+}
+#-------------------------------------------------------------------------------
+save(){
+ echo "Save an image to a tar archive"
+ docker save -o $container"-"$TAG"-docker-image.tar.gz" $images || true
+ echo $(pwd | awk -F '/' '{print $NF}')
+ tar cvfzp ../$container"-"$TAG"-docker-script.tar.gz" ../$(pwd | awk -F '/' '{print $NF}')
+ echo "Save $container-$TAG"
+}
+#-------------------------------------------------------------------------------
+load(){
+ echo "Load an image from a tar archive"
+ docker load -i $container"-"$TAG"-docker-image.tar.gz" || true
+ echo "Load $container-$TAG"
+}
+#-------------------------------------------------------------------------------
+help(){
+ echo "help"
+ usage
+}
+#-------------------------------------------------------------------------------
+usage (){
+ echo "USAGE: $0" COMMAND
+
+ echo -e "\nCommands:"
+ echo " start Start a stopped container"
+ echo " attach Attach to a running container"
+ echo " stop Stop a running container"
+ echo " status Status a running container"
+ echo " rm Remove this containers"
+ echo " restart stop , start a container"
+ echo " kill Kill a running container"
+ echo " logs Fetch the logs of a container"
+ echo " cp Copy files/folders from a container's filesystem to the host path"
+ echo " pull Pull an image or a repository from a Docker registry server"
+ echo " inspect Return low-level information on a containe"
+ echo " top Lookup the running processes of a container"
+ echo " save Save an image to a tar archive"
+ echo " load Load an image from a tar archive"
+ echo " help help"
+ exit 1
+}
+#-------------------------------------------------------------------------------
+if [ $# -eq 0 ]
+then
+ usage
+fi
+
+#-------------------------------------------------------------------------------
+case "$1" in
+ start)
+ start
+ ;;
+ attach)
+ attach
+ ;;
+ status)
+ status
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ stop
+ start
+ ;;
+
+ kill)
+ kill
+ rm
+ ;;
+ rm)
+ rm
+ ;;
+ logs)
+ logs
+ ;;
+ cp)
+ cp $2 $3
+ ;;
+ pull)
+ pull
+ ;;
+ push)
+ push
+ ;;
+ inspect)
+ inspect
+ ;;
+ top)
+ top
+ ;;
+ save)
+ save
+ ;;
+ load)
+ load
+ ;;
+ help)
+ help
+ ;;
+ *)
+ usage
+ ;;
+esac
+#===============================================================================
+