2

Is it possible to restart a Java application Service with install4j ?

I need to change some configurations in the application and then restart it in unattended mode using the api. (Not doing the complete install or update)

I found this answer that would work if the application is not a service: https://stackoverflow.com/a/65777281/150566 I tried to do the same thing using a Custom Application but using Service call like this:

enter image description here

I've also tried without the request privileges and without sleep with same result or using the stop service commandHalf of it works. The service stops but the Service never restart.

Is there something missing so that the service can start again ? Is there other alternative ?


Updated info: The config is changed as mentioned to stop the service instead of ShutDown calling launcher: enter image description here

When using debug as mentioned by Ingo Kegel those output are the result:

Called from mylauncher Service with the Api (not working):

[INFO] com.install4j.runtime.beans.actions.services.StopServiceAction [ID 147]: Execute action
       Property executable: null
       Property launcherId: 36
       Property serviceName: null
       Property windowsStopMinimumWaitTime: 30000
       Property rollbackSupported: true
       usedExecutable: C:\MyInstaller\mylauncher.exe
       Stop minimum wait time: 30000

Called from command line (working):

[INFO] com.install4j.runtime.beans.actions.services.StopServiceAction [ID 147]: Execute action
       Property executable: null
       Property launcherId: 36
       Property serviceName: null
       Property windowsStopMinimumWaitTime: 30000
       Property rollbackSupported: true
       usedExecutable: C:\MyInstaller\mylauncher.exe
       Stop minimum wait time: 30000
       previous state true
       Execute action successful after 519 ms
[INFO] com.install4j.runtime.beans.actions.services.StartServiceAction [ID 148]: Execute action
       Property executable: null
       Property launcherId: 36
       Property serviceName: null
       Property autostartOnly: false
       Property rollbackSupported: true
       usedExecutable: C:\MyInstaller\mylauncher.exe
       previous state false
       Execute action successful after 44 ms
[INFO] com.install4j.runtime.beans.screens.StartupScreen [ID 131]: command: move 1 screens, executing actions, checking condition
[INFO] cleaning up
[INFO] Finished at 2023-02-06 15:06:06

(I've also tried without the request privileges and without sleep with same result or using the stop service command)

Mike
  • 2,354
  • 3
  • 23
  • 37

1 Answers1

0

Instead of "Shutdown calling launcher" you need the "Stop a service" action. Also, for unattended mode, you don't need the "Finish" screen, you can add all actions to the "Startup" node.

To check if there is a problem, start the executable of the custom application from the command line with the argument -Dinstall4j.log=<path to writable log file.txt> and check the log file.

Ingo Kegel
  • 46,523
  • 10
  • 71
  • 102
  • Thanks, I updated my project as suggested and it still don't work. (See my updated post for new information). When I run in command line the restart works. It ask for admin privileges and then perform the restart. When it's being called in the service with ApplicationLauncher.launchApplicationInProcess it doesn't work. It seems to get stuck in the stop (see log) even though the service really stopped. I tried to add the Request Privileges action at the beginning but it still don't work. – Mike Feb 06 '23 at 20:25
  • You cannot shut down the service from within the service itself. This is what happen if you use `ApplicationLauncher.launchApplicationInProcess`. You have to use `ApplicationLauncher.launchApplication` instead to create a new process. – Ingo Kegel Feb 07 '23 at 06:55
  • 1
    That's what was missing. Now it works. Thanks a lot. When should I use the InProcess vs the other ? If I run the StandAlone update downloader in unattended mode should it be called with InProcess or without ? I was using inProcess and it was working, But now I'm not sure if I should change it. Thanks. – Mike Feb 07 '23 at 14:01
  • In the standalone updater `launchApplicationInProcess` will work with the "Shutdown calling launcher" action, but not with the "Stop a service" action. – Ingo Kegel Feb 07 '23 at 23:02