1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/FastAPI_ynh.git synced 2024-09-03 18:36:00 +02:00
fastapi_ynh/scripts/install

118 lines
No EOL
3.7 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
# Install parameters are automatically saved as settings
#
# Settings are automatically loaded as bash variables
# in every app script context, therefore typically these will exist:
# - $domain
# - $path
# - $language
# ... etc
#
# Resources defined in the manifest are provisioned prior to this script
# and corresponding settings are also available, such as:
# - $install_dir
# - $port
# - $db_name
# ...
#
# $app is the app id (i.e. 'example' for first install,
# or 'example__2', '__3', ... for multi-instance installs)
#
#=================================================
# 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
cp ../conf/requirements.txt "$data_dir/requirements.txt"
myynh_setup_python_venv
#=================================================
# copy config files
# ================================================
ynh_script_progression --message="Create $app configuration files..."
ynh_add_config --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py"
mkdir -p "$data_dir/FastAPIAppFolder"
ynh_add_config --template="__init__.py" --destination="$data_dir/FastAPIAppFolder/__init__.py"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Set file permissions..."
myynh_fix_file_permissions
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..."
# Create a dedicated nginx config
# https://yunohost.org/en/contribute/packaging_apps/helpers
# https://github.com/YunoHost/yunohost/blob/dev/helpers/nginx
ynh_add_nginx_config "public_path" "port"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5
ynh_add_systemd_config --service=$app --template="systemd.service"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app
#=================================================
# 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
#=================================================
ynh_script_progression --message="Installation of $app completed" --last