2022-11-26 19:48:19 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
|
|
|
|
2022-11-28 18:08:44 +01:00
|
|
|
final_path=/opt/yunohost/$app
|
2022-11-26 19:48:19 +01:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Finding an available port..." --weight=1
|
|
|
|
|
|
|
|
# Find an available port
|
2022-11-28 18:08:44 +01:00
|
|
|
port=$(ynh_find_port --port=9200)
|
2022-11-26 19:48:19 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
2022-11-29 22:01:57 +01:00
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
|
2022-11-26 19:48:19 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=1
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2022-11-28 18:08:44 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=15
|
2022-11-26 19:48:19 +01:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-01-04 16:03:46 +01:00
|
|
|
ynh_setup_source --dest_dir="$final_path" --source_id="$YNH_ARCH"
|
2022-11-26 19:48:19 +01:00
|
|
|
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
2022-11-28 18:08:44 +01:00
|
|
|
chown -R $app:$app "$final_path"
|
2022-11-26 19:48:19 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DATA DIRECTORY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a data directory..." --weight=1
|
|
|
|
|
|
|
|
datadir=/home/yunohost.app/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
|
|
|
|
|
|
|
mkdir -p $datadir
|
|
|
|
|
|
|
|
chmod 750 "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
|
|
|
chown -R $app:www-data "$datadir"
|
|
|
|
|
2022-11-28 18:08:44 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE PID DIRECTORY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
mkdir -p "/run/$app"
|
|
|
|
|
|
|
|
chmod 700 "/run/$app"
|
|
|
|
chown $app:$app "/run/$app"
|
|
|
|
|
2022-11-26 19:48:19 +01:00
|
|
|
#=================================================
|
2022-11-29 22:01:57 +01:00
|
|
|
# ADD CONFIGURATIONS
|
2022-11-26 19:48:19 +01:00
|
|
|
#=================================================
|
2022-11-29 22:01:57 +01:00
|
|
|
ynh_script_progression --message="Adding the configuration files..." --weight=1
|
2022-11-26 19:48:19 +01:00
|
|
|
|
2023-01-05 17:12:12 +01:00
|
|
|
ynh_add_config --template="elasticsearch.yml" --destination="$final_path/config/elasticsearch.yml"
|
2022-11-29 22:01:57 +01:00
|
|
|
ynh_add_config --template="jvm.options" --destination="$final_path/config/jvm.options.d/yunohost.options"
|
2022-11-28 18:08:44 +01:00
|
|
|
|
2023-01-05 17:12:12 +01:00
|
|
|
chmod 400 "$final_path/config/elasticsearch.yml" "$final_path/config/jvm.options.d/yunohost.options"
|
|
|
|
chown $app:$app "$final_path/config/elasticsearch.yml" "$final_path/config/jvm.options.d/yunohost.options"
|
2022-11-26 19:48:19 +01:00
|
|
|
|
2023-01-04 16:06:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INCREASE MAX_MAP_COUNT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Increasing maximum map count (sysctl)..."
|
|
|
|
|
|
|
|
# Increase the maximum number of files inotify can monitor.
|
2023-01-05 17:12:12 +01:00
|
|
|
cp -a ../conf/90-max_map_count-elasticsearch.conf /etc/sysctl.d/
|
2023-01-04 16:06:57 +01:00
|
|
|
# Then, reload the kernel configuration.
|
2023-01-05 17:38:27 +01:00
|
|
|
if ! [ "$container" = "lxc" ] # lxc doesn't allow sysctl to play with kernel options.
|
2023-01-04 16:06:57 +01:00
|
|
|
then
|
2023-01-05 17:12:12 +01:00
|
|
|
sysctl -p /etc/sysctl.d/90-max_map_count-elasticsearch.conf
|
2023-01-04 16:06:57 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2022-11-26 19:48:19 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
|
2023-01-05 17:12:12 +01:00
|
|
|
yunohost service add $app --description="ElasticSearch - Distributed and RESTful search engine" --log="/var/log/$app/$app.log"
|
2022-11-26 19:48:19 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|