Skip to content

Commit 0cebdfd

Browse files
refactor(distrib): Unified start script (#6052)
* Now kura starts by default in debug mode * Unified start scripts * added missing doc * revemod deprecated options
1 parent d3ac2b4 commit 0cebdfd

File tree

5 files changed

+108
-133
lines changed

5 files changed

+108
-133
lines changed
Lines changed: 101 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,112 @@
1-
#!/bin/sh
2-
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2025 Eurotech and/or its affiliates and others
4+
#
5+
# This program and the accompanying materials are made
6+
# available under the terms of the Eclipse Public License 2.0
7+
# which is available at https://www.eclipse.org/legal/epl-2.0/
8+
#
9+
# SPDX-License-Identifier: EPL-2.0
10+
#
11+
# Contributors:
12+
# Eurotech
13+
#
14+
# Kura should be installed to the \${kura.install.dir} directory.
315
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/opt/jvm/bin:/usr/java/bin:$PATH
416
export MALLOC_ARENA_MAX=1
517

18+
KURA_RUNNING=$(pgrep -f ".*java.*org\.eclipse\.equinox\..*")
19+
20+
if [ -n "$KURA_RUNNING" ] ; then
21+
echo "Failed to start Kura. It is already running ..."
22+
exit 1
23+
fi
24+
625
DIR=$(cd $(dirname $0)/..; pwd)
7-
cd $DIR
26+
cd "$DIR" || exit 1
27+
28+
IS_DEBUG_MODE="false"
29+
IS_DETACHED_MODE="false"
30+
31+
while [[ $# -gt 0 ]]; do
32+
key="$1"
33+
34+
case $key in
35+
-d | --detached)
36+
IS_DETACHED_MODE="true"
37+
;;
38+
-x | --debug)
39+
IS_DEBUG_MODE="true"
40+
;;
41+
-h | --help)
42+
echo
43+
echo "Options:"
44+
echo " -d | --detached run Kura in detached mode"
45+
echo " -x | --debug run Kura in debug mode"
46+
exit 0
47+
;;
48+
*)
49+
echo "Unknown option."
50+
exit 1
51+
;;
52+
esac
53+
shift # past argument or value
54+
done
855

956
# set up the configuration area
1057
mkdir -p /tmp/.kura/configuration
1158
\${DIR}/bin/gen_config_ini.sh \${DIR}/framework/config.ini \${DIR}/plugins > /tmp/.kura/configuration/config.ini
1259

13-
KURA_RUNNING=`ps ax | grep java | grep "org.eclipse.equinox"`
14-
15-
if [ -z "$KURA_RUNNING" ] ; then
16-
exec java -Xms${kura.mem.size} -Xmx${kura.mem.size} \
17-
-XX:+IgnoreUnrecognizedVMOptions \
18-
--add-opens java.base/java.lang=ALL-UNNAMED \
19-
--add-opens java.base/java.util=ALL-UNNAMED \
20-
--add-modules=ALL-SYSTEM \
21-
-Dkura.os.version=${kura.os.version} \
22-
-Dkura.arch=${kura.arch} \
23-
-Dtarget.device=${target.device} \
24-
-Dorg.eclipse.kura.core.crypto.secretKey="$KURA_CRYPTO_SECRET_KEY" \
25-
-Declipse.ignoreApp=true \
26-
-Dkura.home=\${DIR} \
27-
-Dkura.configuration=file:\${DIR}/framework/kura.properties \
28-
-Dkura.custom.configuration=file:\${DIR}/user/kura_custom.properties \
29-
-Ddpa.configuration=\${DIR}/packages/dpa.properties \
30-
-Dlog4j.configurationFile=file:\${DIR}/log4j/log4j.xml \
31-
-Dlog4j2.disable.jmx=true \
32-
-Djava.security.policy=\${DIR}/framework/jdk.dio.policy \
33-
-Djdk.dio.registry=\${DIR}/framework/jdk.dio.properties \
34-
-Djdk.tls.trustNameService=true \
35-
-Dosgi.console \
36-
-Declipse.consoleLog=true \
37-
-jar \${DIR}/plugins/org.eclipse.equinox.launcher-${org.eclipse.equinox.launcher.version}.jar \
38-
-configuration /tmp/.kura/configuration
60+
if [[ -n "${KURA_DEBUG_MODE}" && "${KURA_DEBUG_MODE}" == "true" ]]; then
61+
IS_DEBUG_MODE="true"
62+
fi
63+
64+
DEBUG_OPTS=""
65+
if [[ $IS_DEBUG_MODE == "true" ]]; then
66+
DEBUG_OPTS="-Xdebug \
67+
-Xrunjdwp:server=y,transport=dt_socket,address=*:8000,suspend=n \
68+
-Xlog:gc=info:file=/var/log/kura-gc.log:time:filecount=10,filesize=10m \
69+
-XX:+HeapDumpOnOutOfMemoryError \
70+
-XX:HeapDumpPath=/var/log/kura-heapdump.hprof \
71+
-XX:ErrorFile=/var/log/kura-error.log"
72+
fi
73+
74+
KURA_LAUNCH_COMMAND="exec java"
75+
76+
if [[ $IS_DETACHED_MODE == "true" ]]; then
77+
KURA_LAUNCH_COMMAND="nohup java"
78+
fi
79+
80+
KURA_CMD="${KURA_LAUNCH_COMMAND} -Xms${kura.mem.size} -Xmx${kura.mem.size} \
81+
$DEBUG_OPTS \
82+
-XX:+IgnoreUnrecognizedVMOptions \
83+
--add-opens java.base/java.lang=ALL-UNNAMED \
84+
--add-opens java.base/java.util=ALL-UNNAMED \
85+
--add-modules=ALL-SYSTEM \
86+
-Dkura.os.version=${kura.os.version} \
87+
-Dkura.arch=${kura.arch} \
88+
-Dtarget.device=${target.device} \
89+
-Declipse.ignoreApp=true \
90+
-Dkura.home=\${DIR} \
91+
-Dkura.configuration=file:\${DIR}/framework/kura.properties \
92+
-Dkura.custom.configuration=file:\${DIR}/user/kura_custom.properties \
93+
-Ddpa.configuration=\${DIR}/packages/dpa.properties \
94+
-Dlog4j.configurationFile=file:\${DIR}/log4j/log4j.xml \
95+
-Dlog4j2.disable.jmx=true \
96+
-Djava.security.policy=\${DIR}/framework/jdk.dio.policy \
97+
-Djdk.dio.registry=\${DIR}/framework/jdk.dio.properties \
98+
-Djdk.tls.trustNameService=true \
99+
-Declipse.consoleLog=true \
100+
-jar \${DIR}/plugins/org.eclipse.equinox.launcher-${org.eclipse.equinox.launcher.version}.jar \
101+
-configuration /tmp/.kura/configuration"
102+
103+
if [[ $IS_DETACHED_MODE == "true" ]]; then
104+
eval "$KURA_CMD &"
105+
106+
#Save the PID
107+
KURA_PID=$!
108+
echo "Kura Started (pid=$KURA_PID) ..."
109+
echo $KURA_PID > /var/run/kura.pid
39110
else
40-
echo "Failed to start Kura. It is already running ..."
111+
eval "$KURA_CMD"
41112
fi

