Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RPM M1] Add rpm assemble/bundle code for opensearch using rpmbuild #1726

23 changes: 17 additions & 6 deletions scripts/components/OpenSearch-Dashboards/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ function usage() {
echo -e "-s SNAPSHOT\t[Optional] Build a snapshot, default is 'false'."
echo -e "-p PLATFORM\t[Optional] Platform, default is 'uname -s'."
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, default is 'uname -m'."
echo -e "-d DISTRIBUTION\t[Optional] Distribution, default is 'tar'."
echo -e "-f ARTIFACTS\t[Optional] Location of build artifacts."
echo -e "-o OUTPUT\t[Optional] Output path."
echo -e "-h help"
}

while getopts ":h:v:s:o:p:a:f:" arg; do
while getopts ":h:v:s:o:p:a:d:f:" arg; do
case $arg in
h)
usage
Expand All @@ -42,6 +43,9 @@ while getopts ":h:v:s:o:p:a:f:" arg; do
a)
ARCHITECTURE=$OPTARG
;;
d)
DISTRIBUTION=$OPTARG
;;
f)
ARTIFACTS=$ARTIFACTS
;;
Expand All @@ -66,11 +70,18 @@ fi
[ -z "$SNAPSHOT" ] && SNAPSHOT="false"
[ -z "$PLATFORM" ] && PLATFORM=$(uname -s | awk '{print tolower($0)}')
[ -z "$ARCHITECTURE" ] && ARCHITECTURE=`uname -m`
[ -z "$DISTRIBUTION" ] && DISTRIBUTION="tar"

# Make sure the cwd is where the script is located
DIR="$(dirname "$0")"
echo $DIR
cd $DIR
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved

## Setup default config
(
DIR="$(dirname "$0")"
echo $DIR
cd $DIR
if [ "$DISTRIBUTION" = "tar" ]; then
cp ../../../config/opensearch_dashboards.yml "$OUTPUT/config/"
)

