Search code examples
servicewindows-serviceswildflykeycloak

How can I install Keycloak as a service, so it starts automatically?


I have installed WildFly 10.0 as a service, I ran the service.bat file, but I need Keycloak as service too. If I run Keycloak's service.bat file it says:

ERROR: Service WildFly already exists.

My Keycloak version is 3.3.0, so basically the service of Keycloak wants to install WildFly as service, or I don't understand.


Solution

  • I found a solutions with the NSSM - the Non-Sucking Service Manager

    It's only 324 KB in size, really simple and efficient. Most importantly, it requires no installation and does not depend on components such as .NET. So it is easy to distribute/pack with your software and even if it is outdated, it works with all current Windows versions.

    install.bat

    nssm.exe install "Keycloak" "keycloak/run.bat"
    nssm.exe set "Keycloak" AppDirectory "keycloak/"
    nssm.exe set "Keycloak" Description "Keycloak Identity and Access Management"
    

    I use a separated run.bat, if parameters change (as they have in the past keycloak releases) I can modify the run.bat instead of reinstalling the service.

    keycloak/run.bat

    bin/kc.bat --config-file "../conf/keycloak.conf" start --optimized
    

    conf/keycloak.conf

    http-port=6060
    ...