[__lxc_container] s/\t/ /g; renewed todo.txt file
Replaced all tabs with 4 spaces (~/.vimrc is modified, too). The issue.txt is not required anymore and the todo.txt was updated.
This commit is contained in:
parent
9fd892a224
commit
5d6f90555b
8 changed files with 328 additions and 325 deletions
|
|
@ -17,20 +17,20 @@
|
|||
# 1: parameter name
|
||||
# 2: file to print
|
||||
write_multi_param() {
|
||||
if ! [ -f "$__object/parameter/$1" ]; then return 0; fi
|
||||
if ! [ -f "$__object/parameter/$1" ]; then return 0; fi
|
||||
|
||||
while read -r line; do
|
||||
if [ "$line" = "-" ]; then
|
||||
# append stdin
|
||||
cat "$__object/stdin"
|
||||
elif [ -f "$line" ]; then
|
||||
# append file content
|
||||
cat "$line"
|
||||
else
|
||||
# print out content
|
||||
printf "%s\n" "$line"
|
||||
fi
|
||||
done < "$__object/parameter/$1"
|
||||
while read -r line; do
|
||||
if [ "$line" = "-" ]; then
|
||||
# append stdin
|
||||
cat "$__object/stdin"
|
||||
elif [ -f "$line" ]; then
|
||||
# append file content
|
||||
cat "$line"
|
||||
else
|
||||
# print out content
|
||||
printf "%s\n" "$line"
|
||||
fi
|
||||
done < "$__object/parameter/$1"
|
||||
}
|
||||
|
||||
# Function to get rid of whitespaces inside of key-value pairs. It will clear all of these.
|
||||
|
|
@ -38,11 +38,11 @@ write_multi_param() {
|
|||
# Parameters:
|
||||
# 1: the file which should be handled
|
||||
trimm_whitespaces() {
|
||||
mv "$1" "$1"~ # backup file to read write back original file
|
||||
grep -E -v "^([[:blank:]]*)(#|$)" "$1"~ \
|
||||
| sed 's/^[[:blank:]]*//; s/[[:blank:]]*=[[:blank:]]*/ = /; s/[[:blank:]]*$//' \
|
||||
> "$1"
|
||||
rm -f "$1"~
|
||||
mv "$1" "$1"~ # backup file to read write back original file
|
||||
grep -E -v "^([[:blank:]]*)(#|$)" "$1"~ \
|
||||
| sed 's/^[[:blank:]]*//; s/[[:blank:]]*=[[:blank:]]*/ = /; s/[[:blank:]]*$//' \
|
||||
> "$1"
|
||||
rm -f "$1"~
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -53,33 +53,33 @@ state_is="$(cat "$__object/explorer/state")"
|
|||
# Only required if container will not be absent
|
||||
# prepare the wanted configuration lines
|
||||
if [ "$state_should" != "absent" ]; then
|
||||
# create the files directory
|
||||
mkdir "$__object/files/"
|
||||
# create the files directory
|
||||
mkdir "$__object/files/"
|
||||
|
||||
# Summary of the locally given configuration options
|
||||
# config-present
|
||||
conffile="$__object/files/config-present"
|
||||
write_multi_param config > "$conffile"
|
||||
trimm_whitespaces "$conffile"
|
||||
# config-absent
|
||||
absentfile="$__object/files/config-absent"
|
||||
write_multi_param config-absent > "$absentfile"
|
||||
trimm_whitespaces "$absentfile"
|
||||
# Summary of the locally given configuration options
|
||||
# config-present
|
||||
conffile="$__object/files/config-present"
|
||||
write_multi_param config > "$conffile"
|
||||
trimm_whitespaces "$conffile"
|
||||
# config-absent
|
||||
absentfile="$__object/files/config-absent"
|
||||
write_multi_param config-absent > "$absentfile"
|
||||
trimm_whitespaces "$absentfile"
|
||||
|
||||
# Diff the configuration options by removing duplicate config options
|
||||
# config.add
|
||||
grep -v -f "$__object/explorer/config" -f "$__object/files/config-absent" \
|
||||
"$__object/files/config-present" > "$__object/files/config.add" || true
|
||||
# config.del
|
||||
grep -f "$__object/explorer/config" \
|
||||
"$__object/files/config-absent" > "$__object/files/config.del" || true
|
||||
# Diff the configuration options by removing duplicate config options
|
||||
# config.add
|
||||
grep -v -f "$__object/explorer/config" -f "$__object/files/config-absent" \
|
||||
"$__object/files/config-present" > "$__object/files/config.add" || true
|
||||
# config.del
|
||||
grep -f "$__object/explorer/config" \
|
||||
"$__object/files/config-absent" > "$__object/files/config.del" || true
|
||||
|
||||
|
||||
# fallback: if template parameter exists and container currently absent; try to remove all configs
|
||||
# If the container is currently absent, nothing will be removed, even it's in the default config
|
||||
# In this case, it will try to delete every configuration option to be sure
|
||||
# only the cloning configuration is known, but not if the container will be created in an other way
|
||||
if [ "$state_is" = "absent" ] && ! [ -f "$__object/parameter/clone" ]; then
|
||||
cp "$__object/files/config-absent" "$__object/files/config.del"
|
||||
fi
|
||||
# fallback: if template parameter exists and container currently absent; try to remove all configs
|
||||
# If the container is currently absent, nothing will be removed, even it's in the default config
|
||||
# In this case, it will try to delete every configuration option to be sure
|
||||
# only the cloning configuration is known, but not if the container will be created in an other way
|
||||
if [ "$state_is" = "absent" ] && ! [ -f "$__object/parameter/clone" ]; then
|
||||
cp "$__object/files/config-absent" "$__object/files/config.del"
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
# abort if container will be absent - no config required
|
||||
if [ "$(cat "$__object/parameter/state")" = "absent" ]; then
|
||||
exit 0
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
|
|
@ -26,25 +26,25 @@ fi
|
|||
# else, just use the normal container configuration
|
||||
clone="$__object/parameter/clone"
|
||||
if [ -f "$clone" ] && [ "$("$__type_explorer/state")" = "absent" ]; then
|
||||
clone="$(cat "$clone")"
|
||||
clonepath="$__object/parameter/clonepath"
|
||||
if [ -f "$clonepath" ]; then
|
||||
clonepath="$(cat "$clonepath")"
|
||||
else
|
||||
clonepath="$lxcpath"
|
||||
fi
|
||||
clone="$(cat "$clone")"
|
||||
clonepath="$__object/parameter/clonepath"
|
||||
if [ -f "$clonepath" ]; then
|
||||
clonepath="$(cat "$clonepath")"
|
||||
else
|
||||
clonepath="$lxcpath"
|
||||
fi
|
||||
|
||||
# set the config path of the container to clone from
|
||||
config="$clonepath/$clone/config"
|
||||
# set the config path of the container to clone from
|
||||
config="$clonepath/$clone/config"
|
||||
else
|
||||
# assemble the configuration file of the container
|
||||
config="$lxcpath/$name/config"
|
||||
# assemble the configuration file of the container
|
||||
config="$lxcpath/$name/config"
|
||||
fi
|
||||
|
||||
# check if the file exist, else the container is absent
|
||||
if [ -r "$config" ]; then
|
||||
# print configuration and strip files to just values
|
||||
# grep will hide all comments and empty lines - all others must be key-values
|
||||
# sed will uniform patterns, that no spaces will be problematic (before, in the middle and at end)
|
||||
grep -E -v "^([[:blank:]]*)(#|$)" "$config" | sed 's/^[[:blank:]]*//; s/[[:blank:]]*=[[:blank:]]*/ = /; s/[[:blank:]]*$//'
|
||||
# print configuration and strip files to just values
|
||||
# grep will hide all comments and empty lines - all others must be key-values
|
||||
# sed will uniform patterns, that no spaces will be problematic (before, in the middle and at end)
|
||||
grep -E -v "^([[:blank:]]*)(#|$)" "$config" | sed 's/^[[:blank:]]*//; s/[[:blank:]]*=[[:blank:]]*/ = /; s/[[:blank:]]*$//'
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@ lxcpath="$(cat "$__object/parameter/lxcpath" 2>/dev/null || true)"
|
|||
|
||||
# lxcpath parameter
|
||||
if [ -z "$lxcpath" ]; then
|
||||
user="$(cat "$__object/parameter/user")"
|
||||
user="$(cat "$__object/parameter/user")"
|
||||
|
||||
# gather default value from config
|
||||
if [ "$user" != "$USER" ]; then
|
||||
su -s "$(which -- lxc-config)" -- "$user" lxc.lxcpath
|
||||
else
|
||||
lxc-config lxc.lxcpath
|
||||
fi
|
||||
# gather default value from config
|
||||
if [ "$user" != "$USER" ]; then
|
||||
su -s "$(which -- lxc-config)" -- "$user" lxc.lxcpath
|
||||
else
|
||||
lxc-config lxc.lxcpath
|
||||
fi
|
||||
else
|
||||
# output the parameter
|
||||
echo "$lxcpath"
|
||||
# output the parameter
|
||||
echo "$lxcpath"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -19,27 +19,27 @@ lxcpath="$(cat "$__object/parameter/lxcpath" 2>/dev/null || true)"
|
|||
# assemble optional parameters
|
||||
LXC_PARAM=""
|
||||
if [ "$lxcpath" ]; then
|
||||
# shellcheck disable=SC2089
|
||||
LXC_PARAM="$LXC_PARAM -P \"$lxcpath\""
|
||||
# shellcheck disable=SC2089
|
||||
LXC_PARAM="$LXC_PARAM -P \"$lxcpath\""
|
||||
fi
|
||||
|
||||
|
||||
# function to get information
|
||||
lxc_info() {
|
||||
# shellcheck disable=SC2090 disable=SC2086
|
||||
if [ "$user" != "$USER" ]; then
|
||||
su -s "$(which -- lxc-info)" -- "$user" $LXC_PARAM -n "$name" -H "$@"
|
||||
else
|
||||
lxc-info $LXC_PARAM -n "$name" -H "$@"
|
||||
fi
|
||||
# shellcheck disable=SC2090 disable=SC2086
|
||||
if [ "$user" != "$USER" ]; then
|
||||
su -s "$(which -- lxc-info)" -- "$user" $LXC_PARAM -n "$name" -H "$@"
|
||||
else
|
||||
lxc-info $LXC_PARAM -n "$name" -H "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# the lxc-info command will exit non-zero if container not exist
|
||||
if ! lxc_info -S >/dev/null 2>&1; then
|
||||
# not exist
|
||||
echo "absent"
|
||||
# not exist
|
||||
echo "absent"
|
||||
else
|
||||
# print state (command output matches to type states)
|
||||
lxc_info -s | tr '[:upper:]' '[:lower:]'
|
||||
# print state (command output matches to type states)
|
||||
lxc_info -s | tr '[:upper:]' '[:lower:]'
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -44,31 +44,31 @@ fi
|
|||
# shortcut for checking config changes
|
||||
# returns success (0) if there are changes
|
||||
config_changes() {
|
||||
if [ -s "$__object/files/config.add" ] || [ -s "$__object/files/config.del" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
if [ -s "$__object/files/config.add" ] || [ -s "$__object/files/config.del" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# shortcut to add bdev parameters if available
|
||||
# $1: $__object parameter name without "bdev-"
|
||||
# $2: target parameter flag (like --foo), else "--$1" will be used
|
||||
bdev_add_if_available() {
|
||||
_param_path="$__object/parameter/bdev-$1"
|
||||
if [ -f "$_param_path" ]; then
|
||||
backingstore_opts="$backingstore_opts ${2:---$1} '$(cat "$_param_path")'"
|
||||
fi
|
||||
_param_path="$__object/parameter/bdev-$1"
|
||||
if [ -f "$_param_path" ]; then
|
||||
backingstore_opts="$backingstore_opts ${2:---$1} '$(cat "$_param_path")'"
|
||||
fi
|
||||
}
|
||||
|
||||
# shortcut to add template parameters if available
|
||||
# $1: $__object parameter
|
||||
# $2: target parameter flag (like --foo), else "--$1" will be used
|
||||
template_add_if_available() {
|
||||
_param_path="$__object/parameter/$1"
|
||||
if [ -f "$_param_path" ]; then
|
||||
template_opts="$template_opts ${2:---$1} '$(cat "$_param_path")'"
|
||||
fi
|
||||
_param_path="$__object/parameter/$1"
|
||||
if [ -f "$_param_path" ]; then
|
||||
template_opts="$template_opts ${2:---$1} '$(cat "$_param_path")'"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -81,291 +81,291 @@ if [ "$state_is" = "$state_should" ] && ( ! config_changes ); then exit; fi
|
|||
|
||||
# handle if the container should exist or not
|
||||
case "$state_should" in
|
||||
# all states where the container should exist
|
||||
present|running|stopped|frozen)
|
||||
# only relevant if the container does not exist before
|
||||
if [ "$state_is" = "absent" ]; then
|
||||
# change privileges (too complex to make exceptions)
|
||||
cat <<USER
|
||||
# all states where the container should exist
|
||||
present|running|stopped|frozen)
|
||||
# only relevant if the container does not exist before
|
||||
if [ "$state_is" = "absent" ]; then
|
||||
# change privileges (too complex to make exceptions)
|
||||
cat <<USER
|
||||
su "$user" - <<SU
|
||||
USER
|
||||
|
||||
# backingstore options
|
||||
backingstore_opts=""
|
||||
if [ -f "$__object/parameter/backingstore" ]; then
|
||||
# -B works for both types, they have different long opts
|
||||
backingstore_opts="$backingstore_opts -B '$(cat "$__object/parameter/backingstore")'"
|
||||
# backingstore options
|
||||
backingstore_opts=""
|
||||
if [ -f "$__object/parameter/backingstore" ]; then
|
||||
# -B works for both types, they have different long opts
|
||||
backingstore_opts="$backingstore_opts -B '$(cat "$__object/parameter/backingstore")'"
|
||||
|
||||
# add parameters if available
|
||||
bdev_add_if_available dir
|
||||
bdev_add_if_available fstype
|
||||
bdev_add_if_available fssize
|
||||
bdev_add_if_available lvname
|
||||
bdev_add_if_available vgname
|
||||
bdev_add_if_available thinpool
|
||||
fi
|
||||
# add parameters if available
|
||||
bdev_add_if_available dir
|
||||
bdev_add_if_available fstype
|
||||
bdev_add_if_available fssize
|
||||
bdev_add_if_available lvname
|
||||
bdev_add_if_available vgname
|
||||
bdev_add_if_available thinpool
|
||||
fi
|
||||
|
||||
# check, if the container should be created or cloned
|
||||
if [ -f "$__object/parameter/clone" ]; then
|
||||
copy_from="$(cat "$__object/parameter/clone")"
|
||||
copypath="$(cat "$__object/parameter/clonepath" 2>/dev/null || true)"
|
||||
# check, if the container should be created or cloned
|
||||
if [ -f "$__object/parameter/clone" ]; then
|
||||
copy_from="$(cat "$__object/parameter/clone")"
|
||||
copypath="$(cat "$__object/parameter/clonepath" 2>/dev/null || true)"
|
||||
|
||||
# assemble own optional lxc options
|
||||
lxc_opts=""
|
||||
if [ -n "$copypath" ]; then
|
||||
# this is set as the default $lxcpath, because it is the origin
|
||||
lxc_opts="$lxc_opts -P \"$copypath\""
|
||||
fi
|
||||
if [ -n "$lxcpath" ]; then
|
||||
# this is set as the newpath, because it is the destination
|
||||
lxc_opts="$lxc_opts -p \"$lxcpath\""
|
||||
fi
|
||||
# assemble own optional lxc options
|
||||
lxc_opts=""
|
||||
if [ -n "$copypath" ]; then
|
||||
# this is set as the default $lxcpath, because it is the origin
|
||||
lxc_opts="$lxc_opts -P \"$copypath\""
|
||||
fi
|
||||
if [ -n "$lxcpath" ]; then
|
||||
# this is set as the newpath, because it is the destination
|
||||
lxc_opts="$lxc_opts -p \"$lxcpath\""
|
||||
fi
|
||||
|
||||
# print lxc-copy code (because of the lxcpath thing, $LXC_PARAM conflicts)
|
||||
cat <<LXC
|
||||
# print lxc-copy code (because of the lxcpath thing, $LXC_PARAM conflicts)
|
||||
cat <<LXC
|
||||
lxc-copy $lxc_opts $backingstore_opts -n "$copy_from" --newname "$name"
|
||||
LXC
|
||||
else
|
||||
template="$(cat "$__object/parameter/template")"
|
||||
else
|
||||
template="$(cat "$__object/parameter/template")"
|
||||
|
||||
# assemble general creation options
|
||||
create_opts=""
|
||||
if [ -f "$__object/parameter/no-default-config" ]; then
|
||||
# generate a random empty file and append
|
||||
# maybe work with an nonexistant file - but just be correct
|
||||
cat <<TMPFILE
|
||||
# assemble general creation options
|
||||
create_opts=""
|
||||
if [ -f "$__object/parameter/no-default-config" ]; then
|
||||
# generate a random empty file and append
|
||||
# maybe work with an nonexistant file - but just be correct
|
||||
cat <<TMPFILE
|
||||
empty_conf="\$(mktemp "\${TMPDIR:-/tmp}/cdist__lxc_container-empty-conf.XXXXXXXXXX")"
|
||||
TMPFILE
|
||||
create_opts="$create_opts -f \"\$empty_conf\""
|
||||
create_opts="$create_opts -f \"\$empty_conf\""
|
||||
|
||||
elif [ -f "$__object/parameter/default-config" ]; then
|
||||
# append the configuration
|
||||
create_opts="$create_opts -f \"$(cat "$__object/parameter/default-config")\""
|
||||
fi
|
||||
elif [ -f "$__object/parameter/default-config" ]; then
|
||||
# append the configuration
|
||||
create_opts="$create_opts -f \"$(cat "$__object/parameter/default-config")\""
|
||||
fi
|
||||
|
||||
# assemble template options
|
||||
template_opts=""
|
||||
# add common options (may require different options for different templates)
|
||||
template_add_if_available release -r
|
||||
template_add_if_available arch -a
|
||||
if [ -f "$__object/parameter/mirror" ]; then
|
||||
template_opts="$template_opts --mirror='$(cat "$__object/parameter/mirror")'"
|
||||
fi
|
||||
template_add_if_available ssh-key -S
|
||||
# assemble template options
|
||||
template_opts=""
|
||||
# add common options (may require different options for different templates)
|
||||
template_add_if_available release -r
|
||||
template_add_if_available arch -a
|
||||
if [ -f "$__object/parameter/mirror" ]; then
|
||||
template_opts="$template_opts --mirror='$(cat "$__object/parameter/mirror")'"
|
||||
fi
|
||||
template_add_if_available ssh-key -S
|
||||
|
||||
# at last, apply custom options
|
||||
if [ -f "$__object/parameter/template-opts" ]; then
|
||||
while read -r line; do
|
||||
template_opts="$template_opts $line"
|
||||
done < "$__object/parameter/template-opts"
|
||||
fi
|
||||
# at last, apply custom options
|
||||
if [ -f "$__object/parameter/template-opts" ]; then
|
||||
while read -r line; do
|
||||
template_opts="$template_opts $line"
|
||||
done < "$__object/parameter/template-opts"
|
||||
fi
|
||||
|
||||
# print lxc-create code
|
||||
cat <<LXC
|
||||
# print lxc-create code
|
||||
cat <<LXC
|
||||
lxc-create $LXC_PARAM $backingstore_opts -n "$name" -t "$template" $create_opts -- $template_opts
|
||||
LXC
|
||||
|
||||
# remove empty tempfile if it was created
|
||||
if [ -f "$__object/parameter/no-default-config" ]; then
|
||||
cat <<RM
|
||||
# remove empty tempfile if it was created
|
||||
if [ -f "$__object/parameter/no-default-config" ]; then
|
||||
cat <<RM
|
||||
rm -rf "\$empty_conf"
|
||||
RM
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# end of su here-document
|
||||
echo "SU"
|
||||
# end of su here-document
|
||||
echo "SU"
|
||||
|
||||
# write to the message system
|
||||
echo "create" >> "$__messages_out"
|
||||
fi
|
||||
;;
|
||||
# write to the message system
|
||||
echo "create" >> "$__messages_out"
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# list other states to get a correct error message in the wildcard case
|
||||
absent)
|
||||
;;
|
||||
# list other states to get a correct error message in the wildcard case
|
||||
absent)
|
||||
;;
|
||||
|
||||
# error handling: invalid state
|
||||
*)
|
||||
printf "Container '%s' in unknown state %s\n" "$name" "$state_should" >&2
|
||||
exit 2
|
||||
;;
|
||||
# error handling: invalid state
|
||||
*)
|
||||
printf "Container '%s' in unknown state %s\n" "$name" "$state_should" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# Check the configurations only if the container exists and there are changes
|
||||
if config_changes; then
|
||||
# generate config path
|
||||
container_config="$(cat "$__object/explorer/lxcpath")/$name/config"
|
||||
# create remote tmpfile for config
|
||||
cat <<DONE
|
||||
# generate config path
|
||||
container_config="$(cat "$__object/explorer/lxcpath")/$name/config"
|
||||
# create remote tmpfile for config
|
||||
cat <<DONE
|
||||
tmpconfig="\$(mktemp "$container_config.XXXXXXXXXX")"
|
||||
cp -p "$container_config" "\$tmpconfig"
|
||||
DONE
|
||||
|
||||
# check if smth. to be deleted
|
||||
# must be before adding, because it takes the content of the original file
|
||||
# because 'cat $file > $file' will not work (> opens before command reads it)
|
||||
# will create extended regex pattern for grep with malformed spaces
|
||||
if [ -s "$__object/files/config.del" ]; then
|
||||
cat <<DONE
|
||||
# check if smth. to be deleted
|
||||
# must be before adding, because it takes the content of the original file
|
||||
# because 'cat $file > $file' will not work (> opens before command reads it)
|
||||
# will create extended regex pattern for grep with malformed spaces
|
||||
if [ -s "$__object/files/config.del" ]; then
|
||||
cat <<DONE
|
||||
grep -v -E -f - <<'ABSENT' "$container_config" > "\$tmpconfig"
|
||||
$(awk -v FS=' = ' -v OFS=' = ' -v blank='[[:blank:]]*' '
|
||||
function ntostring(n) { ret=""; for(i=n; i<=NF; i++) ret=ret $i (i<NF ? OFS : ""); return ret }
|
||||
{ printf "^%s%s%s=%s%s%s$%s", blank, $1, blank, blank, ntostring(2), blank, ORS }
|
||||
' "$__object/files/config.del" )
|
||||
' "$__object/files/config.del" )
|
||||
ABSENT
|
||||
DONE
|
||||
fi
|
||||
fi
|
||||
|
||||
# check if smth. to be added
|
||||
if [ -s "$__object/files/config.add" ]; then
|
||||
cat <<DONE
|
||||
# check if smth. to be added
|
||||
if [ -s "$__object/files/config.add" ]; then
|
||||
cat <<DONE
|
||||
cat <<'PRESENT' >> "\$tmpconfig"
|
||||
$(cat "$__object/files/config.add")
|
||||
PRESENT
|
||||
DONE
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# apply all changes
|
||||
cat <<DONE
|
||||
# apply all changes
|
||||
cat <<DONE
|
||||
rm -rf "$container_config"
|
||||
mv "\$tmpconfig" "$container_config"
|
||||
DONE
|
||||
echo "config" >> "$__messages_out"
|
||||
echo "config" >> "$__messages_out"
|
||||
|
||||
|
||||
# restart container only if it is running
|
||||
# do not echo messages start/stop or melt/start/stop/freeze; only restart to avoid junk
|
||||
case "$state_is" in
|
||||
running|frozen)
|
||||
# only do it if the container will run again
|
||||
case "$state_should" in
|
||||
present|running|frozen)
|
||||
# su stuff
|
||||
cat <<USER
|
||||
# restart container only if it is running
|
||||
# do not echo messages start/stop or melt/start/stop/freeze; only restart to avoid junk
|
||||
case "$state_is" in
|
||||
running|frozen)
|
||||
# only do it if the container will run again
|
||||
case "$state_should" in
|
||||
present|running|frozen)
|
||||
# su stuff
|
||||
cat <<USER
|
||||
su "$user" - <<SU
|
||||
USER
|
||||
|
||||
# unfreeze if required
|
||||
if [ "$state_is" = "frozen" ]; then
|
||||
cat <<LXC
|
||||
# unfreeze if required
|
||||
if [ "$state_is" = "frozen" ]; then
|
||||
cat <<LXC
|
||||
lxc-unfreeze $LXC_PARAM -n "$name"
|
||||
LXC
|
||||
fi
|
||||
fi
|
||||
|
||||
# stop and start
|
||||
cat <<LXC
|
||||
# stop and start
|
||||
cat <<LXC
|
||||
lxc-stop $LXC_PARAM -n "$name"
|
||||
lxc-start $LXC_PARAM -n "$name"
|
||||
LXC
|
||||
|
||||
# freeze it again if it was there before, but be clever
|
||||
# if $state_is = running but should be frozen, later code will do that
|
||||
if [ "$state_is" = "frozen" ]; then
|
||||
if [ "$state_should" = "frozen" ] || [ "$state_should" = "present" ]; then
|
||||
cat <<LXC
|
||||
# freeze it again if it was there before, but be clever
|
||||
# if $state_is = running but should be frozen, later code will do that
|
||||
if [ "$state_is" = "frozen" ]; then
|
||||
if [ "$state_should" = "frozen" ] || [ "$state_should" = "present" ]; then
|
||||
cat <<LXC
|
||||
lxc-freeze $LXC_PARAM -n "$name"
|
||||
LXC
|
||||
else
|
||||
# correct current state
|
||||
state_is="running"
|
||||
echo "melt" >> "$__messages_out"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# correct current state
|
||||
state_is="running"
|
||||
echo "melt" >> "$__messages_out"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ending
|
||||
echo "restart" >> "$__messages_out"
|
||||
echo "SU"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
# ending
|
||||
echo "restart" >> "$__messages_out"
|
||||
echo "SU"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
# Check if there is a difference within the states
|
||||
if [ "$state_is" != "$state_should" ] && [ "$state_should" != "present" ]; then
|
||||
# change privileges (too complex to make exceptions)
|
||||
cat <<USER
|
||||
# change privileges (too complex to make exceptions)
|
||||
cat <<USER
|
||||
su "$user" - <<SU
|
||||
USER
|
||||
|
||||
# unfreeze if nessecary to change state
|
||||
if [ "$state_is" = "frozen" ]; then
|
||||
cat <<LXC
|
||||
# unfreeze if nessecary to change state
|
||||
if [ "$state_is" = "frozen" ]; then
|
||||
cat <<LXC
|
||||
lxc-unfreeze $LXC_PARAM -n "$name"
|
||||
LXC
|
||||
echo "melt" >> "$__messages_out"
|
||||
fi
|
||||
echo "melt" >> "$__messages_out"
|
||||
fi
|
||||
|
||||
# handle if the container should exist or not
|
||||
case "$state_should" in
|
||||
running)
|
||||
# already running if unfreezed
|
||||
if [ "$state_is" != "frozen" ]; then
|
||||
cat <<LXC
|
||||
# handle if the container should exist or not
|
||||
case "$state_should" in
|
||||
running)
|
||||
# already running if unfreezed
|
||||
if [ "$state_is" != "frozen" ]; then
|
||||
cat <<LXC
|
||||
lxc-start $LXC_PARAM -n "$name"
|
||||
LXC
|
||||
echo "start" >> "$__messages_out"
|
||||
fi
|
||||
;;
|
||||
echo "start" >> "$__messages_out"
|
||||
fi
|
||||
;;
|
||||
|
||||
# stop the container if it should be removed
|
||||
stopped)
|
||||
cat <<LXC
|
||||
# stop the container if it should be removed
|
||||
stopped)
|
||||
cat <<LXC
|
||||
lxc-stop $LXC_PARAM -n "$name"
|
||||
LXC
|
||||
echo "stop" >> "$__messages_out"
|
||||
;;
|
||||
echo "stop" >> "$__messages_out"
|
||||
;;
|
||||
|
||||
# container should be stopped if not already done
|
||||
absent)
|
||||
if [ "$state_is" != "stopped" ]; then
|
||||
cat <<LXC
|
||||
# container should be stopped if not already done
|
||||
absent)
|
||||
if [ "$state_is" != "stopped" ]; then
|
||||
cat <<LXC
|
||||
lxc-stop $LXC_PARAM -n "$name"
|
||||
LXC
|
||||
fi
|
||||
;;
|
||||
fi
|
||||
;;
|
||||
|
||||
frozen)
|
||||
# stopped containers can't be frozen; they must be started first
|
||||
if [ "$state_is" = "stopped" ] || [ "$state_is" = "absent" ]; then
|
||||
cat <<LXC
|
||||
frozen)
|
||||
# stopped containers can't be frozen; they must be started first
|
||||
if [ "$state_is" = "stopped" ] || [ "$state_is" = "absent" ]; then
|
||||
cat <<LXC
|
||||
lxc-start $LXC_PARAM -n "$name"
|
||||
LXC
|
||||
echo "start" >> "$__messages_out"
|
||||
fi
|
||||
cat <<LXC
|
||||
echo "start" >> "$__messages_out"
|
||||
fi
|
||||
cat <<LXC
|
||||
lxc-freeze $LXC_PARAM -n "$name"
|
||||
LXC
|
||||
echo "freeze" >> "$__messages_out"
|
||||
;;
|
||||
echo "freeze" >> "$__messages_out"
|
||||
;;
|
||||
|
||||
*)
|
||||
# must be checked by previous case
|
||||
;;
|
||||
esac
|
||||
*)
|
||||
# must be checked by previous case
|
||||
;;
|
||||
esac
|
||||
|
||||
# end of su here-document
|
||||
echo "SU"
|
||||
# end of su here-document
|
||||
echo "SU"
|
||||
fi
|
||||
|
||||
|
||||
# Check if the container needs to be removed
|
||||
if [ "$state_should" = "absent" ]; then
|
||||
# change privileges (too complex to make exceptions)
|
||||
# then, shutdown and delete the container
|
||||
# we could force-delete, but better be polite
|
||||
# snapshots are deleted, too - to keep everything clean. May someone does not want it?
|
||||
cat <<USER
|
||||
# change privileges (too complex to make exceptions)
|
||||
# then, shutdown and delete the container
|
||||
# we could force-delete, but better be polite
|
||||
# snapshots are deleted, too - to keep everything clean. May someone does not want it?
|
||||
cat <<USER
|
||||
su "$user" - <<SU
|
||||
lxc-destroy $LXC_PARAM --snapshots -n "$name"
|
||||
SU
|
||||
USER
|
||||
|
||||
# write to the message system
|
||||
echo "destroy" >> "$__messages_out"
|
||||
# write to the message system
|
||||
echo "destroy" >> "$__messages_out"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
$__object_id == name ? sperate parameter required?? multiple same names possible due to --lxcpath!
|
||||
|
|
@ -17,62 +17,62 @@ param="$__object/parameter/"
|
|||
|
||||
# valid check if only --template or --clone given
|
||||
if [ -f "$param/template" ] && [ -f "$param/clone" ]; then
|
||||
# error and exit
|
||||
>&2 echo "error: can not create and clone a container at once!"
|
||||
>&2 echo "error: --template and --clone can not work together"
|
||||
exit 2
|
||||
# error and exit
|
||||
>&2 echo "error: can not create and clone a container at once!"
|
||||
>&2 echo "error: --template and --clone can not work together"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# no clone option if --template given
|
||||
if [ -f "$param/template" ]; then
|
||||
if [ -f "$param/clonepath" ]
|
||||
then
|
||||
>&2 echo "error: container will created by template, no clone options required!"
|
||||
exit 2
|
||||
fi
|
||||
if [ -f "$param/clonepath" ]
|
||||
then
|
||||
>&2 echo "error: container will created by template, no clone options required!"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
# no template options if --clone given
|
||||
if [ -f "$param/clone" ]; then
|
||||
if [ -f "$param/template-opts" ] \
|
||||
|| [ -f "$param/default-config" ] \
|
||||
|| [ -f "$param/no-default-config" ] \
|
||||
|| [ -f "$param/release" ] \
|
||||
|| [ -f "$param/arch" ]
|
||||
then
|
||||
>&2 echo "error: container will created by clone, no template options required!"
|
||||
exit 2
|
||||
fi
|
||||
if [ -f "$param/template-opts" ] \
|
||||
|| [ -f "$param/default-config" ] \
|
||||
|| [ -f "$param/no-default-config" ] \
|
||||
|| [ -f "$param/release" ] \
|
||||
|| [ -f "$param/arch" ]
|
||||
then
|
||||
>&2 echo "error: container will created by clone, no template options required!"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
# check backingstore values
|
||||
if [ -f "$param/backingstore" ]; then
|
||||
backingstore="$(cat "$param/backingstore")"
|
||||
backingstore="$(cat "$param/backingstore")"
|
||||
|
||||
if [ "$backingstore" != "dir" ] && [ "$backingstore" != "none" ]; then
|
||||
if [ -f "$param/bdev-dir" ]
|
||||
then
|
||||
>&2 echo "error: --bdev-dir is only possible for backingstore 'dir' or 'none'"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
if [ "$backingstore" != "dir" ] && [ "$backingstore" != "none" ]; then
|
||||
if [ -f "$param/bdev-dir" ]
|
||||
then
|
||||
>&2 echo "error: --bdev-dir is only possible for backingstore 'dir' or 'none'"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$backingstore" != "lvm" ] && [ "$backingstore" != "loop" ]; then
|
||||
if [ -f "$param/bdev-fstype" ] \
|
||||
|| [ -f "$param/bdev-fssize" ]
|
||||
then
|
||||
>&2 echo "error: --bdev-fstype and --bdev-fssize only available for backingstore 'lvm' or 'loop'"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
if [ "$backingstore" != "lvm" ] && [ "$backingstore" != "loop" ]; then
|
||||
if [ -f "$param/bdev-fstype" ] \
|
||||
|| [ -f "$param/bdev-fssize" ]
|
||||
then
|
||||
>&2 echo "error: --bdev-fstype and --bdev-fssize only available for backingstore 'lvm' or 'loop'"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$backingstore" != "lvm" ]; then
|
||||
if [ -f "$param/bdev-lvname" ] \
|
||||
|| [ -f "$param/bdev-vgname" ] \
|
||||
|| [ -f "$param/bdev-thinpool" ]
|
||||
then
|
||||
>&2 echo "error: --bdev-{lv,vg}name and --bdev-thinpool only available for backingstore 'lvm'"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
if [ "$backingstore" != "lvm" ]; then
|
||||
if [ -f "$param/bdev-lvname" ] \
|
||||
|| [ -f "$param/bdev-vgname" ] \
|
||||
|| [ -f "$param/bdev-thinpool" ]
|
||||
then
|
||||
>&2 echo "error: --bdev-{lv,vg}name and --bdev-thinpool only available for backingstore 'lvm'"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ auto.. (lxc autostart):
|
|||
- group
|
||||
- start
|
||||
|
||||
If config already created, it's considered the container is already created
|
||||
-> first create; then setup
|
||||
detection if template changed??
|
||||
config:
|
||||
- remove whole sections
|
||||
- keep prettier config files?
|
||||
|
||||
|
||||
if multi-valued object ids come to be a thing, following pattern is also used internal at lxc:
|
||||
$lxcpath:$name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue