Skip to content

Commit

Permalink
Upgrade to Karaf 4.3.1 (openhab#1273)
Browse files Browse the repository at this point in the history
* Upgrades Karaf to 4.3.1
* Use Pax Logging as runtime dependency instead of Felix Log
  This dependency change makes the Demo App behave more like the actual distro.
  It also allows for using a single log4j2.xml which simplifies the logging config and makes it more like the distro.
  Fixes some noisy Pax Web commons-logging in the Demo App that would occur when using Felix Log.

The Log4j2 Demo App configuration is now very similar to that of the distro except for:

* Karaf specific logger configuration has been removed
* A commented example logger for a binding is added to help with debug logging

To allow for reconfiguring Log4j2 without making changes some enviroment variables can be used:

* The default root/openhab logger level can be overriden
* Several logger level/names can be reconfigured similarly

Fixes openhab#1167

Signed-off-by: Wouter Born <[email protected]>
  • Loading branch information
wborn authored Apr 2, 2021
1 parent 1feb266 commit 5969384
Show file tree
Hide file tree
Showing 17 changed files with 206 additions and 195 deletions.
7 changes: 0 additions & 7 deletions distributions/openhab-verify/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
<version>${karaf.version}</version>
<type>kar</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<!-- This should have been an optional dependency and will be fixed in Karaf 4.2.8 (KARAF-6462). -->
<groupId>org.knopflerfish.kf6</groupId>
<artifactId>log-API</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
7 changes: 0 additions & 7 deletions distributions/openhab/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
<artifactId>framework</artifactId>
<version>${karaf.version}</version>
<type>kar</type>
<exclusions>
<exclusion>
<!-- This should have been an optional dependency and will be fixed in Karaf 4.2.8 (KARAF-6462). -->
<groupId>org.knopflerfish.kf6</groupId>
<artifactId>log-API</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ featuresBootAsynchronous=false
#
configCfgStore=false

#
# Define if the feature service automatically refresh bundles
#
#autoRefresh=true

#
# Configuration of features processing mechanism (overrides, blacklisting, modification of features)
# XML file defines instructions related to features processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ org.ops4j.pax.url.mvn.localRepository=${openhab.userdata}/tmp/mvn

#
# Default this to false. It's just weird to use undocumented repos
# "false" means that http://repo1.maven.org/maven2@id=central won't be
# "false" means that https://repo1.maven.org/maven2@id=central won't be
# implicitly used as remote repository
#
org.ops4j.pax.url.mvn.useFallbackRepositories=false
Expand All @@ -49,7 +49,7 @@ org.ops4j.pax.url.mvn.useFallbackRepositories=false
# Those repositories will be checked before iterating through the
# below list of repositories and even before the local repository
# A repository url can be appended with zero or more of the following flags:
# @snapshots : the repository contains snaphots
# @snapshots : the repository contains snapshots
# @noreleases : the repository does not contain any released artifacts
#
# The following property value will add the system folder as a repo.
Expand All @@ -76,9 +76,8 @@ org.ops4j.pax.url.mvn.defaultRepositories=\
# profiles defined in effective settings.xml file will be _appended_ to this
# list
# The default list includes the following repositories:
# http://repo1.maven.org/maven2@id=central
# http://repository.apache.org/content/groups/snapshots-group@id=apache@snapshots@noreleases
# https://oss.sonatype.org/content/repositories/snapshots@id=sonatype.snapshots.deploy@snapshots@noreleases
# https://repo1.maven.org/maven2@id=central
# https://repository.apache.org/content/groups/snapshots-group@id=apache@snapshots@noreleases
# https://oss.sonatype.org/content/repositories/ops4j-snapshots@id=ops4j.sonatype.snapshots.deploy@snapshots@noreleases
# A repository url can be appended with zero or more of the following flags:
# @snapshots : the repository contains snapshots
Expand Down
25 changes: 14 additions & 11 deletions distributions/openhab/src/main/resources/bin/karaf
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ LOCAL_CLASSPATH=$CLASSPATH
#
# Sourcing environment settings for karaf similar to tomcats setenv
#
KARAF_SCRIPT="${PROGNAME}"
export KARAF_SCRIPT
if [ "x${KARAF_SCRIPT}" = "x" ]; then
KARAF_SCRIPT="${PROGNAME}"
export KARAF_SCRIPT
fi
if [ -f "${DIRNAME}/setenv" ]; then
. "${DIRNAME}/setenv"
fi
Expand Down Expand Up @@ -197,10 +199,6 @@ run() {
nodebug=false
while [ "${1}" != "" ]; do
case "${1}" in
'clean')
rm -rf "${KARAF_DATA:?}"
shift
;;
'debug')
debug=true
shift
Expand All @@ -219,6 +217,10 @@ run() {
'stop')
MAIN=org.apache.karaf.main.Stop
CHECK_ROOT_INSTANCE_RUNNING=false
# not needed when stopping
JAVA_OPTS=
KARAF_SYSTEM_OPTS=
KARAF_OPTS=
nodebug=true
shift
;;
Expand Down Expand Up @@ -268,12 +270,9 @@ run() {
fi
fi
JAVA_OPTS="${JAVA_DEBUG_OPTS} ${JAVA_OPTS}"

### START openHAB customization
else
JAVA_OPTS="${JAVA_NON_DEBUG_OPTS} ${JAVA_OPTS}"
fi
### END openHAB customization

while true; do
# When users want to update the lib version of, they just need to create
Expand Down Expand Up @@ -302,8 +301,8 @@ run() {
${KARAF_EXEC} "${JAVA}" ${JAVA_OPTS} \
--add-reads=java.xml=java.logging \
--add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED \
--patch-module "java.base=${KARAF_HOME}/lib/endorsed/org.apache.karaf.specs.locator-4.2.7.jar" \
--patch-module "java.xml=${KARAF_HOME}/lib/endorsed/org.apache.karaf.specs.java.xml-4.2.7.jar" \
--patch-module "java.base=${KARAF_HOME}/lib/endorsed/org.apache.karaf.specs.locator-4.3.1.jar" \
--patch-module "java.xml=${KARAF_HOME}/lib/endorsed/org.apache.karaf.specs.java.xml-4.3.1.jar" \
--add-opens java.base/java.security=ALL-UNNAMED \
--add-opens java.base/java.net=ALL-UNNAMED \
--add-opens java.base/java.lang=ALL-UNNAMED \
Expand All @@ -315,11 +314,15 @@ run() {
--add-opens java.base/java.text=ALL-UNNAMED \
--add-opens java.base/java.time=ALL-UNNAMED \
--add-opens java.desktop/java.awt.font=ALL-UNNAMED \
--add-exports=java.base/sun.net.www.protocol.file=ALL-UNNAMED \
--add-exports=java.base/sun.net.www.protocol.ftp=ALL-UNNAMED \
--add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED \
--add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED \
--add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED \
--add-exports=java.base/sun.net.www.content.text=ALL-UNNAMED \
--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED \
--add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED \
--add-exports java.security.sasl/com.sun.security.sasl=ALL-UNNAMED \
-Dkaraf.instances="${KARAF_DATA}/tmp/instances" \
-Dkaraf.home="${KARAF_HOME}" \
-Dkaraf.base="${KARAF_BASE}" \
Expand Down
49 changes: 15 additions & 34 deletions distributions/openhab/src/main/resources/bin/karaf.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ set PROGNAME=%~nx0%
set ARGS=%*

rem Sourcing environment settings for karaf similar to tomcats setenv
SET KARAF_SCRIPT="karaf.bat"

if "%KARAF_SCRIPT%" == "" (
SET KARAF_SCRIPT="karaf.bat"
)
if exist "%DIRNAME%setenv.bat" (
call "%DIRNAME%setenv.bat"
)
Expand All @@ -37,14 +40,6 @@ if not "%KARAF_TITLE%" == "" (
title Karaf
)

rem Check/Set up some easily accessible MIN/MAX params for JVM mem usage
if "%JAVA_MIN_MEM%" == "" (
set JAVA_MIN_MEM=128M
)
if "%JAVA_MAX_MEM%" == "" (
set JAVA_MAX_MEM=512M
)

goto BEGIN

:warn
Expand Down Expand Up @@ -96,7 +91,6 @@ if "%KARAF_ETC%" == "" (
)

set LOCAL_CLASSPATH=%CLASSPATH%
set JAVA_MODE=-server

set CLASSPATH=%LOCAL_CLASSPATH%;%KARAF_BASE%\conf
set DEFAULT_JAVA_DEBUG_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
Expand Down Expand Up @@ -249,18 +243,9 @@ if not exist "%JAVA_HOME%\bin\server\jvm.dll" (
echo WARNING: Running Karaf on a Java HotSpot Client VM because server-mode is not available.
echo Install Java Developer Kit to fix this.
echo For more details see http://java.sun.com/products/hotspot/whitepaper.html#client
set JAVA_MODE=-client
)
)
set DEFAULT_JAVA_OPTS=%JAVA_MODE% -Xms%JAVA_MIN_MEM% -Xmx%JAVA_MAX_MEM% -Dcom.sun.management.jmxremote -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass

rem Check some easily accessible MIN/MAX params for JVM mem usage
if not "%JAVA_PERM_MEM%" == "" (
set DEFAULT_JAVA_OPTS=%DEFAULT_JAVA_OPTS% -XX:PermSize=%JAVA_PERM_MEM%
)
if not "%JAVA_MAX_PERM_MEM%" == "" (
set DEFAULT_JAVA_OPTS=%DEFAULT_JAVA_OPTS% -XX:MaxPermSize=%JAVA_MAX_PERM_MEM%
)
set DEFAULT_JAVA_OPTS=-XX:+UnlockDiagnosticVMOptions

if "%JAVA_OPTS%" == "" set JAVA_OPTS=%DEFAULT_JAVA_OPTS%

Expand Down Expand Up @@ -330,14 +315,17 @@ if "%KARAF_PROFILER%" == "" goto :RUN
if "%1" == "run" goto :EXECUTE_RUN
if "%1" == "daemon" goto :EXECUTE_DAEMON
if "%1" == "client" goto :EXECUTE_CLIENT
if "%1" == "clean" goto :EXECUTE_CLEAN
if "%1" == "debug" goto :EXECUTE_DEBUG
if "%1" == "debugs" goto :EXECUTE_DEBUGS
goto :EXECUTE

:EXECUTE_STOP
SET MAIN=org.apache.karaf.main.Stop
SET CHECK_ROOT_INSTANCE_RUNNING=false
rem not needed when stopping
SET JAVA_OPTS=
SET KARAF_SYSTEM_OPTS=
SET KARAF_OPTS=
shift
goto :RUN_LOOP

Expand Down Expand Up @@ -374,26 +362,17 @@ if "%KARAF_PROFILER%" == "" goto :RUN
shift
goto :RUN_LOOP

:EXECUTE_CLEAN
pushd "%KARAF_DATA%" && (rmdir /S /Q "%KARAF_DATA%" 2>nul & popd)
shift
goto :RUN_LOOP

:EXECUTE_DEBUG
if "%JAVA_DEBUG_OPTS%" == "" set JAVA_DEBUG_OPTS=%DEFAULT_JAVA_DEBUG_OPTS%
set JAVA_OPTS=%JAVA_DEBUG_OPTS% %JAVA_OPTS%
rem START openHAB customization
set DEBUG=true
rem END openHAB customization
shift
goto :RUN_LOOP

:EXECUTE_DEBUGS
if "%JAVA_DEBUG_OPTS%" == "" set JAVA_DEBUG_OPTS=%DEFAULT_JAVA_DEBUGS_OPTS%
set JAVA_OPTS=%JAVA_DEBUG_OPTS% %JAVA_OPTS%
rem START openHAB customization
set DEBUG=true
rem END openHAB customization
shift
goto :RUN_LOOP

Expand All @@ -402,9 +381,7 @@ if "%KARAF_PROFILER%" == "" goto :RUN
rem Execute the Java Virtual Machine
cd "%KARAF_BASE%"

rem START openHAB customization
if not "%DEBUG%" == "true" set JAVA_OPTS=%JAVA_NON_DEBUG_OPTS% %JAVA_OPTS%
rem END openHAB customization

rem When users want to update the lib version of, they just need to create
rem a lib.next directory and on the new restart, it will replace the current lib directory.
Expand All @@ -430,8 +407,8 @@ if "%KARAF_PROFILER%" == "" goto :RUN
"%JAVA%" %JAVA_OPTS% %OPTS% ^
--add-reads=java.xml=java.logging ^
--add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED ^
--patch-module "java.base=%KARAF_HOME%/lib/endorsed/org.apache.karaf.specs.locator-4.2.7.jar" ^
--patch-module "java.xml=%KARAF_HOME%/lib/endorsed/org.apache.karaf.specs.java.xml-4.2.7.jar" ^
--patch-module "java.base=%KARAF_HOME%/lib/endorsed/org.apache.karaf.specs.locator-4.3.1.jar" ^
--patch-module "java.xml=%KARAF_HOME%/lib/endorsed/org.apache.karaf.specs.java.xml-4.3.1.jar" ^
--add-opens java.base/java.security=ALL-UNNAMED ^
--add-opens java.base/java.net=ALL-UNNAMED ^
--add-opens java.base/java.lang=ALL-UNNAMED ^
Expand All @@ -443,11 +420,15 @@ if "%KARAF_PROFILER%" == "" goto :RUN
--add-opens java.base/java.text=ALL-UNNAMED ^
--add-opens java.base/java.time=ALL-UNNAMED ^
--add-opens java.desktop/java.awt.font=ALL-UNNAMED ^
--add-exports=java.base/sun.net.www.protocol.file=ALL-UNNAMED ^
--add-exports=java.base/sun.net.www.protocol.ftp=ALL-UNNAMED ^
--add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED ^
--add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED ^
--add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED ^
--add-exports=java.base/sun.net.www.content.text=ALL-UNNAMED ^
--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED ^
--add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED ^
--add-exports java.security.sasl/com.sun.security.sasl=ALL-UNNAMED ^
-classpath "%CLASSPATH%" ^
-Dkaraf.instances="%OPENHAB_USERDATA%\tmp\instances" ^
-Dkaraf.home="%KARAF_HOME%" ^
Expand Down
6 changes: 2 additions & 4 deletions distributions/openhab/src/main/resources/bin/setenv
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
# karaf scripts
#
# export JAVA_HOME # Location of Java installation
# export JAVA_MIN_MEM # Minimum memory for the JVM
# export JAVA_MAX_MEM # Maximum memory for the JVM
# export JAVA_PERM_MEM # Minimum perm memory for the JVM
# export JAVA_MAX_PERM_MEM # Maximum perm memory for the JVM
# export JAVA_OPTS # Generic JVM options, for instance, where you can pass the memory configuration
# export JAVA_NON_DEBUG_OPTS # Additional non-debug JVM options
# export EXTRA_JAVA_OPTS # Additional JVM options
# export KARAF_HOME # Karaf home folder
# export KARAF_DATA # Karaf data folder
Expand Down
12 changes: 4 additions & 8 deletions distributions/openhab/src/main/resources/bin/setenv.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@ rem Window name of the windows console
rem SET KARAF_TITLE
rem Location of Java installation
rem SET JAVA_HOME
rem Minimum memory for the JVM
rem SET JAVA_MIN_MEM
rem Maximum memory for the JVM
rem SET JAVA_MAX_MEM
rem Minimum perm memory for the JVM
rem SET JAVA_PERM_MEM
rem Maximum perm memory for the JVM
rem SET JAVA_MAX_PERM_MEM
rem Generic JVM options (for instance, where you can provide memory configuration)
rem SET JAVA_OPTS
rem Additional JVM options
rem SET JAVA_NON_DEBUG_OPTS
rem Additional non-debug JVM options
rem SET EXTRA_JAVA_OPTS
rem Karaf home folder
rem SET KARAF_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,23 @@ sshRealm = karaf
sftpEnabled=true

#
# The location of the hostKey file defines where the private/public key of the server
# The location of the hostKey file defines where the private key of the server
# is located. If no file is at the defined location it will be ignored.
#
hostKey = ${karaf.etc}/host.key

#
# The format used for hostKey.
# Possible values are simple (Karaf internal), or PEM (OpenSSH format)
# The password required to decrypt the private key of the server stored in
# 'hostKey'. This is not required if the private key stored in 'hostKey' is
# not encrypted
#
hostKeyFormat = simple
#hostKeyPassword =

#
# The location of the hostKeyPub file defines where the public key of the server
# is located. If no file is at the defined location it will be ignored.
#
#hostKeyPub = ${karaf.etc}/host.key.pub

#
# Self defined key size in 1024, 2048, 3072, or 4096
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ help = { *:help $args | more } ;
man = { help $args } ;
log:list = { log:get ALL } ;
service:get = { $.context getService ($.context getServiceReference $args) };
feature:upgrade = { feature:install -u $args } ;

env = { shell:set $args }
edit = { shell:nano $args }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
# with the name "karaf".
#
openhab = habopen,_g_:admingroup
_g_\:admingroup = group,admin,manager,viewer,systembundles
_g_\:admingroup = group,admin,manager,viewer,systembundles
Loading

0 comments on commit 5969384

Please sign in to comment.