Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LVM-activate: fix drop-in check to avoid re-creating drop-in file when it already exists #1652

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions heartbeat/LVM-activate
Original file line number Diff line number Diff line change
Expand Up @@ -820,17 +820,14 @@ lvm_start() {
if systemd_is_running ; then
# Create drop-in to deactivate VG before stopping
# storage services during shutdown/reboot.
after=$(systemctl show resource-agents-deps.target.d \
--property=After | cut -d'=' -f2)

case "$after" in
*" blk-availability.service "*)
;;
*)
systemd_drop_in "99-LVM-activate" "After" \
systemctl show resource-agents-deps.target \
--property=After | cut -d'=' -f2 | \
grep -qE "(^|\s)blk-availability.service(\s|$)"
Copy link
Member

Choose a reason for hiding this comment

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

\s may or may not be supported as shorthand for [[:space:]], depending on the version of grep.
Why not use an actual space? Or even use the same shell "case" logic as before, but like this:
case " $after " in *" ... "*) (note the extra space around $after)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The shell logic before only matched if you got 3 or more hits (and blk... wasnt first or last). We use \s (and the combination with beginning/end of line) with grep in other agents, and noone has complained about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I had used the case idiom in 79fb4b2 as an attempt at portability -- I don't remember the details, but I think I had found something less than ideal about grep at the time. -q is also not as portable as >/dev/null 2>&1.

But none of that mattered, since my two typos ("$after" instead of " $after ", and target.d instead of target) broke the whole thing anyway :)


if [ "$?" -ne 0 ]; then
systemd_drop_in "99-LVM-activate" "After" \
"blk-availability.service"
;;
esac
fi

# If blk-availability isn't started, the "After="
# directive has no effect.
Expand Down