#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers key=$(ynh_string_random --length=32) ynh_app_setting_set --app=$app --key=key --value=$key #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" --source_id="main" ynh_setup_source --dest_dir="$install_dir/static/fonts/source_han_sans" --source_id="fonts" # Set permissions to app files chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= # CONFIGURE THEN INSTALL SCRIPT AND DEPENDENCIES #================================================= ynh_script_progression --message="Installing service script..." --weight=1 ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env" chmod 600 $install_dir/.env chown $app:www-data "$install_dir/.env" mkdir "$install_dir/venv" python3 -m venv "$install_dir/venv" $install_dir/venv/bin/pip3 install -r "$install_dir/requirements.txt" #================================================= # INITIALIZE DATABASE #================================================= ynh_script_progression --message="Initializing database..." --weight=1 pushd $install_dir $install_dir/venv/bin/python3 "$install_dir/manage.py" migrate $install_dir/venv/bin/python3 "$install_dir/manage.py" initdb $install_dir/venv/bin/python3 "$install_dir/manage.py" compile_themes $install_dir/venv/bin/python3 "$install_dir/manage.py" collectstatic --no-input popd #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # LOGROTATE CONFIGURATION #================================================= ynh_script_progression --message="Configuring logrotate..." --weight=1 # Use logrotate to manage application logfile(s) ynh_use_logrotate --specific_user=$app touch /var/log/$app/$app.log touch /var/log/$app/$app-beat.log touch /var/log/$app/$app-worker.log chown -R $app:www-data /var/log/$app/ #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=1 ynh_add_config --template="../conf/bookwyrm.target" --destination="/etc/systemd/system/$app.target" # Create a dedicated systemd config ynh_add_systemd_config --service="$app-server" --template="bookwyrm-server.service" ynh_add_systemd_config --service="$app-worker" --template="bookwyrm-worker.service" ynh_add_systemd_config --service="$app-beat" --template="bookwyrm-beat.service" #================================================= # GENERIC FINALIZATION #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log" yunohost service add "$app-server" --log="/var/log/$app/$app.log" yunohost service add "$app-worker" --log="/var/log/$app/$app-worker.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="systemd" --line_match="Started bookwyrm celery beat process" ynh_systemd_action --service_name="$app-server" --action="start" --log_path="systemd" --line_match="Booting worker with pid" ynh_systemd_action --service_name="$app-worker" --action="start" --log_path="systemd" --line_match="ready" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last