From 8d7d47ef07ddacd1a18fb2a7c547d98b58126b47 Mon Sep 17 00:00:00 2001 From: Limezy Date: Thu, 16 Jun 2022 14:40:10 +0700 Subject: [PATCH] Trying with swap --- scripts/_common.sh | 1 + scripts/install | 18 +++++++++++++++++- scripts/remove | 3 +++ scripts/upgrade | 18 +++++++++++++++++- scripts/ynh_add_swap | 1 - 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 061b880..cf42455 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,6 +7,7 @@ # Tag name of the installed version PHOTOPRISM_VERSION="220528-efb5d710" +MEMORY_NEEDED="2560" NODEJS_VERSION=14 GO_VERSION="1.18" diff --git a/scripts/install b/scripts/install index a852e73..2985f9e 100755 --- a/scripts/install +++ b/scripts/install @@ -84,6 +84,22 @@ ynh_install_nodejs --nodejs_version=$NODEJS_VERSION 2>&1 # Install go ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION +#================================================= +# ADD SWAP IF NEEDED +#================================================= +ynh_script_progression --message="Adding swap is needed..." + +total_memory=$(ynh_get_ram --total) +swap_needed=0 + +if [ $total_memory -lt $MEMORY_NEEDED ]; then + # Need a minimum of 2.5Go of memory + swap_needed=$(($MEMORY_NEEDED - $total_memory)) +fi + +ynh_script_progression --message="Adding $swap_needed Mo to swap..." +ynh_add_swap --size=$swap_needed + #================================================= # CREATE DEDICATED USER #================================================= @@ -147,7 +163,7 @@ pushd "$final_path" # Setup tensorflow library ./scripts/dist/install-tensorflow.sh # Setup node environment - export NODE_OPTIONS=--max_old_space_size=800 + export NODE_OPTIONS=--max_old_space_size=2048 # Build server from source ynh_use_nodejs env "$ynh_node_load_PATH" npm install -g npm diff --git a/scripts/remove b/scripts/remove index b4c79e2..999f187 100755 --- a/scripts/remove +++ b/scripts/remove @@ -118,6 +118,9 @@ ynh_secure_remove --file="/etc/cron.d/$app" # Remove the log files ynh_secure_remove --file="/var/log/$app" +# Remove swap +ynh_del_swap + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index afc4331..afa7760 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -104,6 +104,22 @@ ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 ynh_install_app_dependencies $pkg_dependencies +#================================================= +# ADD SWAP IF NEEDED +#================================================= +ynh_script_progression --message="Adding swap is needed..." + +total_memory=$(ynh_get_ram --total) +swap_needed=0 + +if [ $total_memory -lt $MEMORY_NEEDED ]; then + # Need a minimum of 2.5Go of memory + swap_needed=$(($MEMORY_NEEDED - $total_memory)) +fi + +ynh_script_progression --message="Adding $swap_needed Mo to swap..." +ynh_add_swap --size=$swap_needed + #================================================= # BUILD PHOTOPRISM @@ -119,7 +135,7 @@ pushd "$final_path" # Setup tensorflow library ./scripts/dist/install-tensorflow.sh # Setup node environment - export NODE_OPTIONS=--max_old_space_size=800 + export NODE_OPTIONS=--max_old_space_size=2048 # Build server from source ynh_use_nodejs env "$ynh_node_load_PATH" npm install -g npm diff --git a/scripts/ynh_add_swap b/scripts/ynh_add_swap index 83e11f5..2fd2d8c 100644 --- a/scripts/ynh_add_swap +++ b/scripts/ynh_add_swap @@ -51,7 +51,6 @@ ynh_add_swap () { # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case if ! fallocate -l ${swap_size}K /swap_$app then - echo "I'm also in !" dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} fi chmod 0600 /swap_$app