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

caddycmd: Add --keep-backup to upgrade commands #4387

Merged
merged 4 commits into from
Nov 8, 2021
Merged

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented Oct 16, 2021

This is a partial fix for #4057, making it possible to retain the old build of Caddy, in case something went wrong, with the --keep-backup flag.

Also includes two additional issues I noticed while reviewing/testing:

  • There was a duplicate error message being printed if something went wrong when running caddy list-modules or caddy version, just an oversight during the recent refactor.

  • Running os.Remove to cleanup the renamed backup binary actually fails on Windows, because that's a program trying to remove itself. It's possible to work around this by running cmd.exe /C del <file> which adds a layer of inversion so that it's actually a different process that deletes the file.

@francislavoie francislavoie added the under review 🧐 Review is pending before merging label Oct 16, 2021
@francislavoie francislavoie added this to the v2.4.6 milestone Oct 16, 2021
@francislavoie francislavoie requested a review from mholt October 16, 2021 05:39
@francislavoie francislavoie force-pushed the upgrade-cmd-fixes branch 4 times, most recently from a303a86 to 8ae6a24 Compare October 16, 2021 05:51
@francislavoie francislavoie force-pushed the upgrade-cmd-fixes branch 3 times, most recently from 26e5f51 to 21d1b96 Compare October 19, 2021 02:31
@francislavoie francislavoie added the feature ⚙️ New feature or request label Oct 20, 2021
This is a partial fix for #4057, making it possible to retain the old build of Caddy, in case something went wrong.
The error message "download succeeded, but unable to execute" was repeated, because it was both in the `listModules`/`showVersion` functions and in the calling `upgradeBuild` function. Oversight when this was refactored.
Without this, the cleanup operation would fail with an error message like this:

upgrade: download succeeded, but unable to clean up backup binary: remove C:\caddy\caddy.exe.tmp: Access is denied.
@mholt
Copy link
Member

mholt commented Nov 8, 2021

Hmm, what if we always left a backup file called caddy_old which could be disabled with --no-backup or something? The backup file was only intended for actual problems during the replacement of the binary, but maybe admins would want to keep the old version lying around in case the deployment failed and they had to roll back. (We used to do this automatically in v1, too, but I haven't gotten around to re-implementing it in v2.)

@francislavoie
Copy link
Member Author

francislavoie commented Nov 8, 2021

Hmm, I think it's best to clean up by default, because it's not so nice to leave things around in /usr/bin unless explicitly asked, I'd say. But I can see the argument both ways. Maybe if the backup by default was in /tmp or something. But bleh.

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Okay, that's fine. My only nit might be could we make the flag name a little clearer / more obvious? Maybe --keep-backup instead of --skip-cleanup.

cmd/removebinary_windows.go Outdated Show resolved Hide resolved
cmd/removebinary_nonwindows.go Outdated Show resolved Hide resolved
@francislavoie francislavoie changed the title caddycmd: Add --skip-cleanup to upgrade commands caddycmd: Add --keep-backup to upgrade commands Nov 8, 2021
@francislavoie francislavoie requested a review from mholt November 8, 2021 18:30
@mholt mholt removed the under review 🧐 Review is pending before merging label Nov 8, 2021
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

LGTM, thank you -- let's give this a try

@mholt mholt merged commit 749e55c into master Nov 8, 2021
@mholt mholt deleted the upgrade-cmd-fixes branch November 8, 2021 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants