Search code examples
install4j

Restart Application Service with install4j


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)


Solution

  • 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.