@@ -93,6 +93,13 @@ cleanup() {
9393 fi
9494}
9595
96+ # Define MYSQL_PASSWORD_OPTION based on SUPERUSER_PASSWORD
97+ if [ -z " $SUPERUSER_PASSWORD " ]; then
98+ MYSQL_PASSWORD_OPTION=" --no-password"
99+ else
100+ MYSQL_PASSWORD_OPTION=" --password=$SUPERUSER_PASSWORD "
101+ fi
102+
96103# Function to run replica setup
97104run_replica_setup () {
98105 case " $SOURCE_TYPE " in
@@ -116,6 +123,8 @@ run_replica_setup() {
116123 ;;
117124 esac
118125
126+ export MYDUCK_PASSWORD=" ${SUPERUSER_PASSWORD} "
127+
119128 # Run replica_setup.sh and check for errors
120129 if source replica_setup.sh; then
121130 echo " Replica setup completed."
@@ -127,7 +136,16 @@ run_replica_setup() {
127136
128137run_server_in_background () {
129138 cd " $DATA_PATH " || { echo " Error: Could not change directory to ${DATA_PATH} " ; exit 1; }
130- nohup myduckserver $DEFAULT_DB $SUPERUSER_PASSWORD $LOG_LEVEL $PROFILER_PORT $RESTORE_FILE $RESTORE_ENDPOINT $RESTORE_ACCESS_KEY_ID $RESTORE_SECRET_ACCESS_KEY | tee -a " ${LOG_PATH} /server.log" 2>&1 &
139+ nohup myduckserver \
140+ ${DEFAULT_DB_OPTION} \
141+ ${SUPERUSER_PASSWORD_OPTION} \
142+ ${LOG_LEVEL_OPTION} \
143+ ${PROFILER_PORT_OPTION} \
144+ ${RESTORE_FILE_OPTION} \
145+ ${RESTORE_ENDPOINT_OPTION} \
146+ ${RESTORE_ACCESS_KEY_ID_OPTION} \
147+ ${RESTORE_SECRET_ACCESS_KEY_OPTION} \
148+ | tee -a " ${LOG_PATH} /server.log" 2>&1 &
131149 echo " $! " > " ${PID_FILE} "
132150}
133151
@@ -141,10 +159,10 @@ wait_for_my_duck_server_ready() {
141159
142160 echo " Waiting for MyDuck Server at $host :$port to be ready..."
143161
144- until mysqlsh --sql --host " $host " --port " $port " --user " $user " --no-password --execute " SELECT VERSION();" & > /dev/null; do
162+ until mysqlsh --sql --host " $host " --port " $port " --user " $user " ${MYSQL_PASSWORD_OPTION} --execute " SELECT VERSION();" & > /dev/null; do
145163 attempt=$(( attempt+ 1 ))
146164 if [ " $attempt " -ge " $max_attempts " ]; then
147- echo " Error: MySQL connection timed out after $max_attempts attempts."
165+ echo " Error: MySQL connection timeout after $max_attempts attempts."
148166 exit 1
149167 fi
150168 echo " Attempt $attempt /$max_attempts : MyDuck Server is unavailable - retrying in $wait_time seconds..."
@@ -186,14 +204,14 @@ execute_init_sqls() {
186204 echo " Executing init SQL scripts from $INIT_SQLS_DIR /mysql..."
187205 for file in " $INIT_SQLS_DIR /mysql" /* .sql; do
188206 echo " Executing $file ..."
189- mysqlsh --sql --host " $host " --port " $mysql_port " --user " $mysql_user " --no-password --file=" $file "
207+ mysqlsh --sql --host " $host " --port " $mysql_port " --user " $mysql_user " $MYSQL_PASSWORD_OPTION --file=" $file "
190208 done
191209 fi
192210 if [ -d " $INIT_SQLS_DIR /postgres" ] && [ " $( find " $INIT_SQLS_DIR /postgres" -maxdepth 1 -name ' *.sql' -type f | head -n 1) " ]; then
193211 echo " Executing init SQL scripts from $INIT_SQLS_DIR /postgres..."
194212 for file in " $INIT_SQLS_DIR /postgres" /* .sql; do
195213 echo " Executing $file ..."
196- psql -h " $host " -p " $postgres_port " -U " $postgres_user " -f " $file "
214+ PGPASSWORD= " $SUPERUSER_PASSWORD " psql -h " $host " -p " $postgres_port " -U " $postgres_user " -f " $file "
197215 done
198216 fi
199217}
@@ -204,35 +222,35 @@ setup() {
204222 trap cleanup SIGTERM SIGINT SIGQUIT
205223
206224 if [ -n " $DEFAULT_DB " ]; then
207- export DEFAULT_DB =" --default-db=$DEFAULT_DB "
225+ export DEFAULT_DB_OPTION =" --default-db=$DEFAULT_DB "
208226 fi
209227
210228 if [ -n " $SUPERUSER_PASSWORD " ]; then
211- export SUPERUSER_PASSWORD =" --superuser-password=$SUPERUSER_PASSWORD "
229+ export SUPERUSER_PASSWORD_OPTION =" --superuser-password=$SUPERUSER_PASSWORD "
212230 fi
213231
214232 if [ -n " $LOG_LEVEL " ]; then
215- export LOG_LEVEL =" --loglevel=$LOG_LEVEL "
233+ export LOG_LEVEL_OPTION =" --loglevel=$LOG_LEVEL "
216234 fi
217235
218236 if [ -n " $PROFILER_PORT " ]; then
219- export PROFILER_PORT =" --profiler-port=$PROFILER_PORT "
237+ export PROFILER_PORT_OPTION =" --profiler-port=$PROFILER_PORT "
220238 fi
221239
222240 if [ -n " $RESTORE_FILE " ]; then
223- export RESTORE_FILE =" --restore-file=$RESTORE_FILE "
241+ export RESTORE_FILE_OPTION =" --restore-file=$RESTORE_FILE "
224242 fi
225243
226244 if [ -n " $RESTORE_ENDPOINT " ]; then
227- export RESTORE_ENDPOINT =" --restore-endpoint=$RESTORE_ENDPOINT "
245+ export RESTORE_ENDPOINT_OPTION =" --restore-endpoint=$RESTORE_ENDPOINT "
228246 fi
229247
230248 if [ -n " $RESTORE_ACCESS_KEY_ID " ]; then
231- export RESTORE_ACCESS_KEY_ID =" --restore-access-key-id=$RESTORE_ACCESS_KEY_ID "
249+ export RESTORE_ACCESS_KEY_ID_OPTION =" --restore-access-key-id=$RESTORE_ACCESS_KEY_ID "
232250 fi
233251
234252 if [ -n " $RESTORE_SECRET_ACCESS_KEY " ]; then
235- export RESTORE_SECRET_ACCESS_KEY =" --restore-secret-access-key=$RESTORE_SECRET_ACCESS_KEY "
253+ export RESTORE_SECRET_ACCESS_KEY_OPTION =" --restore-secret-access-key=$RESTORE_SECRET_ACCESS_KEY "
236254 fi
237255
238256 # Ensure required directories exist
0 commit comments