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

Run a script before uninstall/upgrade (chocolateyBeforeModify.ps1) to allow for things like services to shutdown #268

Closed
ferventcoder opened this issue May 2, 2015 · 30 comments
Assignees
Milestone

Comments

@ferventcoder
Copy link
Member

ferventcoder commented May 2, 2015

Do not fail if it fails though.

Current proposed name: chocolateyBeforeRemove.ps1

Migrated the evolution of the ideas from chocolatey-archive/chocolatey#291

tl;dr - There is a before modify script. It runs in addition to your chocolateyInstall.ps1 during upgrades and in addition to your chocolateyUninstall.ps1 during uninstalls. See https://github.com/chocolatey/choco/wiki/CreatePackages#during-which-scenarios-will-my-custom-scripts-be-triggered

@ferventcoder ferventcoder added this to the 0.9.9.6 milestone May 2, 2015
@ferventcoder
Copy link
Member Author

This is for you @darrelmiller

@ferventcoder ferventcoder changed the title Run chocolateyRemove.ps1 before upgrade to allow for things like services to shutdown Run chocolateyBeforeRemove.ps1 before upgrade to allow for things like services to shutdown May 4, 2015
@ferventcoder ferventcoder changed the title Run chocolateyBeforeRemove.ps1 before upgrade to allow for things like services to shutdown Run chocolateyBeforeRemove.ps1 before uninstall/upgrade to allow for things like services to shutdown May 4, 2015
@darrelmiller
Copy link

Awesome. Will try it out soon!

@ferventcoder
Copy link
Member Author

This is only the ticket. A placeholder for the work. ;)

@darrelmiller
Copy link

Hehe. I guess I need to read more closely. Will wait with baited breath!

@ferventcoder ferventcoder modified the milestones: 0.9.9.6, 0.9.9.7 May 16, 2015
@mrdima
Copy link

mrdima commented Jun 4, 2015

