elasticsearch7_ynh/scripts/install

160 lines
5.4 KiB
Text
Raw Normal View History

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
#=================================================
# 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
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# 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_setup_source` is used to install an app from a zip or tar.gz file,
### downloaded from an upstream source, like a git repository.
### `ynh_setup_source` use the file conf/app.src
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
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
#=================================================
# ADD CONFIGURATIONS
2022-11-26 19:48:19 +01:00
#=================================================
ynh_script_progression --message="Adding the configuration files..." --weight=1
2022-11-26 19:48:19 +01:00
2022-11-28 18:08:44 +01:00
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"
2022-11-28 18:08:44 +01:00
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"
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
2022-11-28 18:08:44 +01:00
yunohost service add $app --description="OpenSearch - Open source 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