From 52005dd6ae88b15ff2dc5f5c090eac601a2a0c22 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 24 May 2021 16:20:54 -0400 Subject: [PATCH] Further flesh out diskless profile --- .../hooks/cmdline/10-confluentdiskless.sh | 2 +- .../diskless/profile/common/scripts/functions | 141 ++++++++++++++++++ .../diskless/profile/common/scripts/onboot.sh | 1 + 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 confluent_osdeploy/diskless/profile/common/scripts/functions diff --git a/confluent_osdeploy/diskless/initramfs/usr/lib/dracut/hooks/cmdline/10-confluentdiskless.sh b/confluent_osdeploy/diskless/initramfs/usr/lib/dracut/hooks/cmdline/10-confluentdiskless.sh index aa3dea0d..dfe9d0b8 100644 --- a/confluent_osdeploy/diskless/initramfs/usr/lib/dracut/hooks/cmdline/10-confluentdiskless.sh +++ b/confluent_osdeploy/diskless/initramfs/usr/lib/dracut/hooks/cmdline/10-confluentdiskless.sh @@ -257,6 +257,6 @@ mkdir -p /sysroot/opt/confluent/bin curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/onboot.sh > /sysroot/opt/confluent/bin/onboot.sh chmod +x /sysroot/opt/confluent/bin/onboot.sh ln -s /etc/systemd/system/onboot.service /sysroot/etc/systemd/system/multi-user.target.wants/onboot.service - +curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/functions > /sysroot/etc/confluent/functions exec /opt/confluent/bin/start_root diff --git a/confluent_osdeploy/diskless/profile/common/scripts/functions b/confluent_osdeploy/diskless/profile/common/scripts/functions new file mode 100644 index 00000000..40fe2fa2 --- /dev/null +++ b/confluent_osdeploy/diskless/profile/common/scripts/functions @@ -0,0 +1,141 @@ +function set_confluent_vars() { + if [ -z "$confluent_mgr" ]; then + confluent_mgr=$(grep ^deploy_server: /etc/confluent/confluent.deploycfg | sed -e 's/[^ ]*: //') + fi + if [ -z "$confluent_profile" ]; then + confluent_profile=$(grep ^profile: /etc/confluent/confluent.deploycfg | sed -e 's/[^ ]*: //') + fi +} + +fetch_remote() { + curlargs="" + if [ -f /etc/confluent/ca.pem ]; then + curlargs=" --cacert /etc/confluent/ca.pem" + fi + set_confluent_vars + mkdir -p $(dirname $1) + curl -f -sS $curlargs https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/$1 > $1 + if [ $? != 0 ]; then echo $1 failed to download; return 1; fi +} + +source_remote_parts() { + confluentscripttmpdir=$(mktemp -d) + apiclient=/opt/confluent/bin/apiclient + if [ -f /etc/confluent/apiclient ]; then + apiclient=/etc/confluent/apiclient + fi + scriptlist=$(/usr/libexec/platform-python $apiclient /confluent-api/self/scriptlist/$1|sed -e 's/^- //') + for script in $scriptlist; do + source_remote $1/$script + done + unset confluentscripttmpdir +} + +run_remote_parts() { + confluentscripttmpdir=$(mktemp -d) + apiclient=/opt/confluent/bin/apiclient + if [ -f /etc/confluent/apiclient ]; then + apiclient=/etc/confluent/apiclient + fi + scriptlist=$(/usr/libexec/platform-python $apiclient /confluent-api/self/scriptlist/$1|sed -e 's/^- //') + for script in $scriptlist; do + run_remote $1/$script + done + unset confluentscripttmpdir +} + +source_remote() { + set_confluent_vars + echo + echo '---------------------------------------------------------------------------' + echo Sourcing $1 from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/ + if [ -z "$confluentscripttmpdir" ]; then + confluentscripttmpdir=$(mktemp -d) + fi + echo Sourcing from $confluentscripttmpdir + cd $confluentscripttmpdir + fetch_remote $1 + if [ $? != 0 ]; then echo $1 failed to download; return 1; fi + chmod +x $1 + cmd=$1 + shift + source $cmd + cd - > /dev/null + return $retcode +} + +run_remote() { + requestedcmd="'$*'" + set_confluent_vars + echo + echo '---------------------------------------------------------------------------' + echo Running $requestedcmd from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/ + if [ -z "$confluentscripttmpdir" ]; then + confluentscripttmpdir=$(mktemp -d) + fi + echo Executing in $confluentscripttmpdir + cd $confluentscripttmpdir + fetch_remote $1 + if [ $? != 0 ]; then echo $requestedcmd failed to download; return 1; fi + chmod +x $1 + cmd=$1 + if [ -x /usr/bin/chcon ]; then + chcon system_u:object_r:bin_t:s0 $cmd + fi + shift + ./$cmd $* + retcode=$? + if [ $retcode -ne 0 ]; then + echo "$requestedcmd exited with code $retcode" + fi + cd - > /dev/null + return $retcode +} + +run_remote_python() { + echo + set_confluent_vars + if [ -f /etc/confluent/ca.pem ]; then + curlargs=" --cacert /etc/confluent/ca.pem" + fi + echo '---------------------------------------------------------------------------' + echo Running python script "'$*'" from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/ + tmpdir=$(mktemp -d) + echo Executing in $tmpdir + cd $tmpdir + mkdir -p $(dirname $1) + curl -f -sS $curlargs https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/$1 > $1 + if [ $? != 0 ]; then echo "'$*'" failed to download; return 1; fi + if [ -x /usr/libexec/platform-python ]; then + /usr/libexec/platform-python $* + else + /usr/bin/python $* + fi + retcode=$? + echo "'$*' exited with code $retcode" + cd - > /dev/null + return $retcode +} + +run_remote_config() { + echo + set_confluent_vars + apiclient=/opt/confluent/bin/apiclient + if [ -f /etc/confluent/apiclient ]; then + apiclient=/etc/confluent/apiclient + fi + echo '---------------------------------------------------------------------------' + echo Requesting to run remote configuration for "'$*'" from $confluent_mgr under profile $confluent_profile + if [ -x /usr/libexec/platform-python ]; then + /usr/libexec/platform-python $apiclient /confluent-api/self/remoteconfig/"$*" -d {} + /usr/libexec/platform-python $apiclient /confluent-api/self/remoteconfig/status -w 204 + else + /usr/bin/python $apiclient /confluent-api/self/remoteconfig/"$*" -d {} + /usr/bin/python $apiclient /confluent-api/self/remoteconfig/status -w 204 + fi + echo + echo 'Completed remote configuration' + echo '---------------------------------------------------------------------------' + return +} + diff --git a/confluent_osdeploy/diskless/profile/common/scripts/onboot.sh b/confluent_osdeploy/diskless/profile/common/scripts/onboot.sh index 9f26fb6e..c238c601 100644 --- a/confluent_osdeploy/diskless/profile/common/scripts/onboot.sh +++ b/confluent_osdeploy/diskless/profile/common/scripts/onboot.sh @@ -11,6 +11,7 @@ confluent_mgr=$(grep deploy_server /etc/confluent/confluent.deploycfg|awk '{prin confluent_profile=$(grep ^profile: /etc/confluent/confluent.deploycfg|awk '{print $2}') export nodename confluent_mgr confluent_profile . /etc/confluent/functions +mkdir -p /var/log/confluent exec >> /var/log/confluent/confluent-onboot.log exec 2>> /var/log/confluent/confluent-onboot.log tail -f /var/log/confluent/confluent-onboot.log > /dev/console &