Skip to content

Commit

Permalink
Add systemd unit for solr
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanleonov committed Mar 21, 2019
1 parent 8fbd4bb commit 87242ac
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 25 deletions.
49 changes: 32 additions & 17 deletions SearchService2/solr-management/ensure_solr_running.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,51 @@ fi
# Generating proper solr.in.sh with needed SolrCloud configurations.
HEAP_REDUCTION="${HEAP_REDUCTION:-0.0}"
TOTAL_MEM_KB=$(awk '/MemTotal/ { print $2 }' /proc/meminfo)
# Give Solr at most half of total memory minus heap reduction.
SOLR_MEM_MB=$(echo "$TOTAL_MEM_KB $HEAP_REDUCTION" \
| awk '{ printf "%d", $1 * (1 - $2) / 1024 / 2 }')
# Give Solr at most half of total memory minus heap reduction (kill if greater).
SOLR_MEM_MAX=$(echo "$TOTAL_MEM_KB $HEAP_REDUCTION" \
| awk '{ printf "%d", $1 * (1 - $2) / 1024 / 2 }')
# Always try to give at least 70% of max memory.
SOLR_MEM_LOW=$(echo "$SOLR_MEM_MAX" | awk '{ printf "%d", $1 * 0.70 }')
# Slow process down when usage is higher.
SOLR_MEM_HIGH=$(echo "$SOLR_MEM_MAX" | awk '{ printf "%d", $1 * 0.90 }')

echo "Ensuring ulimit properties are set for Solr"
grep -q "solr \+hard \+nofile \+65535" /etc/security/limits.conf \
|| echo "solr hard nofile 65535" >> /etc/security/limits.conf
grep -q "solr \+soft \+nofile \+65535" /etc/security/limits.conf \
|| echo "solr soft nofile 65535" >> /etc/security/limits.conf
grep -q "solr \+hard \+nproc \+65535" /etc/security/limits.conf \
|| echo "solr hard nproc 65535" >> /etc/security/limits.conf
grep -q "solr \+soft \+nproc \+65535" /etc/security/limits.conf \
|| echo "solr soft nproc 65535" >> /etc/security/limits.conf
# echo "Ensuring ulimit properties are set for Solr"
# grep -q "solr \+hard \+nofile \+65535" /etc/security/limits.conf \
# || echo "solr hard nofile 65535" >> /etc/security/limits.conf
# grep -q "solr \+soft \+nofile \+65535" /etc/security/limits.conf \
# || echo "solr soft nofile 65535" >> /etc/security/limits.conf
# grep -q "solr \+hard \+nproc \+65535" /etc/security/limits.conf \
# || echo "solr hard nproc 65535" >> /etc/security/limits.conf
# grep -q "solr \+soft \+nproc \+65535" /etc/security/limits.conf \
# || echo "solr soft nproc 65535" >> /etc/security/limits.conf

export SOLR_MEM="${SOLR_MEM_MB}m"
export SOLR_HEAP="${SOLR_MEM_HIGH}m"
export MEMORY_LOW="${SOLR_MEM_LOW}M"
export MEMORY_HIGH="${SOLR_MEM_HIGH}M"
export MEMORY_MAX="${SOLR_MEM_MAX}M"
export ZK_HOST
export PRIVATE_IP
envsubst < "${SOLR_MANAGEMENT_DIR}/solr.in.sh" > "/tmp/solr.in.sh"
if cmp -s "/tmp/solr.in.sh" "/etc/default/solr.in.sh"
envsubst '$SOLR_HEAP $ZK_HOST $PRIVATE_IP' \
< "${SOLR_MANAGEMENT_DIR}/solr.in.sh" > "/tmp/solr.in.sh"
envsubst '$MEMORY_LOW $MEMORY_HIGH $MEMORY_MAX'\
< "${SOLR_MANAGEMENT_DIR}/solr.service" > "/tmp/solr.service"
if cmp -s "/tmp/solr.in.sh" "/etc/default/solr.in.sh" \
&& cmp -s "/tmp/solr.service" "/etc/systemd/system/solr.service"
then
echo "/etc/default/solr.in.sh has no changes."
echo "/etc/systemd/system/solr.service has no changes."
echo "Making sure Solr is running."
sudo systemctl start solr
sudo systemctl enable solr
sudo systemctl start solr
else
echo "Copying new solr.in.sh to /etc/default/solr.in.sh"
sudo cp "/tmp/solr.in.sh" "/etc/default/solr.in.sh"
echo "Copying new solr.service to /etc/systemd/system/solr.service"
sudo cp "/tmp/solr.service" "/etc/systemd/system/solr.service"
echo "Making sure Solr is restarted."
sudo systemctl restart solr
sudo systemctl daemon-reload
sudo systemctl enable solr
sudo systemctl restart solr
fi

