Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions percona-packaging/conf/mongod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ systemLog:
logAppend: true
path: /var/log/mongodb/mongod.log

processManagement:
fork: true
pidFilePath: /var/run/mongod.pid

# network interfaces
net:
port: 27017
Expand Down
6 changes: 3 additions & 3 deletions percona-packaging/conf/mongod.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Description=High-performance, schema-free document-oriented database
After=time-sync.target network.target

[Service]
Type=forking
User=mongod
Group=mongod
PermissionsStartOnly=true
Expand All @@ -13,9 +12,10 @@ LimitAS=infinity
LimitNOFILE=64000
LimitNPROC=64000
EnvironmentFile=-/etc/@@LOCATION@@/mongod
Environment="GLIBC_TUNABLES=glibc.pthread.rseq=0"
Environment="MONGODB_CONFIG_OVERRIDE_NOFORK=1"
ExecStartPre=/usr/bin/percona-server-mongodb-helper.sh
ExecStart=/usr/bin/env bash -c "${NUMACTL} /usr/bin/mongod ${OPTIONS} > ${STDOUT} 2> ${STDERR}"
PIDFile=/var/run/mongod.pid
ExecStart=/usr/bin/env bash -c "${NUMACTL} /usr/bin/mongod ${OPTIONS}"

[Install]
WantedBy=multi-user.target
95 changes: 45 additions & 50 deletions percona-packaging/conf/percona-server-mongodb-enable-auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CONF_FORMAT="yaml"
AUTH_SECTION_EXISTS=0
PARAM_USERNAME=0

SCRIPT_PWD=$(cd $(dirname $0) && pwd)
SCRIPT_PWD=$(cd `dirname $0` && pwd)
MONGO_CLIENT_BIN="${SCRIPT_PWD}/mongosh"

if [ "${SCRIPT_PWD}" = "/usr/bin" ]; then
Expand All @@ -23,7 +23,7 @@ else
fi

usage() {
echo "Usage: $(basename $0) [-h] [-q] [-c ConfigFileName] [-u Username] [-p Password]"
echo "Usage: `basename $0` [-h] [-q] [-c ConfigFileName] [-u Username] [-p Password]"
echo
echo " This script is used to enable authentication in Percona Server for MongoDB automatically."
echo " User 'dba' (or provided with the '-u' argument) with role 'root' will be created with autogenerated password (or provided with the '-p' argument) and the service will be restarted."
Expand All @@ -37,49 +37,44 @@ usage() {
}

while getopts ":hqc:u:p:" arg; do
case $arg in
case $arg in
c) # Specify CONF value.
CONF=${OPTARG}
;;
CONF=${OPTARG}
;;
q) # quiet mode.
QUIET=1
;;
QUIET=1
;;
u) # Username to use instead of 'dba'.
USERNAME="${OPTARG}"
PARAM_USERNAME=1
;;
USERNAME="${OPTARG}"
PARAM_USERNAME=1
;;
p) # Password to use instead of auto generation.
PASSWORD="${OPTARG}"
;;
PASSWORD="${OPTARG}"
;;
h) # Display help.
usage
exit 0
;;
*) ;;
esac
usage
exit 0
;;
*)
;;
esac
done

[[ -z "$CONF" ]] && CONF='/etc/mongod.conf'
[[ -f "$CONF" ]] || {
echo "Configuration file '$CONF' does not exist" >&2
exit 1
}
[[ -f "$CONF" ]] || { echo "Configuration file '$CONF' does not exist" >&2; exit 1; }

[[ "$EUID" -ne 0 ]] && {
echo "Please run as root" >&2
exit 1
}
[[ "$EUID" -ne 0 ]] && { echo "Please run as root" >&2; exit 1; }

[[ -z "$USERNAME" || "$USERNAME" = "root" && "$PARAM_USERNAME" = 0 ]] && USERNAME='dba'
[[ -z "$PASSWORD" ]] && PASSWORD="$(tr -dc 'a-zA-Z0-9' </dev/urandom | head -c 32)"
[[ -z "$PASSWORD" ]] && PASSWORD="$( tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 32 )"
USERNAME="${USERNAME%%\\n}"
PASSWORD="${PASSWORD%%\\n}"

