diff --git a/jobs/haproxy/templates/pre-start.erb b/jobs/haproxy/templates/pre-start.erb index c167909a..03ad3abb 100644 --- a/jobs/haproxy/templates/pre-start.erb +++ b/jobs/haproxy/templates/pre-start.erb @@ -7,19 +7,23 @@ create_or_update_link() { local target="$1" local link="$2" + # check if the symlink already exists if [ -L "$link" ]; then + # symlink already exists + # check if the existing symlink does not point to the target if [ "$(readlink "$link")" != "$target" ]; then - echo "Updating symbolic link..." + echo "Updating symbolic link ($link -> $target)..." sudo ln -sf "$target" "$link" fi else + # symlink doesn't exist + # If the path exists but is not a symlink, remove it (could be a regular file or directory) if [ -e "$link" ]; then - echo "Removing existing file and creating a new symbolic link..." + echo "Removing existing path ($link)..." sudo rm "$link" - else - echo "Creating new symbolic link..." - sudo ln -s "$target" "$link" fi + echo "Creating new symbolic link ($link -> $target)..." + sudo ln -s "$target" "$link" fi }