@@ -126,19 +126,30 @@ templater()
126126 fi
127127 done < " $tfw_cfg_path "
128128
129- opts=$( get_opts " $cfg_content " " access_log" )
130- while read -r line; do
131- if [ $( opt_exists " $line " " mmap" ; echo $? ) -ne 0 ]; then
132- tfw_logger_should_start=1
133- mmap_log=$( get_opt_value " $line " " mmap_log" )
134- mmap_host=$( get_opt_value " $line " " mmap_host" )
135- mmap_user=$( get_opt_value " $line " " mmap_user" )
136- mmap_password=$( get_opt_value " $line " " mmap_password" )
137-
138- [[ -n " $mmap_log " && -n " $mmap_host " ]] ||
139- error " if mmaps enabled in access log, there have to be mmap_host and mmap_log options"
140- fi
141- done <<< " $opts"
129+ tfw_logger_config_path=$( echo " $cfg_content " | grep -oP ' access_log\s+.*logger_config=\K[^;]*' | sed ' s/"//g' | sed " s/'//g" )
130+ if [ -n " $tfw_logger_config_path " ]; then
131+ tfw_logger_should_start=1
132+ else
133+ opts=$( get_opts " $cfg_content " " access_log" )
134+ while read -r line; do
135+ if [ $( opt_exists " $line " " mmap" ; echo $? ) -ne 0 ]; then
136+ tfw_logger_should_start=1
137+ mmap_log=$( get_opt_value " $line " " mmap_log" )
138+ mmap_host=$( get_opt_value " $line " " mmap_host" )
139+ mmap_user=$( get_opt_value " $line " " mmap_user" )
140+ mmap_password=$( get_opt_value " $line " " mmap_password" )
141+
142+ [[ -n " $mmap_log " && -n " $mmap_host " ]] ||
143+ error " if mmaps enabled in access log, there have to be mmap_host and mmap_log options"
144+ fi
145+ done <<< " $opts"
146+ fi
147+
148+ # Check for buffer size
149+ buffer_size=$( echo " $cfg_content " | grep -oP ' mmap_log_buffer_size\s+\K[^;]*' )
150+ if [ -n " $buffer_size " ]; then
151+ mmap_log_buffer_size=$buffer_size
152+ fi
142153
143154 cfg_content=$( remove_opts_by_mask " $cfg_content " " mmap_" )
144155
@@ -311,14 +322,29 @@ start_tfw_logger()
311322 return
312323 fi
313324
314- if [ -z "$mmap_host " ] || [ -z "$mmap_log " ]; then
315- error "You need to specify 'mmap_host' and 'mmap_log' "`
316- `"if access_log mmap was specified"
317- return
318- fi
325+ # Check if we have a JSON config path specified
326+ if [ -n "$tfw_logger_config_path " ]; then
327+ echo "...starting tfw_logger with JSON config: $tfw_logger_config_path "
328+ "$utils_path /tfw_logger" --config="$tfw_logger_config_path " || \
329+ error "cannot start tfw_logger daemon"
330+ else
331+ # Traditional approach with command line parameters
332+ if [ -z "$mmap_host " ] || [ -z "$mmap_log " ]; then
333+ error "You need to specify 'mmap_host' and 'mmap_log' if access_log mmap was specified"
334+ return
335+ fi
336+
337+ echo "...starting tfw_logger with command line arguments"
338+ cmd_args="--clickhouse-host=$mmap_host --log-path=$mmap_log "
319339
320- "$utils_path /tfw_logger" -H "$mmap_host " -l "$mmap_log " -u "$mmap_user " -p "$mmap_password " ||
340+ # Add optional parameters
341+ [ -n "$mmap_user " ] && cmd_args="$cmd_args --clickhouse-user=$mmap_user "
342+ [ -n "$mmap_password " ] && cmd_args="$cmd_args --clickhouse-password=$mmap_password "
343+ [ -n "$mmap_log_buffer_size " ] && cmd_args="$cmd_args --buffer-size=$mmap_log_buffer_size "
344+
345+ "$utils_path /tfw_logger" $cmd_args || \
321346 error "cannot start tfw_logger daemon"
347+ fi
322348
323349 start_time=$(date +%s)
324350 while [[ ! -f "$tfw_logger_pid_path " ]]; do
@@ -329,18 +355,19 @@ start_tfw_logger()
329355 sysctl -e -w net.tempesta.state=stop
330356 unload_modules
331357 tfw_irqbalance_revert
332- error " tfw_logger failed to start, see $mmap_log for details"
358+ error " tfw_logger failed to start, see logs for details"
333359 fi
334360
335361 sleep 0.1
336362 done
337-
338363}
339364
340365stop_tfw_logger ()
341366{
342367 if [ -e $tfw_logger_pid_path ]; then
343- " $utils_path /tfw_logger" -s
368+ echo " ...stopping tfw_logger"
369+ " $utils_path /tfw_logger" --stop || \
370+ echo " Warning: Failed to stop tfw_logger daemon gracefully"
344371 fi
345372}
346373
0 commit comments