Execute script on keycloak restart

Hi, I am using keycloak 18, and i need to execute an script that deletes a .jar file in /deployments.

I have tried placing the script in /opt/jboss/startup-scripts but it isnt working, i have tried executing the script manually and is working as expected so that is not the problem.

Is there any other way to execute an script when i restart keycloak?

Thanks

Keycloak doesn’t support executing scripts at startup (any more).
If you would like to execute custom scripts, you’ll have to implement your custom entrypoint script, do your work and call the original script afterwards.

1 Like

So, for example, you would package a script like this:

#!/bin/bash

# Wrapper script as docker entrypoint. Do your custom thing here
# or call another script from this one.

# Now run the included kc.sh script with the arguments given.
RUN_OPTS="$@"
echo "About to run Keycloak with $RUN_OPTS"
/opt/keycloak/bin/kc.sh $RUN_OPTS

in your Dockerfile with these additions:

COPY ./my-kc.sh /opt/keycloak/bin/
ENTRYPOINT ["/opt/keycloak/bin/my-kc.sh" ]
1 Like