# Created on savesnippets.com · https://savesnippets.com/ca18gbpXXNdIu1 # Atomic deploy pattern: # /opt/myapp/releases/20250312-141500 # /opt/myapp/current -> releases/20250312-141500 deploy() { local release="releases/$(date -u +%Y%m%d-%H%M%S)" mkdir -p "/opt/myapp/$release" # ... unpack the new build into /opt/myapp/$release ... # Atomic switch — readers see either the old or the new, never a torn state ln -sfn "$release" "/opt/myapp/current" echo "Now serving: $(readlink /opt/myapp/current)" } # -s = symbolic, -f = force overwrite, -n = treat existing symlink as a file # (not as a directory to descend into — without -n, ln would create # /opt/myapp/current/release instead of updating the symlink)