2023-11-28 13:20:48 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2023-11-28 15:45:06 +01:00
|
|
|
#=================================================
|
|
|
|
# SETTINGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
|
|
|
|
# Logging:
|
|
|
|
log_file="/var/log/$app/$app.log"
|
|
|
|
ynh_app_setting_set --app=$app --key=log_file --value="$log_file"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOG FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setup logging..."
|
|
|
|
|
|
|
|
myynh_setup_log_file
|
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate --logfile="$log_file" --specific_user=$app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PYTHON VIRTUALENV
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45
|
2023-12-01 15:47:37 +01:00
|
|
|
|
2023-12-01 16:50:49 +01:00
|
|
|
ynh_add_config --template="requirements.txt" --destination="$install_dir/requirements.txt"
|
2023-12-01 15:53:40 +01:00
|
|
|
|
2023-11-28 15:45:06 +01:00
|
|
|
myynh_setup_python_venv
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# copy config files
|
|
|
|
# ================================================
|
|
|
|
ynh_script_progression --message="Create $app configuration files..."
|
|
|
|
|
2023-12-01 16:50:49 +01:00
|
|
|
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
|
2023-11-28 15:45:06 +01:00
|
|
|
|
|
|
|
mkdir -p "$data_dir/FastAPIAppFolder"
|
|
|
|
ynh_add_config --template="__init__.py" --destination="$data_dir/FastAPIAppFolder/__init__.py"
|
|
|
|
|
2023-12-01 20:35:15 +01:00
|
|
|
# Add the password to this user
|
|
|
|
chpasswd <<< "${app}:${password}"
|
|
|
|
|
2023-11-28 15:45:06 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Set file permissions..."
|
|
|
|
|
2023-12-01 15:47:37 +01:00
|
|
|
myynh_fix_file_permissions
|
2023-11-28 15:45:06 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2023-12-01 15:47:37 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2023-11-28 15:45:06 +01:00
|
|
|
|
2023-12-01 15:47:37 +01:00
|
|
|
ynh_add_nginx_config
|
2023-11-28 15:45:06 +01:00
|
|
|
|
2023-12-01 15:53:40 +01:00
|
|
|
ynh_add_systemd_config
|
2023-11-28 15:45:06 +01:00
|
|
|
|
2023-12-01 15:47:37 +01:00
|
|
|
yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
|
2023-11-28 15:45:06 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Start the app server via systemd
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2023-12-01 20:35:15 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|