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

Add support for (un)install hooks #11

Merged
merged 3 commits into from
Mar 6, 2017

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Feb 25, 2017

Fixes #2

This PR allows users to add (un)install hooks like the following in their wix.json file:

  "hooks": [
      {"command": "sc.exe create ServiceName binPath=\"[INSTALLDIR]myexec.exe\" type=share start=auto DisplayName=\"Service Description\"", "when": "install"},
      {"command": "sc.exe start ServiceName", "when": "install"},
      {"command": "sc.exe stop ServiceName", "when": "uninstall"},
      {"command": "sc.exe delete ServiceName", "when": "uninstall"}
  ]

(which, BTW, is a workaround for #9 until services are supported directly)

It doesn't (yet) provide any magic for executing batch files directly (i.e. the user needs to invoke cmd.exe) but it should be easy to extend the code creating CookedCommand.

@mh-cbon
Copy link
Owner

mh-cbon commented Feb 25, 2017

Hi!

awesome thanks! LGTM. I ll check this and load that.

TBD:

  • check RemoveExistingProducts
  • add tests

@2opremio
Copy link
Contributor Author

No problem, I may also tackle #9 if I find the time tomorrow.

  • check RemoveExistingProducts

Out of curiosity, what's there to check?

@2opremio
Copy link
Contributor Author

I have updated the PR so that hooks are run with elevated privileges.

@2opremio
Copy link
Contributor Author

It doesn't (yet) provide any magic for executing batch files directly (i.e. the user needs to invoke cmd.exe) but it should be easy to extend the code creating CookedCommand.

Actually, it doesn't need any magic, windows runs the bat files directly due to the special meaning it gives to extensions.

@2opremio
Copy link
Contributor Author

I have made one last change to make sure uninstall hooks run before files are removed

@mh-cbon mh-cbon merged commit 479ca0b into mh-cbon:master Mar 6, 2017
@mh-cbon
Copy link
Owner

mh-cbon commented Mar 6, 2017

Hi,

I merged and tried to validate your changes, but for me it won t work.

See the testing here https://github.com/mh-cbon/go-msi/blob/master/testing/hello/wix.json#L40

When i msi install, it triggers an error code 1603, it also indicates a windows event ID 11708.

I also tried to change the command to something like echo $null >> file (like a touch),
but it would not work either with the same error code.

I m not sure what s wrong here, i have not tried to dig the wix documentation.

@mh-cbon
Copy link
Owner

mh-cbon commented Mar 6, 2017

@2opremio 2opremio deleted the 2-(un)install-hooks branch March 7, 2017 07:53
@2opremio
Copy link
Contributor Author

2opremio commented Mar 7, 2017

Interesting, it works for me without problems.

When i msi install, it triggers an error code 1603, it also indicates a windows event ID 11708.

Can you get the full logs of the installation?

msiexec /i MyApplication.msi /log MyLogFile.txt

@2opremio
Copy link
Contributor Author

2opremio commented Mar 7, 2017

Oh, is hello.exe a service? Otherwise I think this command will fail: https://github.com/mh-cbon/go-msi/blob/master/testing/hello/wix.json#L42 .

Did you try it in the command line?

The hooks check the status code of the command so, if the command fails, the installer will fail.

Also echo $null >> file is a shell command, not a valid executable AFAIK (it should work if you include it in a batch file though).

@mh-cbon
Copy link
Owner

mh-cbon commented Mar 7, 2017

hi,

great! It works now : )

Though i think i ran into one problem which is not handled,
somehow at some point, the msi installed, but failed to complete.
As a result the service was installed and existing,
but it would not start.
Also, and that s important, the program could not be uninstalled from
Control panel > programs > uninstall

As a result for the end user,
the app did not install: Fail
the app will always fail to re install because
the service already exist, thus the installer will fail
when it tries to install the service again.
The system complaining that the service
already exists.

Is it possible to ensure the configuration
of the system when an error prevent completion
of the msi install command ?

@mh-cbon
Copy link
Owner

mh-cbon commented Mar 7, 2017

Another problem i run into is about uninstall.

The msi installed with success,
the service is started and running 👍

But, on uninstall, via
control panel > programs > uninstall
when the installer is started to show the gui,
it will prompt the user with a message
to require to close some applications,
specifically Hello program.
It provides two options,
one is to stop the app, and try to restart it later,
after completion of the current uninstall command.
Or to simply ignore it and continue.

It will work only if the user chooses to ignore
the message and continue anyway.

I m not sure if it is something the hooks
can resolve.

@mh-cbon
Copy link
Owner

mh-cbon commented Mar 7, 2017

Finally, i got it working!

When uninstalling the program via
the command line msiexec /x,
it would fail.

The reason is about the uninstall
hook {"when": "uninstall", "command": "sc.exe stop HelloSvc"}

For some reasons, it returns errors such as
the service was not started, despite i could see it into
the service manager, up and running.

I finally simply removed it,
kept only the delete command,
and now it works : )

@mh-cbon mh-cbon mentioned this pull request Mar 7, 2017
@2opremio
Copy link
Contributor Author

2opremio commented Mar 7, 2017

the service already exist, thus the installer will fail
when it tries to install the service again.

The problem in the case is that the hooks are not robust enough. I ended up using a batch file which takes care of all these situations and rollbacks all actions if anything fails.

on uninstall, via
control panel > programs > uninstall
when the installer is started to show the gui,
it will prompt the user with a message
to require to close some applications,

This PR only implements hooks as a general mechanism. Using them for services is kinda hackish for the reasons above.

It would still make sense to implement #9

@mh-cbon mh-cbon mentioned this pull request Mar 7, 2017
@2opremio
Copy link
Contributor Author

2opremio commented Mar 7, 2017

As a follow-up, it may be worth providing more granularity in the hooks.

Now we only have "install" (which is really post-install) and "uninstall" (which is really pre-uninstall).

We could potentially add all {pre,post}-install and {pre,post}-uninstall

@2opremio
Copy link
Contributor Author

2opremio commented Mar 7, 2017

On top of that, we could tell the installer to use in-memory batch files (now you need to copy them with your installation files). I think there's a tag for that in wix.

@mh-cbon
Copy link
Owner

mh-cbon commented Mar 7, 2017

Can you expansively describe how that would look like and the possibilities ?

Now we only have "install" (which is really post-install) and "uninstall" (which is really pre-uninstall).

We could potentially add all {pre,post}-install and {pre,post}-uninstall

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

Successfully merging this pull request may close these issues.

2 participants