Commit bffdb9bf authored by Vitaly Lipatov's avatar Vitaly Lipatov

evz-docker: initial implement

parent cea3c9c9
......@@ -17,6 +17,35 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
SETLANG=ru_RU.UTF8
# list all running containers (or by arg list)
list_all()
{
if [ -n "$1" ] ; then
echo "$*"
return
fi
docker ps -q | line_filter
}
# list all containers (or by arg list)
list_ALL()
{
if [ -n "$1" ] ; then
echo "$*"
return
fi
docker ps -a -q | line_filter
}
todo()
{
warning "$@"
}
# TODO: add all support for all cases
evz_docker()
......@@ -27,32 +56,31 @@ case $CMD in
off) # HELPCMD: stop container(s) and disable start on boot
LIST=$(get_list "$@")
for i in $LIST ; do
info "Stopping $i ..."
vzctl stop $i
# TODO: check if enabled
vzctl set $i --onboot no --save
#info "Stopping $i ..."
docmd docker stop $i
docmd docker update --restart no $i
done
;;
on) # HELPCMD: enable start on boot and start container(s)
for i in "$@" ; do
info "Starting $i ..."
#info "Starting $i ..."
# TODO: check if enabled
vzctl set $i --onboot yes --save
vzctl start $i
docmd docker update --restart always $i
docmd docker start $i
done
;;
status) # HELPCMD: print container(s) status
LIST=$(get_list "$@")
info "Do $CMD for $LIST ..."
#info "Do $CMD for $LIST ..."
for i in $LIST ; do
vzctl $CMD $i
docmd docker stats --no-stream $i
done
;;
compact) # HELPCMD: do named operation on container(s)
LIST=$(get_list "$@")
for i in $LIST ; do
info "Do $CMD on $i ..."
vzctl $CMD $i
todo vzctl $CMD $i
done
;;
set) # HELPCMD: set param. Use with --option param
......@@ -61,60 +89,61 @@ case $CMD in
LIST=$(get_list "$@")
for i in $LIST ; do
info "Do $CMD on $i ..."
vzctl $CMD $i $OPTIONS --save
todo vzctl $CMD $i $OPTIONS --save
done
;;
ubc) # HELPCMD: print resource using via vzubc
LIST=$(get_list "$@")
showcmd docker stats --no-stream
for i in $LIST ; do
#info "Do $CMD on $i ..."
vzubc $i
a= docker stats --no-stream $i
done
;;
stop) # HELPCMD: stop container(s)
LIST=$(get_list "$@")
for i in "$@" ; do
info "Stopping $i ..."
vzctl stop $i
docmd docker stop $i
done
;;
start) # HELPCMD: start container(s)
LIST=$(get_list "$@")
for i in $LIST ; do
info "Starting $i ..."
vzctl start $i
docmd docker start $i
done
;;
restart) # HELPCMD: restart container(s)
LIST=$(get_list "$@")
for i in $LIST ; do
info "Restarting $i ..."
vzctl restart $i
docmd docker restart $i
done
;;
list) # HELPCMD: list avaiable container(s) (use -q|-1 for list only ID, list ALL|-a for list ever stopped containers)
# if -q, just id list
if [ -z "$verbose" ] || [ "$1" = "-1" ] || [ "$1" = "-q" ] ; then
[ -z "$verbose" ] || shift
#get_list "$@"
docker ps
get_list "$@"
exit
fi
vzlist "$@"
docmd docker ps "$@"
;;
exec) # HELPCMD: execute command by list (all for all containers)
INCMD="$1"
shift
LIST=$(get_list "$@")
for i in $LIST ; do
docker exec -ti "$i" "$INCMD"
showcmd docker exec -ti $SETLANG "$i" "$INCMD"
a= docker exec -ti $SETLANG "$i" "$INCMD"
done
;;
enter) # HELPCMD: enter in a container with ID
docker exec -ti "$1" bash
showcmd docker exec -ti $SETLANG "$1" bash
a= docker exec -ti $SETLANG "$1" bash
;;
log|logs) # HELPCMD: print container log
docker logs "$1"
docmd docker logs "$1"
;;
info) # HELPCMD: print containers(s) info (vzlist like)
LIST=$(get_list "$@")
......@@ -129,15 +158,18 @@ case $CMD in
;;
destroy) # HELPCMD: destroy container(s) by list
echo "You request to destroy follow containers:"
vzlist -a "$@"
# don't support all/ALL
#LIST=$(get_list "$@")
LIST="$@"
echo "$LIST"
#local response
read -r -p "Are you sure? [Yes/No]" response
[ "$response" = "Yes" ] || fatal "Have no receive your accept."
for i in "$@" ; do
for i in "$LIST" ; do
info "Stopping $i ..."
vzctl stop $i
vzctl destroy $i
docmd docker stop $i
docmd docker rm -f -v $i
done
;;
*)
......
......@@ -23,15 +23,6 @@ line_filter()
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' -e "s| \+| |g" -e "s|^ ||g" -e "s| $||g"
}
list_all()
{
vzlist -1 "$@" | line_filter
}
list_ALL()
{
vzlist -1 -a "$@" | line_filter
}
get_list()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment