Skip to content

Commit

Permalink
google_set_hostname: extract rsyslog service name with a regexp for v…
Browse files Browse the repository at this point in the history
…alid systemd unit names (#67)
  • Loading branch information
a-crate authored Mar 4, 2024
1 parent b0fbc3b commit b261b1c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/usr/bin/google_set_hostname
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ if [ -n "$new_host_name" ] && [ "${new_host_name%%.*}" != "$old_hostname" ] && !
# Restart rsyslog to update the hostname.
systemctl=$(which systemctl 2> /dev/null)
if [ -x "$systemctl" ]; then
hasrsyslog=$($systemctl | grep rsyslog | cut -f1 -d' ')
# See man 5 systemd.unit for systemd unit naming rules
hasrsyslog=$($systemctl | grep rsyslog | grep -oE '[a-zA-Z0-9:-_.\]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)')
if [ ! -z "$hasrsyslog" ]; then
$systemctl -q --no-block restart "$hasrsyslog"
fi
Expand Down

0 comments on commit b261b1c

Please sign in to comment.