elif [ "$DISTRIBUTION" = "rpm" ]; then
cp -a ../../../scripts/service_templates/opensearch-dashboards/* "$OUTPUT/../"
cp -a ../../../scripts/build_templates/opensearch-dashboards/* "$OUTPUT/../"
fi
23 changes: 17 additions & 6 deletions scripts/components/OpenSearch/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ function usage() {
echo -e "-s SNAPSHOT\t[Optional] Build a snapshot, default is 'false'."
echo -e "-p PLATFORM\t[Optional] Platform, default is 'uname -s'."
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, default is 'uname -m'."
echo -e "-d DISTRIBUTION\t[Optional] Distribution, default is 'tar'."
echo -e "-f ARTIFACTS\t[Optional] Location of build artifacts."
echo -e "-o OUTPUT\t[Optional] Output path."
echo -e "-h help"
}

while getopts ":h:v:s:o:p:a:f:" arg; do
while getopts ":h:v:s:o:p:a:d:f:" arg; do
case $arg in
h)
usage
Expand All @@ -42,6 +43,9 @@ while getopts ":h:v:s:o:p:a:f:" arg; do
a)
ARCHITECTURE=$OPTARG
;;
d)
DISTRIBUTION=$OPTARG
;;
f)
ARTIFACTS=$ARTIFACTS
;;
Expand All @@ -66,11 +70,18 @@ fi
[ -z "$SNAPSHOT" ] && SNAPSHOT="false"
[ -z "$PLATFORM" ] && PLATFORM=$(uname -s | awk '{print tolower($0)}')
[ -z "$ARCHITECTURE" ] && ARCHITECTURE=`uname -m`
[ -z "$DISTRIBUTION" ] && DISTRIBUTION="tar"

# Make sure the cwd is where the script is located
DIR="$(dirname "$0")"
echo $DIR
cd $DIR

## Copy the tar installation script into the bundle
(
DIR="$(dirname "$0")"
echo $DIR
cd $DIR
if [ "$DISTRIBUTION" = "tar" ]; then
cp ../../../scripts/legacy/tar/linux/opensearch-tar-install.sh "$OUTPUT/"
)

elif [ "$DISTRIBUTION" = "rpm" ]; then
cp -a ../../../scripts/pkg/service_templates/opensearch/* "$OUTPUT/../"
cp -a ../../../scripts/pkg/build_templates/opensearch/* "$OUTPUT/../"
fi
157 changes: 157 additions & 0 deletions scripts/pkg/build_templates/opensearch/opensearch.rpm.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# No build, no debuginfo
%define debug_package %{nil}

# Disable brp-java-repack-jars, so jars will not be decompressed and repackaged
%define __jar_repack 0

# User Define Variables
%define product_dir %{_datadir}/%{name}
%define config_dir %{_sysconfdir}/%{name}
%define data_dir %{_sharedstatedir}/%{name}
%define log_dir %{_localstatedir}/log/%{name}
%define pid_dir %{_localstatedir}/run/%{name}

Name: opensearch
Version: 1.3.0
Release: 1
License: Apache-2.0
Summary: An open source distributed and RESTful search engine
URL: https://www.opensearch.org/
Group: Application/Internet
ExclusiveArch: x86_64
#Requires: #java-11-amazon-corretto-devel
AutoReqProv: no

%description
OpenSearch makes it easy to ingest, search, visualize, and analyze your data.
For more information, see: https://www.opensearch.org/

%prep
# No-op. We are using dir so no need to setup.

%build
# No-op. This is all pre-built Java. Nothing to do here.

%install
cd %{_topdir} && pwd
# Create necessary directories
mkdir -p %{buildroot}%{pid_dir}
# Install directories/files
cp -a etc usr var %{buildroot}
#rm -rf %{buildroot}%{product_dir}/jdk
# Symlinks (do not symlink config dir as security demo installer has dependency, if no presense it will switch to rpm/deb mode)
ln -s %{data_dir} %{buildroot}%{product_dir}/data
ln -s %{log_dir} %{buildroot}%{product_dir}/logs
# Performance Analyzer Settings
echo 'true' > %{buildroot}%{data_dir}/rca_enabled.conf
echo 'true' > %{buildroot}%{config_dir}/performance_analyzer_enabled.conf
echo 'true' > %{buildroot}%{config_dir}/rca_enabled.conf
# Change Permissions
chmod -Rf a+rX,u+w,g-w,o-w %{buildroot}/*
exit 0

%pre
# Stop existing service
if command -v systemctl >/dev/null && systemctl is-active %{name}.service >/dev/null; then
echo "Stop existing %{name}.service"
systemctl --no-reload stop %{name}.service
fi
# Create user and group if they do not already exist.
getent group %{name} > /dev/null 2>&1 || groupadd -r %{name}
getent passwd %{name} > /dev/null 2>&1 || \
useradd -r -g %{name} -M -s /sbin/nologin \
-c "%{name} user/group" %{name}
exit 0

%post
# Apply Security Settings
chmod 0755 %{product_dir}/bin/*
chmod 0755 %{product_dir}/plugins/opensearch-security/tools/*
sh %{product_dir}/plugins/opensearch-security/tools/install_demo_configuration.sh -y -i -s > %{log_dir}/install_demo_configuration.log 2>&1
chown -R %{name}.%{name} %{config_dir}
chown -R %{name}.%{name} %{log_dir}
# Apply PerformanceAnalyzer Settings
chmod a+rw /tmp
if ! grep -q '## OpenSearch Performance Analyzer' %{config_dir}/jvm.options; then
# Add Performance Analyzer settings in %{config_dir}/jvm.options
CLK_TCK=`/usr/bin/getconf CLK_TCK`
echo >> %{config_dir}/jvm.options
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:///usr/share/opensearch/plugins/opensearch-performance-analyzer/pa_config/opensearch_security.policy" >> %{config_dir}/jvm.options
fi
# Reload systemctl daemon
if command -v systemctl > /dev/null; then
systemctl daemon-reload
fi
# Reload other configs
sysctl -p %{_prefix}/lib/sysctl.d/%{name}.conf > /dev/null 2>&1
systemd-tmpfiles --create opensearch.conf
# Messages
echo "### NOT starting on installation, please execute the following statements to configure opensearch service to start automatically using systemd"
echo " sudo systemctl daemon-reload"
echo " sudo systemctl enable opensearch.service"
echo "### You can start opensearch service by executing"
echo " sudo systemctl start opensearch.service"
echo "### Created opensearch demo certificates in %{config_dir}/certs"
echo " See demo certs creation log in %{log_dir}/install_demo_configuration.log"
exit 0

%preun
if command -v systemctl >/dev/null && systemctl is-active %{name}.service >/dev/null; then
echo "Stop existing %{name}.service"
systemctl --no-reload stop %{name}.service
fi
exit 0

%postun
# No-op, let rpm handle the removal of folders and files that it owns.

%files
# Permissions
%defattr(-, %{name}, %{name})

# Root dirs/docs/licenses
%dir %{product_dir}
%doc %{product_dir}/NOTICE.txt
%doc %{product_dir}/README.md
%license %{product_dir}/LICENSE.txt
%{product_dir}/manifest.yml

# Config dirs/files
%dir %{config_dir}
%{config_dir}/jvm.options.d
%{config_dir}/opensearch-*
%config(noreplace) %{config_dir}/%{name}.yml
%config(noreplace) %{config_dir}/jvm.options
%config(noreplace) %{config_dir}/log4j2.properties
%config(noreplace) %{config_dir}/performance_analyzer_enabled.conf
%config(noreplace) %{data_dir}/rca_enabled.conf
%config(noreplace) %{config_dir}/rca_enabled.conf

# Service files
%attr(0644, root, root) %{_prefix}/lib/systemd/system/%{name}.service
%attr(0644, root, root) %{_prefix}/lib/systemd/system/opensearch-performance-analyzer.service
%attr(0644, root, root) %{_sysconfdir}/init.d/%{name}
%attr(0644, root, root) %config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%attr(0644, root, root) %config(noreplace) %{_prefix}/lib/sysctl.d/%{name}.conf
%attr(0644, root, root) %config(noreplace) %{_prefix}/lib/tmpfiles.d/%{name}.conf

# Main dirs
%{product_dir}/bin
%{product_dir}/jdk
%{product_dir}/lib
%{product_dir}/modules
%{product_dir}/performance-analyzer-rca
%{product_dir}/plugins
%{log_dir}
%{pid_dir}
%dir %{data_dir}

# Symlinks
%{product_dir}/data
%{product_dir}/logs

%changelog

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

# Description:
# Default opensearch-dashboards.service file

[Unit]
Description="OpenSearch Dashboards"

[Service]
Type=simple
User=opensearch-dashboards
Group=opensearch-dashboards
# Load env vars from /etc/default/ and /etc/sysconfig/ if they exist.
# Prefixing the path with '-' makes it try to load, but if the file doesn't
# exist, it continues onward.
EnvironmentFile=-/etc/default/opensearch-dashboards
EnvironmentFile=-/etc/sysconfig/opensearch-dashboards
ExecStart=/usr/share/opensearch-dashboards/bin/opensearch-dashboards "-c /etc/opensearch-dashboards/opensearch_dashboards.yml"
Restart=always
WorkingDirectory=/usr/share/opensearch-dashboards

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
################################
# OpenSearch
################################

# OpenSearch home directory
OPENSEARCH_HOME=/usr/share/opensearch

# OpenSearch Java path
#OPENSEARCH_JAVA_HOME=/usr/lib/jvm/java-11-amazon-corretto

# OpenSearch configuration directory
# Note: this setting will be shared with command-line tools
OPENSEARCH_PATH_CONF=/etc/opensearch

# OpenSearch PID directory
PID_DIR=/var/run/opensearch

# Additional Java OPTS
#OPENSEARCH_JAVA_OPTS=

# Configure restart on package upgrade (true, every other setting will lead to not restarting)
#RESTART_ON_UPGRADE=true

################################
# OpenSearch service
################################

# The number of seconds to wait before checking if OpenSearch started successfully as a daemon process
OPENSEARCH_STARTUP_SLEEP_TIME=5

# Notification for systemd
OPENSEARCH_SD_NOTIFY=true

################################
# System properties
################################

# Specifies the maximum file descriptor number that can be opened by this process
# When using Systemd, this setting is ignored and the LimitNOFILE defined in
# /usr/lib/systemd/system/opensearch.service takes precedence
#MAX_OPEN_FILES=65535

# The maximum number of bytes of memory that may be locked into RAM
# Set to "unlimited" if you use the 'bootstrap.memory_lock: true' option
# in opensearch.yml.
# When using systemd, LimitMEMLOCK must be set in a unit file such as
# /etc/systemd/system/opensearch.service.d/override.conf.
#MAX_LOCKED_MEMORY=unlimited

# Maximum number of VMA (Virtual Memory Areas) a process can own
# When using Systemd, this setting is ignored and the 'vm.max_map_count'
# property is set at boot time in /usr/lib/sysctl.d/opensearch.conf
#MAX_MAP_COUNT=262144
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=OpenSearch Performance Analyzer
#PartOf=opensearch.service

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

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