Commit cea3c9c9 authored by Vitaly Lipatov's avatar Vitaly Lipatov

evz-openvz: don't use vz commands directly

parent db21e4e9
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2017 Etersoft # Copyright (C) 2017, 2020 Etersoft
# Copyright (C) 2017 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2017, 2020 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -19,6 +19,17 @@ ...@@ -19,6 +19,17 @@
# TODO: add all support for all cases # TODO: add all support for all cases
list_all()
{
a= vzlist -1 "$@" | line_filter
}
list_ALL()
{
a= vzlist -1 -a "$@" | line_filter
}
evz_openvz() evz_openvz()
{ {
CMD=$1 CMD=$1
...@@ -28,31 +39,31 @@ case $CMD in ...@@ -28,31 +39,31 @@ case $CMD in
LIST=$(get_list "$@") LIST=$(get_list "$@")
for i in $LIST ; do for i in $LIST ; do
info "Stopping $i ..." info "Stopping $i ..."
vzctl stop $i docmd vzctl stop $i
# TODO: check if enabled # TODO: check if enabled
vzctl set $i --onboot no --save docmd vzctl set $i --onboot no --save
done done
;; ;;
on) # HELPCMD: enable start on boot and start container(s) on) # HELPCMD: enable start on boot and start container(s)
for i in "$@" ; do for i in "$@" ; do
info "Starting $i ..." info "Starting $i ..."
# TODO: check if enabled # TODO: check if enabled
vzctl set $i --onboot yes --save docmd vzctl set $i --onboot yes --save
vzctl start $i docmd vzctl start $i
done done
;; ;;
status) # HELPCMD: print container(s) status status) # HELPCMD: print container(s) status
LIST=$(get_list "$@") LIST=$(get_list "$@")
info "Do $CMD for $LIST ..." info "Do vzctl $CMD for $LIST ..."
for i in $LIST ; do for i in $LIST ; do
vzctl $CMD $i a= vzctl $CMD $i
done done
;; ;;
compact) # HELPCMD: do named operation on container(s) compact) # HELPCMD: do named operation on container(s)
LIST=$(get_list "$@") LIST=$(get_list "$@")
for i in $LIST ; do for i in $LIST ; do
info "Do $CMD on $i ..." #info "Do $CMD on $i ..."
vzctl $CMD $i docmd vzctl $CMD $i
done done
;; ;;
set) # HELPCMD: set param. Use with --option param set) # HELPCMD: set param. Use with --option param
...@@ -61,35 +72,35 @@ case $CMD in ...@@ -61,35 +72,35 @@ case $CMD in
LIST=$(get_list "$@") LIST=$(get_list "$@")
for i in $LIST ; do for i in $LIST ; do
info "Do $CMD on $i ..." info "Do $CMD on $i ..."
vzctl $CMD $i $OPTIONS --save a= vzctl $CMD $i $OPTIONS --save
done done
;; ;;
ubc) # HELPCMD: print resource using via vzubc ubc) # HELPCMD: print resource using via vzubc
LIST=$(get_list "$@") LIST=$(get_list "$@")
for i in $LIST ; do for i in $LIST ; do
#info "Do $CMD on $i ..." #info "Do $CMD on $i ..."
vzubc $i a= vzubc $i
done done
;; ;;
stop) # HELPCMD: stop container(s) stop) # HELPCMD: stop container(s)
LIST=$(get_list "$@") LIST=$(get_list "$@")
for i in "$@" ; do for i in "$@" ; do
info "Stopping $i ..." info "Stopping $i ..."
vzctl stop $i docmd vzctl stop $i
done done
;; ;;
start) # HELPCMD: start container(s) start) # HELPCMD: start container(s)
LIST=$(get_list "$@") LIST=$(get_list "$@")
for i in $LIST ; do for i in $LIST ; do
info "Starting $i ..." info "Starting $i ..."
vzctl start $i docmd vzctl start $i
done done
;; ;;
restart) # HELPCMD: restart container(s) restart) # HELPCMD: restart container(s)
LIST=$(get_list "$@") LIST=$(get_list "$@")
for i in $LIST ; do for i in $LIST ; do
info "Restarting $i ..." info "Restarting $i ..."
vzctl restart $i docmd vzctl restart $i
done done
;; ;;
list) # HELPCMD: list avaiable container(s) (use -q|-1 for list only ID, list ALL|-a for list ever stopped containers) list) # HELPCMD: list avaiable container(s) (use -q|-1 for list only ID, list ALL|-a for list ever stopped containers)
...@@ -109,10 +120,12 @@ case $CMD in ...@@ -109,10 +120,12 @@ case $CMD in
#info "Executing on $i ..." #info "Executing on $i ..."
#printf "%3d: %s" $i "$(vzctl exec $i "$INCMD")" #printf "%3d: %s" $i "$(vzctl exec $i "$INCMD")"
#vzctl exec $i "$INCMD" | sed -e "s|^|$(printf "%3d: " $i)|g" #vzctl exec $i "$INCMD" | sed -e "s|^|$(printf "%3d: " $i)|g"
vzctl exec $i "$INCMD" showcmd vzctl exec $i "$INCMD"
a= vzctl exec $i "$INCMD"
done done
;; ;;
enter) # HELPCMD: enter in a container with ID enter) # HELPCMD: enter in a container with ID
showcmd exec vzctl enter "$1"
exec vzctl enter "$1" exec vzctl enter "$1"
;; ;;
info) # HELPCMD: print containers(s) info (vzlist like) info) # HELPCMD: print containers(s) info (vzlist like)
...@@ -123,20 +136,34 @@ case $CMD in ...@@ -123,20 +136,34 @@ case $CMD in
#vzctl exec $i "$INCMD" | sed -e "s|^|$(printf "%3d: " $i)|g" #vzctl exec $i "$INCMD" | sed -e "s|^|$(printf "%3d: " $i)|g"
#vzctl exec $i "$INCMD" #vzctl exec $i "$INCMD"
# TODO: internal IP, red if internal hostname differs # TODO: internal IP, red if internal hostname differs
vzlist $LIST -o ctid,ip,hostname,diskspace showcmd vzlist $LIST -o ctid,ip,hostname,diskspace
#done #done
;; ;;
load) # HELPCMD: print load average for container(s) by list
for id in $(get_list "$@") ; do
CONF=/etc/vz/conf/$id.conf
test -r $CONF || continue
# TODO: drop long part?
eval `cat $CONF | grep ^HOSTNAME | sed -e "s|office.etersoft.ru||g"`
printf "%4s (%30s):" $id $HOSTNAME
a= vzctl exec $id uptime
done
#echo "---"
#uptime
;;
destroy) # HELPCMD: destroy container(s) by list destroy) # HELPCMD: destroy container(s) by list
echo "You request to destroy follow containers:" echo "You request to destroy follow containers:"
vzlist -a "$@" #vzlist -a "$@"
LIST=$(get_list "$@")
echo "$LIST"
#local response #local response
read -r -p "Are you sure? [Yes/No]" response read -r -p "Are you sure? [Yes/No]" response
[ "$response" = "Yes" ] || fatal "Have no receive your accept." [ "$response" = "Yes" ] || fatal "Have no receive your accept."
for i in "$@" ; do for i in "$LIST" ; do
info "Stopping $i ..." #info "Stopping $i ..."
vzctl stop $i docmd vzctl stop $i
vzctl destroy $i docmd vzctl destroy $i
done done
;; ;;
*) *)
......
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