commit e5712474c904289dd969782a81a23402acdde78a
parent 44c5e7043005fdd16eafba18246d60bb5367e6a7
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Tue, 24 Jun 2014 23:39:56 +0200
WIP vserver reloading, no_unset shell option
Diffstat:
3 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/bin/confz b/bin/confz
@@ -3,7 +3,7 @@
autoload -Uz colors; colors
-setopt extended_glob warn_create_global
+setopt extended_glob warn_create_global no_unset
typeset -gA vars vars_prev
typeset -ga do_command
diff --git a/sbin/vserver-listconfigs b/sbin/vserver-listconfigs
@@ -0,0 +1,20 @@
+#!/bin/zsh
+# vim: ft=zsh noet ts=4 sts=4 sw=4
+
+setopt extended_glob warn_create_global no_unset
+
+die() {
+ print -r - "$@" >&2
+ exit 1
+}
+
+vserver_name=${1:-${${PWD#/etc/vservers/}:h}}
+
+[[ -e /etc/vservers/$vserver_name ]] || \
+ die "could not determine vserver name"
+
+vdir=/etc/vservers/$vserver_name/vdir
+vdir=$vdir:A
+
+print -rl - >/var/run/vservers/$vserver_name.files /etc/vservers/**/*(.)
+grep >/var/run/vservers/$vserver_name.mtab '^[^ ]* '$vdir'[/ ]' /etc/mtab
diff --git a/zsh-functions/confz_vserver_init b/zsh-functions/confz_vserver_init
@@ -4,6 +4,8 @@
# confz functions for deploying vservers
#
+# load the zstat builtin and keep stat external
+zmodload -F zsh/stat b:zstat
# deploy filesystem image from directory, rsync or tarball
confz_deployed_system_check() {
@@ -53,10 +55,10 @@ confz_vserver_check() {
require mounted_volume :size :filesystem \
lv_name=vs_$vars[name] \
label=$vars[name] \
- mountpoint=$vars[vdir]
+ mountpoint=$vars[vdir]
require deployed_system :source path=${vars[vdir]}
-
+
fail_reason="${(j:,:)fails}"
return $#fails
}
@@ -69,3 +71,38 @@ confz_vserver_do() {
ln -s $vars[vdir] ${vars[etcdir]}/vdir || return $?
print -r - ${vars[context_id]} >${vars[etcdir]}/context
}
+
+confz_vserver_started_check() {
+ checkvars name
+ do_command=( vserver -- $vars[name] start )
+ vserver --silent -- $vars[name] running || return $?
+ local context_id
+ context_id=$(</etc/vservers/$vars[name]/run)
+ if [[ -z $vars[context_id] ]]; then
+ vars[context_id]=$context_id
+ elif (( $vars[context_id] != $context_id )); then
+ die "vserver ${(qqq)name} running under context id $context_id, expected $vars[context_id]"
+ fi
+}
+
+confz_vserver_stopped_check() {
+ checkvars name
+ do_command=( vserver -- $vars[name] stop )
+ vserver --silent -- $vars[name] running
+ (( $? == 1 ))
+}
+
+confz_vserver_autorestart() {
+ checkvars name
+
+ require vserver_started :name %context_id
+
+ # local key val bias btime
+ # while read key val; do
+ # [[ $key == btime ]] && btime=$val
+ # done</proc/stat
+
+ # while read key val; do
+ # [[ $key == BiasUptime: ]] && bias=$val
+ # done </proc/virtual/10/cvirt
+}