echo "Making sure appscale-specific config set is uploaded to zookeeper."
Expand Down
10 changes: 5 additions & 5 deletions SearchService2/solr-management/solr.in.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#SOLR_STOP_WAIT="180"

# Increase Java Heap as needed to support your indexing / query needs
SOLR_HEAP="${SOLR_MEM}"
SOLR_HEAP="${SOLR_HEAP}"

# Expert: If you want finer control over memory options, specify them directly
# Comment out SOLR_HEAP if you are using this though, that takes precedence
Expand Down Expand Up @@ -83,11 +83,11 @@ SOLR_HOST="${PRIVATE_IP}"

# Location where the bin/solr script will save PID files for running instances
# If not set, the script will create PID files in $SOLR_TIP/bin
SOLR_PID_DIR="/var/solr"
SOLR_PID_DIR="/opt/appscale/solr7"

# Path to a directory for Solr to store cores and their data. By default, Solr will use server/solr
# If solr.xml is not stored in ZooKeeper, this directory needs to contain solr.xml
SOLR_HOME="/var/solr/data"
SOLR_HOME="/opt/appscale/solr7/data"

# Path to a directory that Solr will use as root for data folders for each core.
# If not set, defaults to <instance_dir>/data. Overridable per core through 'dataDir' core property
Expand All @@ -96,14 +96,14 @@ SOLR_HOME="/var/solr/data"
# Solr provides a default Log4J configuration xml file in server/resources
# however, you may want to customize the log settings and file appender location
# so you can point the script to use a different log4j2.xml file
LOG4J_PROPS="/var/solr/log4j2.xml"
LOG4J_PROPS="/opt/appscale/solr7/log4j2.xml"

# Changes the logging level. Valid values: ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF. Default is INFO
# This is an alternative to changing the rootLogger in log4j2.xml
SOLR_LOG_LEVEL="INFO"

# Location where Solr should write logs to. Absolute or relative to solr start dir
SOLR_LOGS_DIR="/var/solr/logs"
SOLR_LOGS_DIR="/var/log/appscale/solr"

# Enables log rotation before starting Solr. Setting SOLR_LOG_PRESTART_ROTATION=true will let Solr take care of pre
# start rotation of logs. This is false by default as log4j2 handles this for us. If you choose to use another log
Expand Down
34 changes: 34 additions & 0 deletions SearchService2/solr-management/solr.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# /etc/systemd/system/solr.service
[Unit]
Description=Apache SOLR
After=syslog.target network.target remote-fs.target nss-lookup.target
Conflicts=shutdown.target

[Service]
User=solr
LimitNOFILE=65535
LimitNPROC=65535
PIDFile=/opt/appscale/solr7/solr-8983.pid
Environment=SOLR_INCLUDE=/etc/default/solr.in.sh
Environment=RUNAS=solr
Environment=SOLR_INSTALL_DIR=/opt/solr

Restart=on-failure
RestartSec=5

ExecStart=/opt/solr/bin/solr start
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=on-failure

MemoryLow=${MEMORY_LOW}
MemoryHigh=${MEMORY_HIGH}
MemoryMax=${MEMORY_MAX}

CPUAccounting=yes
MemoryAccounting=yes
TasksAccounting=yes
IOAccounting=yes

[Install]
WantedBy=multi-user.target
9 changes: 6 additions & 3 deletions debian/appscale_install_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ installsolr7()
cachepackage ${SOLR_PACKAGE} ${SOLR_PACKAGE_MD5}

SOLR_EXTRACT_DIR=/opt/
SOLR_VAR_DIR=/var/solr/
SOLR_VAR_DIR=/opt/appscale/solr7/
SOLR_ARCHIVE="${PACKAGE_CACHE}/${SOLR_PACKAGE}"

tar xzf "${SOLR_ARCHIVE}" solr-${SOLR_VER}/bin/install_solr_service.sh --strip-components=2
Expand All @@ -360,9 +360,12 @@ installsolr7()
# -n Do not start solr service after install.
# -f Upgrade Solr. Overwrite symlink and init script of previous installation.
sudo bash ./install_solr_service.sh "${SOLR_ARCHIVE}" \
-d "${SOLR_VAR_DIR}" \
-i "${SOLR_EXTRACT_DIR}" \
-d ${SOLR_VAR_DIR} \
-i ${SOLR_EXTRACT_DIR} \
-n -f
# Ensure systemd won't start Solr on its own after boot.
sed -i "s/### BEGIN INIT INFO.*/# COMMENTED # # # BEGIN INIT INFO/g" /etc/init.d/solr
sed -i "s/### END INIT INFO.*/# COMMENTED # # # END INIT INFO/g" /etc/init.d/solr
}

installcassandra()
Expand Down

0 comments on commit 87242ac

Please sign in to comment.