mirror of
https://github.com/YunoHost-Apps/elasticsearch7_ynh.git
synced 2024-09-03 18:26:25 +02:00
Use config_panel to customize heap size
This commit is contained in:
parent
b16fe0e8e6
commit
2fddcb9d5e
7 changed files with 101 additions and 197 deletions
23
conf/jvm.options
Normal file
23
conf/jvm.options
Normal file
|
@ -0,0 +1,23 @@
|
|||
## JVM configuration
|
||||
|
||||
################################################################
|
||||
## IMPORTANT: JVM heap size
|
||||
################################################################
|
||||
##
|
||||
## You should always set the min and max JVM heap
|
||||
## size to the same value. For example, to set
|
||||
## the heap to 4 GB, set:
|
||||
##
|
||||
## -Xms4g
|
||||
## -Xmx4g
|
||||
##
|
||||
## See https://opensearch.org/docs/opensearch/install/important-settings/
|
||||
## for more information
|
||||
##
|
||||
################################################################
|
||||
|
||||
# Xms represents the initial size of total heap space
|
||||
# Xmx represents the maximum size of total heap space
|
||||
|
||||
-Xms__XMS__
|
||||
-Xmx__XMX__
|
37
config_panel.toml
Normal file
37
config_panel.toml
Normal file
|
@ -0,0 +1,37 @@
|
|||
version = "1.0"
|
||||
|
||||
[main]
|
||||
|
||||
name.en = "OpenSearch configuration"
|
||||
name.fr = "Configuration d'OpenSearch"
|
||||
|
||||
services = ["__APP__"]
|
||||
|
||||
[main.jvm]
|
||||
name.en = "JVM (Java Virtual Machine) configuration"
|
||||
name.fr = "Configuration de la JVM (machine virtuelle Java)"
|
||||
optional = false
|
||||
|
||||
[main.jvm.xms]
|
||||
ask.en = "Initial heap space"
|
||||
ask.fr = "Espace initial réservé pour le tas (ou « Heap »)"
|
||||
help = """\
|
||||
Indicate a size followed by a unit (either m for megabytes or g for gigabytes) with no space. Examples: \
|
||||
"512m"\
|
||||
"2g"\
|
||||
"""
|
||||
type = "string"
|
||||
pattern.regexp = '^(\d+)[mMgG]$'
|
||||
pattern.error = "Please respect the format describe in help text"
|
||||
|
||||
[main.jvm.xmx]
|
||||
ask.en = "Maximum heap space"
|
||||
ask.fr = "Espace maximal pour le tas (ou « Heap »)"
|
||||
help = """\
|
||||
Indicate a size followed by a unit (either m for megabytes or g for gigabytes) with no space. Examples: \
|
||||
"512m"\
|
||||
"2g"\
|
||||
"""
|
||||
type = "string"
|
||||
pattern.regexp = '^(\d+)[mMgG]$'
|
||||
pattern.error = "Please respect the format describe in help text"
|
Binary file not shown.
Before Width: | Height: | Size: 35 KiB |
|
@ -1,134 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
old_domain=$YNH_APP_OLD_DOMAIN
|
||||
old_path=$YNH_APP_OLD_PATH
|
||||
|
||||
new_domain=$YNH_APP_NEW_DOMAIN
|
||||
new_path=$YNH_APP_NEW_PATH
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
# Needed for helper "ynh_add_nginx_config"
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
# Add settings here as needed by your application
|
||||
#db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
#db_user=$db_name
|
||||
#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
|
||||
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
|
||||
# Restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# CHECK WHICH PARTS SHOULD BE CHANGED
|
||||
#=================================================
|
||||
|
||||
change_domain=0
|
||||
if [ "$old_domain" != "$new_domain" ]
|
||||
then
|
||||
change_domain=1
|
||||
fi
|
||||
|
||||
change_path=0
|
||||
if [ "$old_path" != "$new_path" ]
|
||||
then
|
||||
change_path=1
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
|
||||
|
||||
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
|
||||
# Change the path in the NGINX config file
|
||||
if [ $change_path -eq 1 ]
|
||||
then
|
||||
# Make a backup of the original NGINX config file if modified
|
||||
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
|
||||
# Set global variables for NGINX helper
|
||||
domain="$old_domain"
|
||||
path_url="$new_path"
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
fi
|
||||
|
||||
# Change the domain for NGINX
|
||||
if [ $change_domain -eq 1 ]
|
||||
then
|
||||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum --file="$nginx_conf_path"
|
||||
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||
# Store file checksum for the new config file location
|
||||
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC MODIFICATIONS
|
||||
#=================================================
|
||||
# ...
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Change of URL completed for $app" --last
|
|
@ -1,10 +1,10 @@
|
|||
#!/bin/bash
|
||||
# In simple cases, you don't need a config script.
|
||||
# In simple cases, you don't need a config script.
|
||||
|
||||
# With a simple config_panel.toml, you can write in the app settings, in the
|
||||
# With a simple config_panel.toml, you can write in the app settings, in the
|
||||
# upstream config file or replace complete files (logo ...) and restart services.
|
||||
|
||||
# The config scripts allows you to go further, to handle specific cases
|
||||
# The config scripts allows you to go further, to handle specific cases
|
||||
# (validation of several interdependent fields, specific getter/setter for a value,
|
||||
# display dynamic informations or choices, pre-loading of config type .cube... ).
|
||||
|
||||
|
@ -28,72 +28,36 @@ final_path=$(ynh_app_setting_get $app final_path)
|
|||
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||
#=================================================
|
||||
|
||||
get__amount() {
|
||||
# Here we can imagine to have an API call to stripe to know the amount of donation during a month
|
||||
local amount = 200
|
||||
|
||||
# It's possible to change some properties of the question by overriding it:
|
||||
if [ $amount -gt 100 ]
|
||||
then
|
||||
cat << EOF
|
||||
style: success
|
||||
value: $amount
|
||||
ask:
|
||||
en: A lot of donation this month: **$amount €**
|
||||
EOF
|
||||
else
|
||||
cat << EOF
|
||||
style: danger
|
||||
value: $amount
|
||||
ask:
|
||||
en: Not so much donation this month: $amount €
|
||||
EOF
|
||||
fi
|
||||
get__xms() {
|
||||
ynh_app_setting_get --app=$app --key=xms
|
||||
}
|
||||
|
||||
get__prices() {
|
||||
local prices = "$(grep "DONATION\['" "$final_path/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')"
|
||||
if [ "$prices" == "," ];
|
||||
then
|
||||
# Return YNH_NULL if you prefer to not return a value at all.
|
||||
echo YNH_NULL
|
||||
else
|
||||
echo $prices
|
||||
fi
|
||||
get__xmx() {
|
||||
ynh_app_setting_get --app=$app --key=xmx
|
||||
}
|
||||
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
||||
#=================================================
|
||||
validate__publishable_key() {
|
||||
|
||||
# We can imagine here we test if the key is really a publisheable key
|
||||
(is_secret_key $publishable_key) &&
|
||||
echo 'This key seems to be a secret key'
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
||||
#=================================================
|
||||
set__prices() {
|
||||
|
||||
#---------------------------------------------
|
||||
# IMPORTANT: setter are trigger only if a change is detected
|
||||
#---------------------------------------------
|
||||
for price in $(echo $prices | sed "s/,/ /"); do
|
||||
frequency=$(echo $price | cut -d/ -f1)
|
||||
currency=$(echo $price | cut -d/ -f2)
|
||||
price_id=$(echo $price | cut -d/ -f3)
|
||||
sed "d/DONATION\['$frequency'\]\['$currency'\]" "$final_path/settings.py"
|
||||
regenerate_jvm_options() {
|
||||
ynh_add_config --template="jvm.options" --destination="$final_path/config/jvm.options.d/yunohost.options"
|
||||
chown $app:$app "$final_path/config/jvm.options.d/yunohost.options"
|
||||
chmod 400 "$final_path/config/jvm.options.d/yunohost.options"
|
||||
}
|
||||
|
||||
echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$final_path/settings.py"
|
||||
done
|
||||
|
||||
#---------------------------------------------
|
||||
# IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too
|
||||
#---------------------------------------------
|
||||
ynh_app_setting_set $app prices $prices
|
||||
set__xms() {
|
||||
ynh_app_setting_set --app=$app --key=xms --value=$xms
|
||||
regenerate_jvm_options
|
||||
}
|
||||
|
||||
set__xmx() {
|
||||
ynh_app_setting_set --app=$app --key=xmx --value=$xmx
|
||||
regenerate_jvm_options
|
||||
}
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -41,6 +41,16 @@ ynh_script_progression --message="Finding an available port..." --weight=1
|
|||
port=$(ynh_find_port --port=9200)
|
||||
ynh_app_setting_set --app=$app --key=port --value=$port
|
||||
|
||||
#=================================================
|
||||
# DEFAULT VALUES FOR CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
xms=256m
|
||||
ynh_app_setting_set --app=$app --key=xms --value=$xms
|
||||
|
||||
xmx=1g
|
||||
ynh_app_setting_set --app=$app --key=xmx --value=$xmx
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
@ -98,14 +108,15 @@ chmod 700 "/run/$app"
|
|||
chown $app:$app "/run/$app"
|
||||
|
||||
#=================================================
|
||||
# ADD A CONFIGURATION
|
||||
# ADD CONFIGURATIONS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
||||
ynh_script_progression --message="Adding the configuration files..." --weight=1
|
||||
|
||||
ynh_add_config --template="opensearch.yml" --destination="$final_path/config/opensearch.yml"
|
||||
ynh_add_config --template="jvm.options" --destination="$final_path/config/jvm.options.d/yunohost.options"
|
||||
|
||||
chmod 400 "$final_path/config/opensearch.yml"
|
||||
chown $app:$app "$final_path/config/opensearch.yml"
|
||||
chmod 400 "$final_path/config/opensearch.yml" "$final_path/config/jvm.options.d/yunohost.options"
|
||||
chown $app:$app "$final_path/config/opensearch.yml" "$final_path/config/jvm.options.d/yunohost.options"
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
|
|
|
@ -19,6 +19,8 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
xms=$(ynh_app_setting_get --app=$app --key=xms)
|
||||
xmx=$(ynh_app_setting_get --app=$app --key=xmx)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
|
@ -92,7 +94,7 @@ then
|
|||
ynh_script_progression --message="Upgrading source files..." --weight=20
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$final_path" --keep="config/opensearch.yml"
|
||||
ynh_setup_source --dest_dir="$final_path" --keep="config/opensearch.yml config/jvm.options.d/yunohost.conf"
|
||||
fi
|
||||
|
||||
chmod 750 "$final_path"
|
||||
|
@ -112,9 +114,10 @@ ynh_install_app_dependencies $pkg_dependencies
|
|||
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
||||
|
||||
ynh_add_config --template="opensearch.yml" --destination="$final_path/config/opensearch.yml"
|
||||
ynh_add_config --template="jvm.options" --destination="$final_path/config/jvm.options.d/yunohost.options"
|
||||
|
||||
chmod 400 "$final_path/config/opensearch.yml"
|
||||
chown $app:$app "$final_path/config/opensearch.yml"
|
||||
chmod 400 "$final_path/config/opensearch.yml" "$final_path/config/jvm.options.d/yunohost.options"
|
||||
chown $app:$app "$final_path/config/opensearch.yml" "$final_path/config/jvm.options.d/yunohost.options"
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
|
|
Loading…
Reference in a new issue