Skip to content

Commit

Permalink
Make config folder dynamic using OPENSEARCH_PATH_CONF var (#2048)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
  • Loading branch information
peterzhuamazon authored Apr 28, 2022
1 parent 2c2e4e4 commit 4597d77
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Export OpenSearch Home
export OPENSEARCH_HOME=/usr/share/opensearch
export OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config

# The virtual file /proc/self/cgroup should list the current cgroup
# membership. For each hierarchy, you can follow the cgroup path from
Expand Down
5 changes: 3 additions & 2 deletions docker/release/dockerfiles/opensearch.al2.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ ARG UID=1000
ARG GID=1000
ARG TEMP_DIR=/tmp/opensearch
ARG OPENSEARCH_HOME=/usr/share/opensearch
ARG OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config
ARG SECURITY_PLUGIN_DIR=$OPENSEARCH_HOME/plugins/opensearch-security
ARG PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR=$OPENSEARCH_HOME/config/opensearch-performance-analyzer
ARG PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR=$OPENSEARCH_PATH_CONF/opensearch-performance-analyzer

# Update packages
# Install the tools we need: tar and gzip to unpack the OpenSearch tarball, and shadow-utils to give us `groupadd` and `useradd`.
Expand All @@ -41,7 +42,7 @@ RUN ls -l $TEMP_DIR && \
if [[ -d $SECURITY_PLUGIN_DIR ]] ; then chmod -v 750 $SECURITY_PLUGIN_DIR/tools/* ; fi && \
if [[ -d $PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR ]] ; then cp -v $TEMP_DIR/performance-analyzer.properties $PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR; fi && \
cp -v $TEMP_DIR/opensearch-docker-entrypoint.sh $TEMP_DIR/opensearch-onetime-setup.sh $OPENSEARCH_HOME/ && \
cp -v $TEMP_DIR/log4j2.properties $TEMP_DIR/opensearch.yml $OPENSEARCH_HOME/config/ && \
cp -v $TEMP_DIR/log4j2.properties $TEMP_DIR/opensearch.yml $OPENSEARCH_PATH_CONF/ && \
ls -l $OPENSEARCH_HOME && \
rm -rf $TEMP_DIR

Expand Down
21 changes: 12 additions & 9 deletions scripts/legacy/tar/linux/opensearch-tar-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0

OPENSEARCH_HOME=`dirname $(realpath $0)`; cd $OPENSEARCH_HOME
export OPENSEARCH_HOME=`dirname $(realpath $0)`
export OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config
cd $OPENSEARCH_HOME

KNN_LIB_DIR=$OPENSEARCH_HOME/plugins/opensearch-knn/lib
##Security Plugin
bash $OPENSEARCH_HOME/plugins/opensearch-security/tools/install_demo_configuration.sh -y -i -s

echo "done security"
PA_AGENT_JAVA_OPTS="-Dlog4j.configurationFile=$OPENSEARCH_HOME/config/opensearch-performance-analyzer/log4j2.xml \
PA_AGENT_JAVA_OPTS="-Dlog4j.configurationFile=$OPENSEARCH_PATH_CONF/opensearch-performance-analyzer/log4j2.xml \
-Xms64M -Xmx64M -XX:+UseSerialGC -XX:CICompilerCount=1 -XX:-TieredCompilation -XX:InitialCodeCacheSize=4096 \
-XX:MaxRAM=400m"

OPENSEARCH_MAIN_CLASS="org.opensearch.performanceanalyzer.PerformanceAnalyzerApp" \
OPENSEARCH_ADDITIONAL_CLASSPATH_DIRECTORIES=plugins/opensearch-performance-analyzer \
OPENSEARCH_JAVA_OPTS=$PA_AGENT_JAVA_OPTS

if ! grep -q '## OpenSearch Performance Analyzer' $OPENSEARCH_HOME/config/jvm.options; then
if ! grep -q '## OpenSearch Performance Analyzer' $OPENSEARCH_PATH_CONF/jvm.options; then
CLK_TCK=`/usr/bin/getconf CLK_TCK`
echo >> $OPENSEARCH_HOME/config/jvm.options
echo '## OpenSearch Performance Analyzer' >> $OPENSEARCH_HOME/config/jvm.options
echo "-Dclk.tck=$CLK_TCK" >> $OPENSEARCH_HOME/config/jvm.options
echo "-Djdk.attach.allowAttachSelf=true" >> $OPENSEARCH_HOME/config/jvm.options
echo "-Djava.security.policy=$OPENSEARCH_HOME/config/opensearch-performance-analyzer/opensearch_security.policy" >> $OPENSEARCH_HOME/config/jvm.options
echo "--add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED" >> $OPENSEARCH_HOME/config/jvm.options
echo >> $OPENSEARCH_PATH_CONF/jvm.options
echo '## OpenSearch Performance Analyzer' >> $OPENSEARCH_PATH_CONF/jvm.options
echo "-Dclk.tck=$CLK_TCK" >> $OPENSEARCH_PATH_CONF/jvm.options
echo "-Djdk.attach.allowAttachSelf=true" >> $OPENSEARCH_PATH_CONF/jvm.options
echo "-Djava.security.policy=$OPENSEARCH_PATH_CONF/opensearch-performance-analyzer/opensearch_security.policy" >> $OPENSEARCH_PATH_CONF/jvm.options
echo "--add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED" >> $OPENSEARCH_PATH_CONF/jvm.options
fi
echo "done plugins"

Expand Down
24 changes: 13 additions & 11 deletions scripts/opensearch-onetime-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
# This script performs one-time setup for the OpenSearch tarball distribution.
# It installs a demo security config and sets up the performance analyzer

OPENSEARCH_HOME=`dirname $(realpath $0)`; cd $OPENSEARCH_HOME
export OPENSEARCH_HOME=`dirname $(realpath $0)`
export OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config
cd $OPENSEARCH_HOME

##Security Plugin
SECURITY_PLUGIN="opensearch-security"
Expand All @@ -23,24 +25,24 @@ if [ -d "$OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN" ]; then

if [ "$DISABLE_SECURITY_PLUGIN" = "true" ]; then
echo "Disabling OpenSearch Security Plugin"
sed -i '/plugins.security.disabled/d' $OPENSEARCH_HOME/config/opensearch.yml
echo "plugins.security.disabled: true" >> $OPENSEARCH_HOME/config/opensearch.yml
sed -i '/plugins.security.disabled/d' $OPENSEARCH_PATH_CONF/opensearch.yml
echo "plugins.security.disabled: true" >> $OPENSEARCH_PATH_CONF/opensearch.yml
else
echo "Enabling OpenSearch Security Plugin"
sed -i '/plugins.security.disabled/d' $OPENSEARCH_HOME/config/opensearch.yml
sed -i '/plugins.security.disabled/d' $OPENSEARCH_PATH_CONF/opensearch.yml
fi
fi

##Perf Plugin
PA_PLUGIN="opensearch-performance-analyzer"

if ! grep -q '## OpenDistro Performance Analyzer' $OPENSEARCH_HOME/config/jvm.options; then
if ! grep -q '## OpenDistro Performance Analyzer' $OPENSEARCH_PATH_CONF/jvm.options; then
CLK_TCK=`/usr/bin/getconf CLK_TCK`
echo >> $OPENSEARCH_HOME/config/jvm.options
echo '## OpenDistro Performance Analyzer' >> $OPENSEARCH_HOME/config/jvm.options
echo "-Dclk.tck=$CLK_TCK" >> $OPENSEARCH_HOME/config/jvm.options
echo "-Djdk.attach.allowAttachSelf=true" >> $OPENSEARCH_HOME/config/jvm.options
echo "-Djava.security.policy=$OPENSEARCH_HOME/config/$PA_PLUGIN/opensearch_security.policy" >> $OPENSEARCH_HOME/config/jvm.options
echo "--add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED" >> $OPENSEARCH_HOME/config/jvm.options
echo >> $OPENSEARCH_PATH_CONF/jvm.options
echo '## OpenDistro Performance Analyzer' >> $OPENSEARCH_PATH_CONF/jvm.options
echo "-Dclk.tck=$CLK_TCK" >> $OPENSEARCH_PATH_CONF/jvm.options
echo "-Djdk.attach.allowAttachSelf=true" >> $OPENSEARCH_PATH_CONF/jvm.options
echo "-Djava.security.policy=$OPENSEARCH_PATH_CONF/$PA_PLUGIN/opensearch_security.policy" >> $OPENSEARCH_PATH_CONF/jvm.options
echo "--add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED" >> $OPENSEARCH_PATH_CONF/jvm.options
fi

2 changes: 1 addition & 1 deletion scripts/pkg/build_templates/opensearch/opensearch.rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ if ! grep -q '## OpenSearch Performance Analyzer' %{config_dir}/jvm.options; the
echo '## OpenSearch Performance Analyzer' >> %{config_dir}/jvm.options
echo "-Dclk.tck=$CLK_TCK" >> %{config_dir}/jvm.options
echo "-Djdk.attach.allowAttachSelf=true" >> %{config_dir}/jvm.options
echo "-Djava.security.policy=file:///etc/opensearch/opensearch-performance-analyzer/opensearch_security.policy" >> %{config_dir}/jvm.options
echo "-Djava.security.policy=file://%{config_dir}/opensearch-performance-analyzer/opensearch_security.policy" >> %{config_dir}/jvm.options
echo "--add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED" >> %{config_dir}/jvm.options
fi
# Reload systemctl daemon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[Unit]
Description=OpenSearch Performance Analyzer
#PartOf=opensearch.service

[Service]
Type=simple
ExecStart=/usr/share/opensearch/bin/opensearch-performance-analyzer/performance-analyzer-agent-cli
Restart=on-failure
User=opensearch
Group=opensearch
Environment=OPENSEARCH_HOME=/usr/share/opensearch
EnvironmentFile=-/etc/sysconfig/opensearch
WorkingDirectory=/usr/share/opensearch

[Install]
#WantedBy=opensearch.service
WantedBy=multi-user.target

0 comments on commit 4597d77

Please sign in to comment.