parse_yaml() {
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
Expand All @@ -106,7 +101,7 @@ get_value_from_yaml() {
break
fi
done
done <<<"$array"
done <<< "$array"
echo $result
}

Expand Down Expand Up @@ -137,10 +132,10 @@ add_value_to_yaml() {
sed -i "s/security:/security:\n authorization: enabled/" $CONF
fi
else
delim=$(grep '## Enterprise-Only Options:' $CONF)
delim=$( grep '## Enterprise-Only Options:' $CONF )
if [[ $delim == '' ]]; then
echo "security:" >>$CONF
echo " authorization: enabled" >>$CONF
echo "security:" >> $CONF
echo " authorization: enabled" >> $CONF
else
sed -i "s/## Enterprise-Only Options:/security:\n authorization: enabled\n## Enterprise-Only Options:/" $CONF
fi
Expand All @@ -153,8 +148,8 @@ add_user_to_mongo() {
port="$(get_value_from_yaml net port)"
user="$USERNAME"
password="$PASSWORD"
echo "db.createUser({user: \"$user\", pwd: \"$password\", roles: [ \"root\" ] });" | ${MONGO_CLIENT_BIN} admin --port ${port} --eval >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "db.createUser({user: \"$user\", pwd: \"$password\", roles: [ \"root\" ] });" | ${MONGO_CLIENT_BIN} admin --port ${port} --eval > /dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "User has been created successfully!\nUser:${user}\nPassword:${password}"
else
echo "ERROR! User cannot be added!"
Expand All @@ -166,15 +161,15 @@ add_user_to_mongo() {
if [ ! -f /tmp/mongodb_create.lock ]; then
AUTH_ENABLED=0
auth_res=$(get_value_from_yaml security auth)
if [[ $auth_res == enabled ]]; then
if [[ $auth_res == enabled ]]; then
AUTH_ENABLED=1
elif [[ $auth_res == disabled ]]; then
elif [[ $auth_res == disabled ]]; then
AUTH_ENABLED=0
AUTH_SECTION_EXISTS=1
elif [[ $(egrep '^auth=1' $CONF) ]]; then
elif [[ `egrep '^auth=1' $CONF` ]]; then
AUTH_ENABLED=1
CONF_FORMAT="conf"
elif [[ $(egrep '^auth=0' $CONF) ]]; then
elif [[ `egrep '^auth=0' $CONF` ]]; then
AUTH_ENABLED=0
AUTH_SECTION_EXISTS=1
fi
Expand All @@ -192,16 +187,16 @@ if [ ! -f /tmp/mongodb_create.lock ]; then
replsetname_res=$(get_value_from_yaml replication replSetName)
keyfile_res=$(get_value_from_yaml security keyFile)
if [[ $replsetname_res != 0 ]]; then
# replication.replsetName is specified in the config
if [[ $keyfile_res == 0 ]]; then
# security.keyFile does not exist in the config
echo "ERROR! You need to configure a shared keyfile on all members before enabling authentication in a replica set!"
exit 1
elif [[ ! -f "$keyfile_res" ]]; then
# security.keyFile exists but the file is absent
echo "ERROR! The configured keyfile $keyfile_res doesn't exist. Cannot enable authentication in a replica set."
exit 1
fi
# replication.replsetName is specified in the config
if [[ $keyfile_res == 0 ]]; then
# security.keyFile does not exist in the config
echo "ERROR! You need to configure a shared keyfile on all members before enabling authentication in a replica set!"
exit 1
elif [[ ! -f "$keyfile_res" ]]; then
# security.keyFile exists but the file is absent
echo "ERROR! The configured keyfile $keyfile_res doesn't exist. Cannot enable authentication in a replica set."
exit 1
fi
fi
touch /tmp/mongodb_create.lock
started=$(pgrep mongod | wc -l)
Expand Down
41 changes: 24 additions & 17 deletions percona-packaging/conf/percona-server-mongodb-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,38 @@
#
PATH="${PATH}:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
#
touch /var/run/mongod.pid
touch /var/log/@@LOGDIR@@/mongod.{stdout,stderr}
chown mongod:mongod /var/run/mongod.pid
chown -R mongod:mongod /var/log/@@LOGDIR@@
#
KTHP=/sys/kernel/mm/transparent_hugepage
#
[ -z "${CONF}" ] && CONF=/etc/mongod.conf
#
print_error() {
echo " * Error disabling Transparent Huge pages, exiting"
exit 1
print_error(){
echo " * Error enabling Transparent Huge pages, exiting"
exit 1
}
#

if grep -q "pidFilePath" /etc/mongod.conf; then
touch /var/run/mongod.pid
chown mongod:mongod /var/run/mongod.pid
fi

. /etc/@@LOCATION@@/mongod
DAEMON_OPTS="${OPTIONS}"
#
# Handle NUMA access to CPUs (SERVER-3574)
# This verifies the existence of numactl as well as testing that the command works
NUMACTL_ARGS="--interleave=all"
if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null; then
if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null
then
NUMACTL="numactl $NUMACTL_ARGS"
DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"}
NUMA_CONF=$(grep -c 'NUMACTL="numactl --interleave=all"' /etc/@@LOCATION@@/mongod)
if [ $NUMA_CONF = 0 ]; then
echo 'NUMACTL="numactl --interleave=all"' >>/etc/@@LOCATION@@/mongod
if [ $NUMA_CONF = 0 ]
then
echo 'NUMACTL="numactl --interleave=all"' >> /etc/@@LOCATION@@/mongod
fi
else
NUMACTL=""
Expand All @@ -39,13 +45,14 @@ defaults=$(echo "${OPTIONS}" | egrep -o 'storageEngine.*' | tr -d '[[:blank:]]'
config=$(egrep -o '^[[:blank:]]+engine.*' ${CONF} | tr -d '[[:blank:]]' | awk -F':' '{print $NF}' 2>/dev/null)
#
if [ -n "${defaults}" ] && [ -n "${config}" ]; then # engine is set in 2 places
if [ "${defaults}" == "${config}" ]; then # it's OK
echo " * Warning, engine is set both in defaults file and mongod.conf!"
else
echo " * Error, different engines are set in the same time!"
exit 1
fi
if [ "${defaults}" == "${config}" ]; then # it's OK
echo " * Warning, engine is set both in defaults file and mongod.conf!"
else
echo " * Error, different engines are set in the same time!"
exit 1
fi
fi
# disable THP
fgrep '[always]' ${KTHP}/enabled >/dev/null 2>&1 && (echo never >${KTHP}/enabled 2>/dev/null || print_error) || true
fgrep '[always]' ${KTHP}/defrag >/dev/null 2>&1 && (echo never >${KTHP}/defrag 2>/dev/null || print_error) || true
# enable THP
fgrep '[always]' ${KTHP}/enabled > /dev/null 2>&1 || (echo always > ${KTHP}/enabled 2> /dev/null || print_error) || true
fgrep '[defer+madvise]' ${KTHP}/defrag > /dev/null 2>&1 || (echo defer+madvise > ${KTHP}/defrag 2> /dev/null || print_error) || true
fgrep '0' ${KTHP}/khugepaged/max_ptes_none > /dev/null 2>&1 || (echo 0 > ${KTHP}/khugepaged/max_ptes_none 2> /dev/null || print_error) || true
4 changes: 2 additions & 2 deletions percona-packaging/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
percona-server-mongodb (4.4.0) UNRELEASED; urgency=medium
percona-server-mongodb (8.3.0) UNRELEASED; urgency=medium

* Updated to next upstream release.

-- Oleksandr Miroshnychenko <alex.miroshnychenko@percona.com> Thu, 27 Feb 2020 12:20:22 +0600
-- Oleksandr Miroshnychenko <alex.miroshnychenko@percona.com> Mon, 9 Mar 2026 12:45:11 +0200
Loading
Loading