Feature to abort if chocolateyBeforeModify.ps1 fail
This is a feature request. This can be a breaking change.
According to https://github.com/chocolatey/choco/issues/268#issuecomment-120752274 it's designed not to fail the build in case the script is bad. However this rarely happens, and we can make use of --force in both choco upgrade and choco uninstall. Therefore, I propose that error in chocolateyBeforeModify.ps1 should fail the action, unless -f/--force is used.
This would be beneficial as it is useful to have all of the functionality related to cleanly preparing for an installation change in one place and being able to prevent the change if the environment isn't in the required state (and also being able to log appropriate and useful information as to why not).
The type of checks we perform before changing app files are:
- Waiting for services to stop
- Terminating processes that don't want to stop (!)
- Waiting for file-locks (e.g. From aggressive AV products) to be released
- Cleaning up resources installed outside of the Chocolatey lib directories
- Tidying up environment variables etc.
@FranklinYu here's the problem - chocolateyBeforeModify.ps1 comes from the INSTALLED (aka OLDER version) of the package. If it is bad or wrong, the only way to fix this is to manually remove the package (or the beforeModify). The idea of the beforeModify is to handle locking issues. Most things that require failure checks can be done in the chocolateyInstall.ps1 itself as it is also used for upgrade.
I disagree that --force should be used for overriding the use of beforeModify in these cases. Force has other destructive things it does and ignores.
I think we'd want a feature you can flip on if this is the desired behavior you want, and then a command line switch to flip it back off.
I think we'd want a feature you can flip on if this is the desired behavior you want, and then a command line switch to flip it back off.
Would it be acceptable for package maintainer (of community feed, of course) to tell user “you need to flip on this feature, and I won’t fix any issue caused by not enabling it”?
For corporation internal packages we are fine, because we can enforce our user to flip it on.
The big problem with chocolateyBeforeModify.ps1 is that you need to be a seer when creating a package. chocolateyBeforeModify.ps1 run from a a currently installing package, IMHO, would be more useful.
@bcurran3 That would be a breaking change. Breaking many existing packages. Unless we add yet another file without changing behavior of current chocolateyBeforeModify.ps1.
Completely understood. I'm all for a new script that runs before install of the current package. (chocolateyBeforeInstall.ps1? - yeah, this would need to be a new feature request.)
So yeah... +1 for this feature. I need to tell a service to stop before upgrading a particular package, then start after it's done.
@asheroto
You should look at this: https://chocolatey.org/packages/chocolatey-misc-helpers.extension
I made helper functions just for such purpose.
HELPERS: Start-CheckandStop - Checks for and stops a process if running. Creates variables to easily restart the process after a package upgrade. Useful for installers that fail if the program is running, i.e. KeePass, uTorrent, etc. or for stopping programs that automatically run after install, i.e. Skype, SuMo, Ellp, etc. as well as for programs that will stop running during an upgrade and then not return to a running state post upgrade, i.e. Plex Media Server, etc. Screenshot Start-CheckandThrow - Checks if a process is running and aborts installation/upgrade if so. Screenshot Start-WaitandStop - Starts a background process to stop a (foreground) process - quits after 5 minutes or after the process gets stopped. Useful to stop additional pop-up programs during installation. Screenshot Start-WaitandStopActual - (do not directly use) Called by Start-WaitandStop to make Start-WaitandStop simple to use. Test-Dependency - Provides a way to verify a dependency is installed. Does NOT check version. Returns True/False.