mkevenaar / chocolatey-packages

My chocolatey packages
https://mkevenaar.github.io/chocolatey-packages/
Apache License 2.0
42 stars 66 forks source link

zabbix-agent updates broken on 6.4.x with cannot create a file that already exists error #206

Closed anthonysomerset closed 8 months ago

anthonysomerset commented 9 months ago

originally posted at https://github.com/zabbix/zabbix-agent-chocolatey/issues/34 before realising maintenance moved here

Expected Behavior

zabbix-agent upgrades should just work

Current Behavior

When i attempt to update zabbix-agent from older versions (confirmed 6.2.3 and 5.4.3) the upgrade fails with following error

Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): a

Extracting 64-bit C:\ProgramData\chocolatey\lib\zabbix-agent\tools\zabbix_agent-6.4.6-windows-amd64-openssl.zip to C:\Users\asomerset\AppData\Local\Temp\chocolatey\chocolatey\zabbix...
C:\Users\asomerset\AppData\Local\Temp\chocolatey\chocolatey\zabbix
Error installing Zabbix Agent
ERROR: Cannot create a file when that file already exists.

The upgrade of zabbix-agent was NOT successful.
Error while running 'C:\ProgramData\chocolatey\lib\zabbix-agent\tools\chocolateyInstall.ps1'.
 See log for details.

Current workarounds that work - and do not seem to be entirely consistent:

  1. Stop Zabbix Agent Service and redo upgrade
  2. Stop Zabbix Agent Service, Delete the Bin files in Program Files/Zabbix Agent and redo upgrade
  3. In some even weirder edge cases when bin files can't be deleted (locked by event viewer process no less), stop, service, rename them and then run the upgrade

Possible Solution

guessing the upgrade script can't overwrite files and/or needs to stop the service prior to upgrade

Steps to Reproduce (for bugs)

Have any older version of zabbix agent installed via choco (confirmed 6.2.3 and 5.4.3 from my own environment) - could not find/validate 6.4.4 or earlier within 6.4.x yet run choco upgrade zabbix-agent, accept the script prompt

Context

Can't Upgrade Zabbix agent without manual interventions, in an automated config management world this potentially breaks update management processes as a result

Your Environment

anthonysomerset commented 9 months ago

i can replicate this coming from 6.4.4 as well

anthonysomerset commented 9 months ago

same issue with 6.4.7

anthonysomerset commented 9 months ago

I think that this commit onwards brought the issues:

https://github.com/mkevenaar/chocolatey-packages/commit/175d1d81772859d1a2836c97a980cac1761f30dc

is the main culprit - before this it was using the zabbix-agent.install package to download and install the MSI version rather than attempting to download/extract the ZIP

I'd personally recommend reverting that specific change and let the install be managed via MSI - but i am saying that in the absence of other context for this change

anthonysomerset commented 8 months ago

actually on closer review, the issue isn't the diferent extract/install method - but the simple fact that the service isn't stopped if its detected - this was in the old package config script but not in this one - i fixed my PR #213 for this which just needs accepting if happy with the approach