#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --weight=23 ynh_exec_warn_less python3 -m pip install pipenv #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=64 # Set permissions to app files # mkdir -p "$install_dir/.venv" # chown -R $app:$app "$install_dir" # chmod -R g=u,g-w,o-rwx "$install_dir" # setfacl -nR -m g:$app.main:rx -m d:g:$app.main:rx "$install_dir/.venv" # setfacl -n -m g:$app.main:x "$install_dir" # pushd "$install_dir" # sudo -u $app PIPENV_VENV_IN_PROJECT="enabled" PIPENV_SKIP_LOCK=true python3 -m pipenv install jupyterlab==$jupyterlab_version jupyterhub notebook jupyter-server jupyterhub-ldapauthenticator pyzmq sudospawner 2>&1 # sudo -u $app python3 -m pipenv run jupyterhub upgrade-db 2>&1 # popd mkdir -p "$install_dir" # Set permissions to app files chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" pushd $install_dir mkdir -p .venv PIPENV_VENV_IN_PROJECT="enabled" PIPENV_SKIP_LOCK=true ynh_exec_warn_less python3 -m pipenv install fittrackee==$fittrackee_version python-dotenv popd #================================================= # CONFIGURE log file #================================================= ynh_script_progression --message="Configure log file" --weight=1 mkdir /var/log/$app/ touch /var/log/$app/$app.log chown -R $app: /var/log/$app/ #================================================= # CONFIGURE THE INSTALL SCRIPT #================================================= ynh_script_progression --message="Installing service script..." --weight=1 key=$(ynh_string_random --length=45 | base64) ynh_app_setting_set --app=$app --key=key --value=$key ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env" chmod 600 $install_dir/.env chown $app:www-data "$install_dir/.env" set -a; source "$install_dir/.env"; set +a mkdir "$install_dir/venv" python3 -m venv "$install_dir/venv" source $install_dir/.env #================================================= # INITIALIZE DATABASE #================================================= ynh_script_progression --message="Initializing database..." --weight=1 /var/www/fittrackee/.venv/bin/ftcli db upgrade #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config --service="${app}" --template="${app}.service" ynh_add_systemd_config --service="${app}_workers" --template="${app}_workers.service" mkdir /etc/systemd/system/${app}.service.d/ chown $app:www-data /etc/systemd/system/${app}.service.d/ ynh_add_config --template="../conf/variables_fittrackee_workers.conf" --destination="/etc/systemd/system/${app}.service.d/variables.conf" chmod 600 /etc/systemd/system/${app}.service.d/variables.conf chown $app:www-data "/etc/systemd/system/${app}.service.d/variables.conf" mkdir /etc/systemd/system/${app}_workers.service.d/ chown $app:www-data /etc/systemd/system/${app}_workers.service.d/ ynh_add_config --template="../conf/variables_fittrackee_workers.conf" --destination="/etc/systemd/system/${app}_workers.service.d/variables.conf" chmod 600 /etc/systemd/system/${app}_workers.service.d/variables.conf chown $app:www-data "/etc/systemd/system/${app}_workers.service.d/variables.conf" #================================================= # GENERIC FINALIZATION #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add "${app}" --log="/var/log/$app/$app.log" yunohost service add "${app}_workers" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name="${app}" --action="start" --log_path="/var/log/$app/$app.log" --line_match="Booting worker with pid" ynh_systemd_action --service_name="${app}_workers" --action="start" --log_path="systemd" --line_match="ready" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last