1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/influxdb_v2_ynh.git synced 2024-09-03 19:26:11 +02:00
influxdb_v2_ynh/scripts/install
2024-07-22 21:39:49 +02:00

84 lines
3.5 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS AND SETTINGS
#=================================================
influxdb_admin_token=$(ynh_string_random --length=64 --filter='A-Za-z0-9-_')
# Check if the retention value is valid
if ! echo "$influxdb_bucket_retention" | grep -qE '^(0|[0-9]+(ns|u|µ|ms|s|m|h|d|w))$'; then
ynh_die --message="Invalid retention value. It should be either 0 (infinite) or a number followed by a duration unit (ns, u, µ, ms, s, m, h, d, w)."
fi
ynh_app_setting_set --app=$app --key=influxdb_org_name --value=$influxdb_org_name
ynh_app_setting_set --app=$app --key=influxdb_bucket_name --value=$influxdb_bucket_name
ynh_app_setting_set --app=$app --key=influxdb_bucket_retention --value=$influxdb_bucket_retention
ynh_app_setting_set --app=$app --key=influxdb_admin_token --value=$influxdb_admin_token
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_setup_source --dest_dir="$install_dir" --source_id=influxdb2
ynh_setup_source --dest_dir="$install_dir" --source_id=influx
chown -R "$app:www-data" "$install_dir"
#=================================================
# ADD CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="config.toml.example" --destination="$install_dir/config.toml"
chmod 400 "$install_dir/config.toml"
chown $app:$app "$install_dir/config.toml"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app" --template="systemd.service"
yunohost service add "$app" --description="Time-series database" --log="/var/log/$app/$app.log"
ynh_use_logrotate
#=================================================
# START AND ENABLE SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="enable"
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# APP INITIAL CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring $app ..." --weight=30
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="msg=Listening"
# First setup InfluxDB v2 using influx
ynh_exec_as $app $install_dir/influx setup --force --skip-verify --name default --configs-path $install_dir/.influxdbv2/configs --host http://localhost:$port --bucket $influxdb_bucket_name --org $influxdb_org_name --username $admin --password "$password" --retention $influxdb_bucket_retention --token $influxdb_admin_token
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last