From 9e6cbd3d32fa37b139c66829b27f28bc81f1334c Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sat, 27 Feb 2021 05:28:42 +0000 Subject: [PATCH] set uwsgi procs based on cpu count --- install.sh | 13 +++++++++---- restore.sh | 31 +++++++++++++++++++++++++++++-- update.sh | 42 ++++++++++++++++++++++++++++++++---------- 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/install.sh b/install.sh index 10d4bc26..ab628f5a 100644 --- a/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/bin/bash -SCRIPT_VERSION="40" +SCRIPT_VERSION="41" SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/install.sh' sudo apt install -y curl wget dirmngr gnupg lsb-release @@ -406,6 +406,12 @@ python manage.py generate_barcode ${RANDBASE} ${djangousername} ${frontenddomain deactivate read -n 1 -s -r -p "Press any key to continue..." +uwsgiprocs=4 +if [[ "$numprocs" == "1" ]]; then + uwsgiprocs=2 +else + uwsgiprocs=$numprocs +fi uwsgini="$(cat << EOF [uwsgi] @@ -413,8 +419,8 @@ chdir = /rmm/api/tacticalrmm module = tacticalrmm.wsgi home = /rmm/api/env master = true -processes = 6 -threads = 6 +processes = ${uwsgiprocs} +threads = ${uwsgiprocs} enable-threads = true socket = /rmm/api/tacticalrmm/tacticalrmm.sock harakiri = 300 @@ -423,7 +429,6 @@ buffer-size = 65535 vacuum = true die-on-term = true max-requests = 500 -max-requests-delta = 1000 EOF )" echo "${uwsgini}" > /rmm/api/tacticalrmm/app.ini diff --git a/restore.sh b/restore.sh index 8784b60e..40f81514 100755 --- a/restore.sh +++ b/restore.sh @@ -1,6 +1,6 @@ #!/bin/bash -SCRIPT_VERSION="19" +SCRIPT_VERSION="20" SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/restore.sh' sudo apt update @@ -242,9 +242,36 @@ npm install meshcentral@${MESH_VER} print_green 'Restoring the backend' +numprocs=$(nproc) +uwsgiprocs=4 +if [[ "$numprocs" == "1" ]]; then + uwsgiprocs=2 +else + uwsgiprocs=$numprocs +fi + +uwsgini="$(cat << EOF +[uwsgi] +chdir = /rmm/api/tacticalrmm +module = tacticalrmm.wsgi +home = /rmm/api/env +master = true +processes = ${uwsgiprocs} +threads = ${uwsgiprocs} +enable-threads = true +socket = /rmm/api/tacticalrmm/tacticalrmm.sock +harakiri = 300 +chmod-socket = 660 +buffer-size = 65535 +vacuum = true +die-on-term = true +max-requests = 500 +EOF +)" +echo "${uwsgini}" > /rmm/api/tacticalrmm/app.ini + cp $tmp_dir/rmm/local_settings.py /rmm/api/tacticalrmm/tacticalrmm/ cp $tmp_dir/rmm/env /rmm/web/.env -cp $tmp_dir/rmm/app.ini /rmm/api/tacticalrmm/ gzip -d $tmp_dir/rmm/debug.log.gz cp $tmp_dir/rmm/debug.log /rmm/api/tacticalrmm/tacticalrmm/private/log/ cp $tmp_dir/rmm/mesh*.exe /rmm/api/tacticalrmm/tacticalrmm/private/exe/ diff --git a/update.sh b/update.sh index 0bb46d1a..342ed90f 100644 --- a/update.sh +++ b/update.sh @@ -1,6 +1,6 @@ #!/bin/bash -SCRIPT_VERSION="112" +SCRIPT_VERSION="113" SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/update.sh' LATEST_SETTINGS_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/api/tacticalrmm/tacticalrmm/settings.py' YELLOW='\033[1;33m' @@ -172,6 +172,37 @@ printf >&2 "${GREEN}Stopping ${i} service...${NC}\n" sudo systemctl stop ${i} done +rm -f /rmm/api/tacticalrmm/app.ini + +numprocs=$(nproc) +uwsgiprocs=4 +if [[ "$numprocs" == "1" ]]; then + uwsgiprocs=2 +else + uwsgiprocs=$numprocs +fi + +uwsgini="$(cat << EOF +[uwsgi] +chdir = /rmm/api/tacticalrmm +module = tacticalrmm.wsgi +home = /rmm/api/env +master = true +processes = ${uwsgiprocs} +threads = ${uwsgiprocs} +enable-threads = true +socket = /rmm/api/tacticalrmm/tacticalrmm.sock +harakiri = 300 +chmod-socket = 660 +buffer-size = 65535 +vacuum = true +die-on-term = true +max-requests = 500 +EOF +)" +echo "${uwsgini}" > /rmm/api/tacticalrmm/app.ini + + # forgot to add this in install script. catch any installs that don't have it enabled and enable it sudo systemctl enable natsapi.service @@ -230,15 +261,6 @@ sudo chown -R $USER:$GROUP /home/${USER}/.cache sudo chown ${USER}:${USER} -R /etc/letsencrypt sudo chmod 775 -R /etc/letsencrypt -CHECK_BUFF_SIZE=$(grep buffer-size /rmm/api/tacticalrmm/app.ini) -if ! [[ $CHECK_BUFF_SIZE ]]; then -setbuff="$(cat << EOF -buffer-size = 65535 -EOF -)" -echo "${setbuff}" | tee --append /rmm/api/tacticalrmm/app.ini > /dev/null -fi - CHECK_REMOVE_SALT=$(grep KEEP_SALT /rmm/api/tacticalrmm/tacticalrmm/local_settings.py) if ! [[ $CHECK_REMOVE_SALT ]]; then printf >&2 "${YELLOW}This update removes salt from the rmm${NC}\n"