Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions openwisp-config/files/openwisp.agent
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ while [ -n "$1" ]; do
export CHECKSUM_RETRY_DELAY="$2"
shift
;;
--log-message)
log_message "$2"
exit 0
;;
-*)
echo "Invalid option: $1"
exit 1
Expand Down Expand Up @@ -971,3 +975,15 @@ while true; do
# ignore SIGUSR1 signals again
trap "" USR1
done

# Logging function
log_message() {
local level="$1"
local message="${2:-}" # Default to an empty string if the second argument is not provided
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make the message mandatory. For the level I would fall back to daemon.info if none is provided.


if [ -z "$message" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this if statement. You can provide a default value in the assignment of the message variable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the if [ -z "$message" ] check unnecessary when we already have local message="${2:-}"? Could you clarify the reasoning?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shwetd19
If you see the above comment, Oliver suggested a fall back when message is not provided. In that case, this check will be unnecessary

logger -t openwisp -p "$level" "No message provided"
else
logger -t openwisp -p "$level" "$message"
fi
}
4 changes: 2 additions & 2 deletions openwisp-config/files/openwisp.init
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ start_service() {
config_foreach parse_config controller
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_close_instance
logger -s "$PROG_NAME started" -t openwisp -p daemon.info
/usr/sbin/openwisp-config --log-message "$PROG_NAME started"
}

service_triggers() {
Expand All @@ -87,7 +87,7 @@ stop_service() {
}

reload_service() {
logger -s "$PROG_NAME received reload trigger" -t openwisp -p daemon.info
/usr/sbin/openwisp-config --log-message "$PROG_NAME received reload trigger"
# avoid reloading while configuration is being applied
# will wait for a maximum of 30 seconds
for _ in $(seq 1 30); do
Expand Down
3 changes: 2 additions & 1 deletion openwisp-config/files/sbin/openwisp-reload-config
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ if [ -f $MD5FILE ]; then
logger_msg="Service $service has been reloaded via init.d script"
fi
# log which service has been reloaded and how
logger "$logger_msg" -t openwisp -p daemon.info
/usr/sbin/openwisp-config --log-message "$logger_msg"

done
fi
md5sum /var/run/config.check/* >$MD5FILE
Expand Down
Loading