javalockinghigh-availabilitykaraf

karaf - how to add environmental variable in system.properties file


I want to enable HA lock for Karaf. I would like to provide env variable value for some of the flag while enabling the lock. The flag which i need to update are as follows:
karaf.lock.jdbc.clustername karaf.lock.delay

I tired giving below entry in etc/system.properties file but karaf took it as empty string

karaf.lock.jdbc.clustername=${APP_CLUSTER_NAME}
karaf.lock.delay=${LOCK_REFRESH}

where APP_CLUSTER_NAME and LOCK_REFRESH are environmental variables.

Even i tried define them in the custom.properties file as below,

LOCK_REFRESH=${env:LOCK_REFRESH}

APP_CLUSTER_NAME=${env:APP_CLUSTER_NAME}

This also not worked for me!

Please help


Solution

  • There are couple of ways we can achieve this, what i did was,

    1) Exported EXTRA_JAVA_OPTS as,

    export EXTRA_JAVA_OPTS="$EXTRA_JAVA_OPTS -Dapp.name=myApp"
    

    then used the same in system.propeties file,

    karaf.lock.jdbc.clustername=${app.name}
    

    2) Even we can directly export the karaf varaible to EXTRA_JAVA_OPTS export EXTRA_JAVA_OPTS="$EXTRA_JAVA_OPTS -Dkaraf.lock.jdbc.clustername=myApp" //i have not tried, it should work