added config-warewulf
This commit is contained in:
@@ -66,6 +66,8 @@ RUN zypper -n install \
|
|||||||
cp -vr container-scripts/label-* \
|
cp -vr container-scripts/label-* \
|
||||||
container-scripts/wwctl \
|
container-scripts/wwctl \
|
||||||
container-scripts/warewulf.service \
|
container-scripts/warewulf.service \
|
||||||
|
container-scripts/warewulf-container-manage.sh \
|
||||||
|
container-scripts/config-warewul \
|
||||||
/container &&\
|
/container &&\
|
||||||
mkdir -p /usr/share/bash_completion/completions/ &&\
|
mkdir -p /usr/share/bash_completion/completions/ &&\
|
||||||
cp /etc/warewulf/bash_completion.d/warewulf /usr/share/bash_completion/completions/wwctl &&\
|
cp /etc/warewulf/bash_completion.d/warewulf /usr/share/bash_completion/completions/wwctl &&\
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -254,7 +254,7 @@ warewulfconf: config_defaults
|
|||||||
./config_defaults
|
./config_defaults
|
||||||
|
|
||||||
dist: vendor config
|
dist: vendor config
|
||||||
rm -rf .dist/$(WAREWULF)-$(VERSION)
|
rm -rf .dist/$(WAREWULF)-$(VERSION) $(WAREWULF)-$(VERSION).tar.gz
|
||||||
mkdir -p .dist/$(WAREWULF)-$(VERSION)
|
mkdir -p .dist/$(WAREWULF)-$(VERSION)
|
||||||
cp -rap * .dist/$(WAREWULF)-$(VERSION)/
|
cp -rap * .dist/$(WAREWULF)-$(VERSION)/
|
||||||
find .dist/$(WAREWULF)-$(VERSION)/ -type f -name '*~' -delete
|
find .dist/$(WAREWULF)-$(VERSION)/ -type f -name '*~' -delete
|
||||||
|
|||||||
73
container-scripts/config-warewulf
Executable file
73
container-scripts/config-warewulf
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Helper functions
|
||||||
|
# Get the mask form prefix
|
||||||
|
cdr2mask()
|
||||||
|
{
|
||||||
|
# Number of args to shift, 255..255, first non-255 byte, zeroes
|
||||||
|
set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
|
||||||
|
[ $1 -gt 1 ] && shift $1 || shift
|
||||||
|
echo ${1-0}.${2-0}.${3-0}.${4-0}
|
||||||
|
}
|
||||||
|
# Get the ip4 address of the netork
|
||||||
|
network_address() {
|
||||||
|
declare address prefix_length
|
||||||
|
IFS=/ read address prefix_length <<< "$1"
|
||||||
|
|
||||||
|
declare -a octets
|
||||||
|
IFS=. read -a octets <<< "$address"
|
||||||
|
|
||||||
|
declare mask
|
||||||
|
mask=$( printf "%08x" $(( (1 << 32) - (1 << (32 - prefix_length)) )) )
|
||||||
|
|
||||||
|
declare -i i
|
||||||
|
for i in {0..3}; do octets[$i]=$(( octets[i] & 16#${mask:2*i:2} )); done
|
||||||
|
|
||||||
|
echo $( IFS=.; echo "${octets[*]}" )
|
||||||
|
}
|
||||||
|
echo "-- WW4 CONFIGURAION $* --"
|
||||||
|
|
||||||
|
# Make sure that a ip address was defined for out network so that
|
||||||
|
# we can configure dhcpd correctly
|
||||||
|
IP4CIDR=`ip addr | awk '/scope global/ {print $2;exit}'`
|
||||||
|
IP4=${IP4CIDR%/*}
|
||||||
|
IP4PREFIX=${IP4CIDR#*/}
|
||||||
|
IP4MASK=$(cdr2mask $IP4PREFIX)
|
||||||
|
IP4NET=$(network_address "$IP4/$IP4PREFIX")
|
||||||
|
|
||||||
|
if [ "$IP4PREFIX" -gt 25 ] ; then
|
||||||
|
echo "ERROR: warewulf does at least a /25 network for dynamic addresses"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
DYNSIZE=100
|
||||||
|
DYNSTART=${IP4#*.*.*.}
|
||||||
|
DYNPRE=${IP4%.*}
|
||||||
|
DYNEND=$(( $DYNSTART + $DYNSIZE ))
|
||||||
|
if [ $DYNEND -gt 254 ] ; then
|
||||||
|
DYNEND=$(( $IPNET + 2 + $DYNSIZE ))
|
||||||
|
DYNSTART=$(( $IPNET + 2 ))
|
||||||
|
fi
|
||||||
|
DYNSTART="${DYNPRE}.${DYNSTART}"
|
||||||
|
DYNEND="${DYNPRE}.${DYNEND}"
|
||||||
|
|
||||||
|
|
||||||
|
WW4CONF=/etc/warewulf/warewulf.conf
|
||||||
|
if [ -e $WW4CONF ] ; then
|
||||||
|
test -n $IP4 && sed -i 's/^ipaddr: EMPTY/ipaddr: '$IP4'/' $WW4CONF
|
||||||
|
test -n $IP4MASK && sed -i 's/^netmask: EMPTY/netmask: '$IP4MASK'/' $WW4CONF
|
||||||
|
test -n $IP4NET && sed -i 's/^network: EMPTY/network: '$IP4NET'/' $WW4CONF
|
||||||
|
test -n $DYNSTART && sed -i 's/^ range start: EMPTY/ range start: '$DYNSTART'/' $WW4CONF
|
||||||
|
test -n $DYNEND && sed -i 's/^ range end: EMPTY/ range end: '$DYNEND'/' $WW4CONF
|
||||||
|
cat << EOF
|
||||||
|
ipaddr: $IP4
|
||||||
|
netmask: $IP4MASK
|
||||||
|
network: $IP4NET
|
||||||
|
range start: $DYNSTART
|
||||||
|
range end: $DYNEND
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
# configure the services of the host by building the host overlay
|
||||||
|
echo "-- Running wwctl --"
|
||||||
|
wwctl overlay build
|
||||||
|
wwctl configure tftp
|
||||||
7
container-scripts/label-install
Normal file → Executable file
7
container-scripts/label-install
Normal file → Executable file
@@ -12,7 +12,8 @@ OVERLAYDIR=/var/lib/warewulf/overlays
|
|||||||
CHROOTDIR=/var/lib/warewulf/chroots
|
CHROOTDIR=/var/lib/warewulf/chroots
|
||||||
CONTAINERDIR=/var/lib/warewulf/container
|
CONTAINERDIR=/var/lib/warewulf/container
|
||||||
WAREWULFCONF=/etc/warewulf
|
WAREWULFCONF=/etc/warewulf
|
||||||
BASHCOMPLETION=/usr/share/bash-completion/completions/wwctl
|
BASHCOMPLETION=/usr/share/bash_completion/completions/wwctl
|
||||||
|
CONFSCRIPT=/container/config-warewulf
|
||||||
|
|
||||||
echo "LABEL INSTALL"
|
echo "LABEL INSTALL"
|
||||||
# ensure all scripts will be present on the host
|
# ensure all scripts will be present on the host
|
||||||
@@ -23,6 +24,7 @@ mkdir -p $BASEDIR
|
|||||||
if [ ! -e /host/usr/local/bin/${SCRIPT} ]; then
|
if [ ! -e /host/usr/local/bin/${SCRIPT} ]; then
|
||||||
echo "copy /container/${SCRIPT} in /host/usr/local/bin/"
|
echo "copy /container/${SCRIPT} in /host/usr/local/bin/"
|
||||||
rsync -u /container/${SCRIPT} /host/usr/local/bin/${SCRIPT}
|
rsync -u /container/${SCRIPT} /host/usr/local/bin/${SCRIPT}
|
||||||
|
chmod 755 /host/usr/local/bin/${SCRIPT}
|
||||||
else
|
else
|
||||||
echo "/host/usr/local/bin/${SCRIPT} already exist, will not update it"
|
echo "/host/usr/local/bin/${SCRIPT} already exist, will not update it"
|
||||||
fi
|
fi
|
||||||
@@ -73,3 +75,6 @@ fi
|
|||||||
|
|
||||||
# containerdir
|
# containerdir
|
||||||
mkdir -p /host/$CONTAINERDIR
|
mkdir -p /host/$CONTAINERDIR
|
||||||
|
|
||||||
|
# now config the container
|
||||||
|
$CONFSCRIPT
|
||||||
|
|||||||
0
container-scripts/label-purge
Normal file → Executable file
0
container-scripts/label-purge
Normal file → Executable file
2
container-scripts/label-uninstall
Normal file → Executable file
2
container-scripts/label-uninstall
Normal file → Executable file
@@ -17,4 +17,4 @@ echo "LABEL UNINSTALL: Removing all files"
|
|||||||
rm -vf /host/usr/local/bin/wwctl
|
rm -vf /host/usr/local/bin/wwctl
|
||||||
rm -vf /host/usr/local/bin/warewulf-container-manage.sh
|
rm -vf /host/usr/local/bin/warewulf-container-manage.sh
|
||||||
rm -vf /host/etc/systemd/system/${CONTAINER}.service
|
rm -vf /host/etc/systemd/system/${CONTAINER}.service
|
||||||
rm -vf /host/usr/share/bash-completion/completions/wwctl
|
rm -vf /host/usr/share/bash_completion/completions/wwctl
|
||||||
|
|||||||
108
container-scripts/warewulf-container-manage.sh
Executable file
108
container-scripts/warewulf-container-manage.sh
Executable file
@@ -0,0 +1,108 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# quick script to manage the container
|
||||||
|
CONTAINER_NAME=warewulf
|
||||||
|
|
||||||
|
create_container() {
|
||||||
|
podman create \
|
||||||
|
--name ${CONTAINER_NAME} \
|
||||||
|
--tls-verify=false \
|
||||||
|
--network host \
|
||||||
|
${IMAGE}
|
||||||
|
}
|
||||||
|
|
||||||
|
run_container() {
|
||||||
|
podman run \
|
||||||
|
--name ${CONTAINER_NAME} \
|
||||||
|
--rm -ti \
|
||||||
|
--network host \
|
||||||
|
--entrypoint bash \
|
||||||
|
${IMAGE}
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "
|
||||||
|
First ARG is mandatory:
|
||||||
|
$0 [create|start|stop|rm|rmcache|run|bash|logs|install|uninstall]
|
||||||
|
|
||||||
|
CONTAINER_NAME: '${CONTAINER_NAME}'
|
||||||
|
|
||||||
|
DEPLOYMENT:
|
||||||
|
create
|
||||||
|
Pull the image and create the container automatically
|
||||||
|
|
||||||
|
install
|
||||||
|
install needed files on the host to manage '${CONTAINER_NAME}' container
|
||||||
|
(in /usr/local/bin and /etc)
|
||||||
|
|
||||||
|
start
|
||||||
|
Start the container '${CONTAINER_NAME}'
|
||||||
|
|
||||||
|
REMOVAL:
|
||||||
|
uninstall
|
||||||
|
uninstall all needed files on the host to manage '${CONTAINER_NAME}' container
|
||||||
|
|
||||||
|
stop
|
||||||
|
stop the container '${CONTAINER_NAME}'
|
||||||
|
|
||||||
|
rm
|
||||||
|
delete the container '${CONTAINER_NAME}'
|
||||||
|
|
||||||
|
rmcache
|
||||||
|
remove the container image in cache ${IMAGE}
|
||||||
|
|
||||||
|
DEBUG:
|
||||||
|
run
|
||||||
|
podman run container '${CONTAINER_NAME}'
|
||||||
|
|
||||||
|
bash
|
||||||
|
go with /bin/bash command inside '${CONTAINER_NAME}'
|
||||||
|
|
||||||
|
logs
|
||||||
|
see log of container '${CONTAINER_NAME}'
|
||||||
|
|
||||||
|
"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
###########
|
||||||
|
# MAIN
|
||||||
|
###########
|
||||||
|
set -euxo pipefail
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
start)
|
||||||
|
podman start ${CONTAINER_NAME}
|
||||||
|
podman ps | grep ${CONTAINER_NAME}
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
podman stop ${CONTAINER_NAME}
|
||||||
|
podman ps | grep ${CONTAINER_NAME}
|
||||||
|
;;
|
||||||
|
rm)
|
||||||
|
set +e
|
||||||
|
podman stop ${CONTAINER_NAME}
|
||||||
|
podman rm ${CONTAINER_NAME}
|
||||||
|
;;
|
||||||
|
create)
|
||||||
|
create_container
|
||||||
|
;;
|
||||||
|
run)
|
||||||
|
run_container
|
||||||
|
;;
|
||||||
|
rmcache)
|
||||||
|
podman rmi ${IMAGE}
|
||||||
|
;;
|
||||||
|
logs)
|
||||||
|
podman logs ${CONTAINER_NAME}
|
||||||
|
;;
|
||||||
|
bash)
|
||||||
|
set +e
|
||||||
|
podman exec -ti ${CONTAINER_NAME} $@
|
||||||
|
;;
|
||||||
|
install)
|
||||||
|
podman run --env IMAGE=${IMAGE} --rm --privileged -v /:/host ${IMAGE} /bin/bash /container/label-install
|
||||||
|
;;
|
||||||
|
uninstall)
|
||||||
|
podman run --env IMAGE=${IMAGE} --rm --privileged -v /:/host ${IMAGE} /bin/bash /container/label-uninstall
|
||||||
|
;;
|
||||||
|
esac
|
||||||
2
container-scripts/wwctl
Normal file → Executable file
2
container-scripts/wwctl
Normal file → Executable file
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source /etc/warewulf-container.conf
|
|
||||||
|
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
# Run the domain
|
# Run the domain
|
||||||
|
|||||||
Reference in New Issue
Block a user