kura/distrib/src/main/resources/filtered/pkg/bin/start_kura_background.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

kura/distrib/src/main/resources/filtered/pkg/bin/start_kura_debug.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

kura/distrib/src/main/resources/filtered/pkg/install/kura.service

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ After=dbus.service
77
User=kurad
88
Group=kurad
99
Type=forking
10-
ExecStart=/bin/sh ${kura.install.dir}/kura/bin/start_kura_background.sh
11-
ExecStopPost=/bin/sh -c 'if [ -f /tmp/watchdog ]; then echo w > `cat /tmp/watchdog`; fi'
10+
ExecStart=/bin/bash ${kura.install.dir}/kura/bin/start_kura.sh --detached
11+
ExecStopPost=/bin/bash -c 'if [ -f /tmp/watchdog ]; then echo w > `cat /tmp/watchdog`; fi'
1212
PIDFile=/var/run/kura.pid
1313
Restart=on-failure
1414
RestartSec=5

kura/distrib/src/main/resources/unfiltered/pkg/install/customize-installation.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@ customize_ram() {
6969
fi
7070

7171
echo "Setting kura RAM to ${RAM_MB_FOR_KURA}"
72-
start_scripts_to_change=("start_kura.sh" "start_kura_debug.sh" "start_kura_background.sh")
7372

7473
RAM_REPLACEMENT_STRING="-Xms${RAM_MB_FOR_KURA}m -Xmx${RAM_MB_FOR_KURA}m"
75-
for installer_name in "${start_scripts_to_change[@]}"; do
76-
echo "Updating RAM values for $installer_name"
77-
sed -i "s/-Xms[0-9]*m -Xmx[0-9]*m/$RAM_REPLACEMENT_STRING/g" "/opt/eclipse/kura/bin/$installer_name"
78-
done
79-
80-
fi
74+
75+
echo "Updating RAM values for start_kura.sh"
76+
sed -i "s/-Xms[0-9]*m -Xmx[0-9]*m/$RAM_REPLACEMENT_STRING/g" "/opt/eclipse/kura/bin/start_kura.sh"
77+
78+
fi
8179
}
8280

8381
setup_libudev
@@ -94,4 +92,3 @@ mv "/opt/eclipse/kura/install/jdk.dio.properties-${BOARD}" "/opt/eclipse/kura/fr
9492
install_snapshot
9593
customize_kura_properties "${BOARD}"
9694
customize_ram "${BOARD}"
97-

0 commit comments

Comments
 (0)