Run chocolateyBeforeRemove.ps1 when you want to shut down a service before upgrade doesn't sound logical to me, I would expect a chocolateyBeforeUpgrade.ps1.
If you want to stop a service before uninstall, because for whatever reason the msi/exe uninstaller doesn't to that for you, can't you can just put that it in chocolateyUninstall.ps1 (which should always run before the auto-uninstaller if that's enabled)?

@ferventcoder
Copy link
Member Author

Before remove to signify it is run in upgrades and uninstalls - no reason to write tge same logic twice in your automation scripts.

@ferventcoder
Copy link
Member Author

Might need a better name but it needs to signify that by the name that it is done prior to the upgrade/uninstall action and that it is not a script meant for handling the upgrade, only preparing for an upgrade or uninstall.

@mrdima
Copy link

mrdima commented Jun 4, 2015

Any reason why you propose 1 script for both upgrade and uninstall? And if you do an uninstall what can be done extra in chocolateyBeforeUpgrade.ps1 what cannot be done in chocolateyUninstall.ps1?

@ferventcoder ferventcoder changed the title Run chocolateyBeforeRemove.ps1 before uninstall/upgrade to allow for things like services to shutdown Run a script before uninstall/upgrade to allow for things like services to shutdown Jun 4, 2015
@ferventcoder
Copy link
Member Author

Think of it like this - if you have a service running and you need to shut it down, you need to shut it down before ANY changes can be made.

So the uninstall script is still going to run on uninstalls, we are not replacing that.

Imagine for a second if you needed to shut down a service before upgrade or uninstall, and we only had a beforeUpgrade.ps1. So now you need to include the exact same logic TWICE in your scripts, once for upgrades and once for uninstalls. Now every time you need to adjust that logic, you have to remember to adjust it in both places. That would not be maintainable and not much fun. (Yes, I know you could dot source a function from another script, but most scripts self-contain all logic).

@mrdima
Copy link

mrdima commented Jun 4, 2015

Ok I get it. Would there be an option to know if you're running an upgrade or uninstall if there's things you only want to do during an upgrade? (I don't have a particular use-case at this moment, but I can imagine that you need to do something special only on upgrade)

@ferventcoder
Copy link
Member Author

Right now, the thought wasn't there, but it could easily be passed the action that was about to occur.

In some MSIs, folks want to uninstall before upgrading (mostly because some minor versions of MSIs don't always upgrade at all).

@ferventcoder ferventcoder modified the milestones: 0.9.9.7, 0.9.9.8 Jun 12, 2015
@ferventcoder ferventcoder modified the milestones: 0.9.9.8, 0.9.9.9 Jun 26, 2015
RichardJFoster pushed a commit to RichardJFoster/choco that referenced this issue Mar 10, 2016
This action will trigger the execution of chocolateyBeforeModify.ps1 if that script is present in the package.
RichardJFoster pushed a commit to RichardJFoster/choco that referenced this issue Mar 10, 2016
…thod.

If not null, this action should be triggered in an update scenario but
in the forseeable future the action will only be used by the
NugetService (from where it will be used to trigger execution of the
chocolateyBeforeModify script described in chocolateyGH-268).
RichardJFoster pushed a commit to RichardJFoster/choco that referenced this issue Mar 10, 2016
…kageService

This method is passed into the ISourceRunner instance's upgrade_run
as the beforeUpgradeAction. Only the NugetService currently uses it
to trigger execution of the pre-modification script.
RichardJFoster pushed a commit to RichardJFoster/choco that referenced this issue Mar 10, 2016
RichardJFoster pushed a commit to RichardJFoster/choco that referenced this issue Mar 10, 2016
ferventcoder pushed a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
…ecution.

While there appeared to be verification in the noop scenario, there did
not appear to be any verification in the regular case. These spec items
verify that the encapsulated package script was run by examining the
script output.
ferventcoder pushed a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
…ages.

If we are going to verify script execution, it needs to be included in
the test packages.
ferventcoder pushed a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
…ackage.

There were a several places with functionally identical code to locate
the installation folder for a package. When the new pre-modification
script gets added the same functionality will be needed again.
Refactored into a method to eliminate additional duplicate.
ferventcoder pushed a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
…rios.

These scenarios verify that chocolateyBeforeModify.ps1 is executed on
the correct package version when appropriate.
ferventcoder pushed a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
This action will trigger the execution of chocolateyBeforeModify.ps1 if that script is present in the package.
ferventcoder pushed a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
…thod.

If not null, this action should be triggered in an update scenario but
in the forseeable future the action will only be used by the
NugetService (from where it will be used to trigger execution of the
chocolateyBeforeModify script described in chocolateyGH-268).
ferventcoder pushed a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
…kageService

This method is passed into the ISourceRunner instance's upgrade_run
as the beforeUpgradeAction. Only the NugetService currently uses it
to trigger execution of the pre-modification script.
ferventcoder pushed a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
ferventcoder added a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
Ensure the folder is renamed prior to running before modify for the
package.
ferventcoder added a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
- Adding back in chocolateyGH-560 - loading modules from known location (90d53ee)
- Adding back in chocolateyGH-542 - not running templated scripts (d5f09bf)
ferventcoder added a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
A failure in the before modify script should report the error but not
do anything to stop the script from failing.
ferventcoder added a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
* pr531-modify:
  (chocolateyGH-268)(specs) BeforeModify failure is ignored
  (maint) remove comment
  (chocolateyGH-268) Revert removed fixes
  (chocolateyGH-268) Rename Legacy Prior to Before Modify
  (maint) formatting
  (chocolateyGH-268) Use MockLogger.contains_message in verification expressions.
  (chocolateyGH-268) Trigger beforeUpgradeAction from the NugetService.
  (chocolateyGH-268) Add before-package-upgrade method to ChocolateyPackageService
  (chocolateyGH-268) Add optional beforeUpgradeAction to upgrade_run method.
  (chocolateyGH-268) Add a before_modify action to the PowershellService
  (chocolateyGH-268)(spec) Added "before modify" integration test scenarios.
  (chocolateyGH-268) Extract method to provide folder information for package.
  (chocolateyGH-268) Add chocolateyBeforeModify.ps1 script to test packages.
  (chocolateyGH-268)(spec) Add scenarios verifying powershell script execution.
ferventcoder added a commit to ferventcoder/choco that referenced this issue Apr 9, 2016
* stable:
  (chocolateyGH-268)(specs) BeforeModify failure is ignored
  (maint) remove comment
  (chocolateyGH-268) Revert removed fixes
  (chocolateyGH-268) Rename Legacy Prior to Before Modify
  (maint) formatting
  (chocolateyGH-268) Use MockLogger.contains_message in verification expressions.
  (chocolateyGH-268) Trigger beforeUpgradeAction from the NugetService.
  (chocolateyGH-268) Add before-package-upgrade method to ChocolateyPackageService
  (chocolateyGH-268) Add optional beforeUpgradeAction to upgrade_run method.
  (chocolateyGH-268) Add a before_modify action to the PowershellService
  (chocolateyGH-268)(spec) Added "before modify" integration test scenarios.
  (chocolateyGH-268) Extract method to provide folder information for package.
  (chocolateyGH-268) Add chocolateyBeforeModify.ps1 script to test packages.
  (chocolateyGH-268)(spec) Add scenarios verifying powershell script execution.
ferventcoder added a commit to ferventcoder/choco that referenced this issue Apr 11, 2016
ferventcoder added a commit to ferventcoder/choco that referenced this issue Apr 11, 2016
With the move to finding the script in a singular function, the old
code no longer is used. Remove it.
ferventcoder added a commit to ferventcoder/choco that referenced this issue Apr 11, 2016
* stable:
  (chocolateyGH-268) Remove Unused Code
  (chocolateyGH-268) Add BeforeModify to install template
  (maint) solution folders for nuspecs / top level
  (maint) catch pack catastrophic errors
  (chocolateyGH-586) Ignore invalid options/switches by default
  (specs) update scenarios
  (chocolateyGH-596) Allow failure on invalid license
  (chocolateyGH-571) Arg parsing error should be warning
  (chocolateyGH-680) Switch to .NET Client Profile
@ferventcoder ferventcoder changed the title Run a script before uninstall/upgrade to allow for things like services to shutdown Run a script before uninstall/upgrade (chocolateyBeforeModify.ps1) to allow for things like services to shutdown Apr 11, 2016
@darrelmiller
Copy link

Really happy to see this feature. I have big plans for this :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants