Skip to content

Commit

Permalink
Simple test to avoid service restart if unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusburghardt committed May 25, 2023
1 parent b8e785e commit 8dc3884
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ rainer_regex='^\s*(module|input)\((load|type)="(imtcp|imudp)".*$'
readarray -t legacy_targets < <(grep -l -E -r "${legacy_regex[@]}" /etc/rsyslog.conf /etc/rsyslog.d/)
readarray -t rainer_targets < <(grep -l -E -r "${rainer_regex[@]}" /etc/rsyslog.conf /etc/rsyslog.d/)

config_changed=false
if [ ${#legacy_targets[@]} -gt 0 ]; then
for target in "${legacy_targets[@]}"; do
sed -E -i "/$legacy_regex/ s/^/# /" "$target"
done
config_changed=true
fi

if [ ${#rainer_targets[@]} -gt 0 ]; then
for target in "${rainer_targets[@]}"; do
sed -E -i "/$rainer_regex/ s/^/# /" "$target"
done
config_changed=true
fi

systemctl restart rsyslog.service
if $config_changed; then
systemctl restart rsyslog.service
fi

0 comments on commit 8dc3884

Please sign in to comment.