Search code examples
linuxkeycloak

How to set a startscript in Linux for Keycloak Quarkus up to Version 17 , 18 or 19 in systemctl


How to set a startscript in Linux for Keycloak Quarkus up to Version 17 , 18 or 19, in order to run KeyCloak as a daemon. Actually I am not searching for a KeyCloak Wildfly solution!

I allready found this solution:

./kc.sh start-dev > keycloak.stdout 2>&1 & echo "$!" > keycloak.pid

for starting KeyCloak with a PID

How can I build a startscript in systemctl format?

Thanks in advance.


Solution

  • The following configuration did the trick for me.

    1.) Configure keycloak using database: mysql first

    kc.sh build --db mysql
    

    2.) Insert environment variables to the corresponding keycloak user on your system

    KEYCLOAK_HOME=/opt/keycloak
    export PATH=$PATH:$KEYCLOAK_HOME/bin
    
    

    3.) Create a systemd start-stop-script in: /usr/lib/systemd/system named: keycloak.service for example.

    [Unit]
    Description=keycloak service
    After=network.service
    
    [Service]
    ExecStart=/opt/keycloak/bin/kc.sh start
    PIDFile=/var/run/keycloak.pid
    
    [Install]
    WantedBy=multi-user.target
    
    

    ExecStart defines your fullpath to the kc.sh script.

    Running: systemctl daemon-reload to enable the new startscript

    After this you can start/stop keycloak by Quarkus up from version 17 like charme with:

    systemctl start keycloak