@@ -7,8 +7,8 @@ ENV_FILE_PATH="/etc/environment"
77source $ENV_FILE_PATH
88env | grep -E ' K8S|RKE2|WORK|CONTROL'
99
10- # Redirect stdout and stderr to log file
11- exec > >( tee -a " $LOG_FILE " ) 2>&1
10+ # Simple logging approach - log important steps manually
11+ echo " Script started at: $( date ) " | tee -a " $LOG_FILE "
1212
1313# set commands for error handling.
1414set -e
@@ -18,44 +18,44 @@ set -o errtrace # trace ERR through 'time command' and other functions
1818set -o pipefail # trace ERR through pipes
1919
2020# Add error handler
21- trap ' echo "Error occurred at line $LINENO. Exit code: $?" >&2' ERR
21+ trap ' echo "Error occurred at line $LINENO. Exit code: $?" | tee -a "$LOG_FILE" >&2' ERR
2222
2323# Validate required environment variables
24- echo " Validating required environment variables..."
24+ echo " Validating required environment variables..." | tee -a " $LOG_FILE "
2525required_vars=(" WORK_DIR" " K8S_INFRA_REPO_URL" " K8S_INFRA_BRANCH" " RKE2_CONFIG_DIR" " RKE2_LOCATION" " NODE_NAME" " K8S_TOKEN" " INTERNAL_IP" " CONTROL_PLANE_NODE_1" " CLUSTER_DOMAIN" )
2626
2727for var in " ${required_vars[@]} " ; do
2828 if [[ -z " ${! var:- } " ]]; then
29- echo " Error: Required environment variable $var is not set"
29+ echo " Error: Required environment variable $var is not set" | tee -a " $LOG_FILE "
3030 exit 1
3131 else
32- echo " $var is set"
32+ echo " $var is set" | tee -a " $LOG_FILE "
3333 fi
3434done
3535
36- echo " All required environment variables are present"
36+ echo " All required environment variables are present" | tee -a " $LOG_FILE "
3737
3838
39- echo " Installing RKE2"
39+ echo " Installing RKE2" | tee -a " $LOG_FILE "
4040RKE2_EXISTENCE=$( which rke2 2> /dev/null || echo " " )
4141if [[ -z " $RKE2_EXISTENCE " ]]; then
42- echo " RKE2 not found, installing..."
42+ echo " RKE2 not found, installing..." | tee -a " $LOG_FILE "
4343 curl -sfL https://get.rke2.io | sh -
44- echo " RKE2 installation completed"
44+ echo " RKE2 installation completed" | tee -a " $LOG_FILE "
4545else
46- echo " RKE2 already installed at: $RKE2_EXISTENCE "
46+ echo " RKE2 already installed at: $RKE2_EXISTENCE " | tee -a " $LOG_FILE "
4747fi
4848
4949cd $WORK_DIR
50- echo " Cloning K8S infrastructure repository..."
50+ echo " Cloning K8S infrastructure repository..." | tee -a " $LOG_FILE "
5151if [ -d " k8s-infra" ]; then
52- echo " k8s-infra directory already exists, updating..."
52+ echo " k8s-infra directory already exists, updating..." | tee -a " $LOG_FILE "
5353 cd k8s-infra
54- git pull origin $K8S_INFRA_BRANCH || echo " Warning: git pull failed, continuing with existing files"
54+ git pull origin $K8S_INFRA_BRANCH || echo " Warning: git pull failed, continuing with existing files" | tee -a " $LOG_FILE "
5555 cd $WORK_DIR
5656else
5757 git clone $K8S_INFRA_REPO_URL -b $K8S_INFRA_BRANCH || {
58- echo " Warning: git clone failed, but continuing..."
58+ echo " Warning: git clone failed, but continuing..." | tee -a " $LOG_FILE "
5959 }
6060fi
6161
@@ -65,28 +65,27 @@ chown -R 1000:1000 $RKE2_CONFIG_DIR
6565cd $RKE2_LOCATION
6666
6767if [[ -f " $RKE2_CONFIG_DIR /config.yaml" ]]; then
68- echo " RKE CONFIG file exists \" $RKE2_CONFIG_DIR /config.yaml\" "
69- echo " RKE2 setup already completed, exiting successfully"
68+ echo " RKE CONFIG file exists \" $RKE2_CONFIG_DIR /config.yaml\" " | tee -a " $LOG_FILE "
69+ echo " RKE2 setup already completed, exiting successfully" | tee -a " $LOG_FILE "
7070 exit 0
7171fi
7272
7373# Determine the role of the instance using pattern matching
74- sleep 30
7574source $ENV_FILE_PATH
76- echo " Node name: $NODE_NAME "
77- echo " Current directory: $( pwd) "
78- echo " Files in current directory:"
79- ls -la
75+ echo " Node name: $NODE_NAME " | tee -a " $LOG_FILE "
76+ echo " Current directory: $( pwd) " | tee -a " $LOG_FILE "
77+ echo " Files in current directory:" | tee -a " $LOG_FILE "
78+ ls -la | tee -a " $LOG_FILE "
8079
8180if [[ " $NODE_NAME " == CONTROL-PLANE-NODE-1 ]]; then
82- echo " PRIMARY CONTROL PLANE NODE"
81+ echo " PRIMARY CONTROL PLANE NODE" | tee -a " $LOG_FILE "
8382 RKE2_SERVICE=" rke2-server"
84- echo " Looking for primary control plane config template..."
85- ls -la rke2-server-control-plane-primary.conf.template 2> /dev/null || echo " Template file not found!"
83+ echo " Looking for primary control plane config template..." | tee -a " $LOG_FILE "
84+ ls -la rke2-server-control-plane-primary.conf.template 2> /dev/null | tee -a " $LOG_FILE " || echo " Template file not found!" | tee -a " $LOG_FILE "
8685 if cp rke2-server-control-plane-primary.conf.template $RKE2_CONFIG_DIR /config.yaml; then
87- echo " Successfully copied primary control plane config template"
86+ echo " Successfully copied primary control plane config template" | tee -a " $LOG_FILE "
8887 else
89- echo " Error: Failed to copy primary control plane config template"
88+ echo " Error: Failed to copy primary control plane config template" | tee -a " $LOG_FILE "
9089 exit 1
9190 fi
9291 export RKE2_SERVICE=" rke2-server" | sudo tee -a $ENV_FILE_PATH
0 commit comments