1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/superset_ynh.git synced 2024-09-03 20:26:31 +02:00
superset_ynh/scripts/install
2024-05-02 23:06:58 +02:00

90 lines
3.2 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# APP INITIAL CONFIGURATION
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding app's configuration file..."
secret_key=$(ynh_string_random --length=42)
ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key
ynh_add_config --template="superset_config.py" --destination="$install_dir/superset_config.py"
chmod 400 "$install_dir/superset_config.py"
chown $app:$app "$install_dir/superset_config.py"
#=================================================
# INSTALL APP
#=================================================
ynh_script_progression --message="Installing app..." --weight=5
# Prepare environment
python3 -m venv $install_dir/venv
localpath=$install_dir/venv/bin:$PATH
environment="FLASK_APP=superset SUPERSET_CONFIG_PATH=$install_dir/superset_config.py SUPERSET_SECRET_KEY=$secret_key"
export $environment
# Install and initialize Superset
pushd $install_dir
(
source venv/bin/activate
ynh_exec_warn_less env $environment pip3 install psycopg2 openpyxl python-ldap Pillow sqlalchemy-bigquery apache-superset==$(ynh_app_upstream_version)
ynh_exec_warn_less env $environment superset db upgrade
ynh_exec_warn_less env $environment superset init
deactivate
)
popd
chown -R $app:$app "$install_dir"
#=================================================
# CREATE AN ADDITIONAL DATABASE FOR USER DATA
#=================================================
userdata_db_user=${app}_userdata
userdata_db_name=$userdata_db_user
userdata_db_pwd=$(ynh_string_random)
ynh_psql_create_user "$userdata_db_user" "$userdata_db_pwd"
ynh_psql_create_db "$userdata_db_name" "$userdata_db_user"
ynh_app_setting_set --app=$app --key=userdata_db_user --value=$userdata_db_user
ynh_app_setting_set --app=$app --key=userdata_db_name --value=$userdata_db_name
ynh_app_setting_set --app=$app --key=userdata_db_pwd --value=$userdata_db_pwd
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..."
# Create a dedicated NGINX config using the conf/nginx.conf template
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add $app --log="/var/log/$app/$app.log"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Running on http" --timeout=30
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last