diff --git a/conf/development.ini.sample b/conf/development.ini.sample index 4887ecb..1a614b4 100644 --- a/conf/development.ini.sample +++ b/conf/development.ini.sample @@ -278,12 +278,12 @@ preview_cache_dir = %(basic_setup.preview_cache_dir)s ### pyramid_beaker parameters ### -session.type = file +session.type = ext:redis # needed for "file" storage config : ; session.data_dir = %(here)s/sessions_data session.data_dir = %(basic_setup.sessions_data_root_dir)s/sessions_data # needed for many session storage type, but not for file (leave as empty for file) -session.url = +session.url = redis://localhost:6379/__REDIS_DB__ ## "Redis" storage config sample: # session.type = ext:redis diff --git a/scripts/_common.sh b/scripts/_common.sh index e74ed09..d825d8a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="postgresql ghostscript git imagemagick iproute2 libfile-mimeinfo-perl libimage-exiftool-perl webp libmagic1 locales poppler-utils python3 python3-pip uwsgi uwsgi-plugin-python3 supervisor" +pkg_dependencies="postgresql ghostscript git imagemagick iproute2 libfile-mimeinfo-perl libimage-exiftool-perl webp libmagic1 locales poppler-utils python3 python3-pip uwsgi uwsgi-plugin-python3 supervisor redis-server" preview_pkg_dependencies="ffmpeg xvfb inkscape libreoffice" diff --git a/scripts/change_url b/scripts/change_url index 31a5a68..78148e6 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -139,7 +139,7 @@ chown $app:$app "$final_path/frontend/configEnv.json" ynh_script_progression --message="Starting a systemd service..." # Start a systemd service -ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app.log" --line_match="spawned uWSGI" +ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app-web.log" --line_match="spawned uWSGI" ynh_supervisor_action --service_name="$app" --action="restart" --log_path="/var/log/supervisor/supervisord.log" #================================================= diff --git a/scripts/install b/scripts/install index 4e1dcd5..51fa273 100755 --- a/scripts/install +++ b/scripts/install @@ -8,6 +8,7 @@ source _common.sh source ynh_supervisor +source ynh_redis source /usr/share/yunohost/helpers #================================================= @@ -146,6 +147,9 @@ chown -R $app:www-data "$datadir" #================================================= ynh_script_progression --message="Adding a configuration file..." +redis_db=$(ynh_redis_get_free_db) +ynh_app_setting_set --app=$app --key=redis_db --value=$redis_db + ynh_add_config --template="../conf/development.ini.sample" --destination="$final_path/backend/development.ini" chmod 400 "$final_path/backend/development.ini" chown $app:$app "$final_path/backend/development.ini" @@ -226,7 +230,7 @@ ln -sf /etc/uwsgi/apps-available/$app-caldav.ini /etc/uwsgi/apps-enabled/$app-ca #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add uwsgi --log="/var/log/uwsgi/app/$app.log" +yunohost service add uwsgi --log="/var/log/uwsgi/app/$app-web.log" yunohost service add supervisor --log="/var/log/supervisor/supervisord.log" #================================================= @@ -235,7 +239,7 @@ yunohost service add supervisor --log="/var/log/supervisor/supervisord.log" ynh_script_progression --message="Starting a systemd service..." # Start a systemd service -ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app.log" --line_match="spawned uWSGI" +ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app-web.log" --line_match="spawned uWSGI" ynh_supervisor_action --service_name="$app" --action="restart" --log_path="/var/log/supervisor/supervisord.log" #================================================= diff --git a/scripts/remove b/scripts/remove index ed52b56..bc2ffac 100755 --- a/scripts/remove +++ b/scripts/remove @@ -8,6 +8,7 @@ source _common.sh source ynh_supervisor +source ynh_redis source /usr/share/yunohost/helpers #================================================= @@ -23,6 +24,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) datadir=$(ynh_app_setting_get --app=$app --key=datadir) +redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) #================================================= # STANDARD REMOVE @@ -31,20 +33,15 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null +if ynh_exec_warn_less yunohost service status uwsgi >/dev/null then - ynh_script_progression --message="Removing $app service integration..." - yunohost service remove $app + ynh_script_progression --message="Removing uwsgi service integration..." + yunohost service remove uwsgi fi -if ynh_exec_warn_less yunohost service status $app-webdav >/dev/null +if ynh_exec_warn_less yunohost service status supervisor >/dev/null then - ynh_script_progression --message="Removing $app-webdav service integration..." - yunohost service remove $app-webdav -fi -if ynh_exec_warn_less yunohost service status $app-caldav >/dev/null -then - ynh_script_progression --message="Removing $app-caldav service integration..." - yunohost service remove $app-caldav + ynh_script_progression --message="Removing supervisor service integration..." + yunohost service remove supervisor fi #================================================= @@ -61,7 +58,7 @@ ynh_secure_remove --file="/etc/uwsgi/apps-enabled/$app-webdav.ini" ynh_secure_remove --file="/etc/uwsgi/apps-available/$app-webdav.ini" ynh_secure_remove --file="/etc/uwsgi/apps-enabled/$app-caldav.ini" ynh_secure_remove --file="/etc/uwsgi/apps-available/$app-caldav.ini" -ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app.log" --line_match="spawned uWSGI" +ynh_systemd_action --service_name="uwsgi" --action="restart" #================================================= # REMOVE THE POSTGRESQL DATABASE @@ -104,11 +101,22 @@ ynh_remove_nginx_config ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies +ynh_redis_remove_db "$redis_db" ynh_remove_nodejs ynh_remove_app_dependencies #================================================= # SPECIFIC REMOVE +#================================================= +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing various files..." + +# Remove the log files +ynh_secure_remove --file="/var/log/uwsgi/app/$app-web.log" +ynh_secure_remove --file="/var/log/uwsgi/app/$app-webdav.log" +ynh_secure_remove --file="/var/log/uwsgi/app/$app-caldav.log" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index cdbc5c8..56a5e6c 100755 --- a/scripts/restore +++ b/scripts/restore @@ -138,7 +138,7 @@ supervisorctl update #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add uwsgi --log="/var/log/uwsgi/app/$app.log" +yunohost service add uwsgi --log="/var/log/uwsgi/app/$app-web.log" yunohost service add supervisor --log="/var/log/supervisor/supervisord.log" #================================================= @@ -147,7 +147,7 @@ yunohost service add supervisor --log="/var/log/supervisor/supervisord.log" ynh_script_progression --message="Starting a systemd service..." # Start a systemd service -ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app.log" --line_match="spawned uWSGI" +ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app-web.log" --line_match="spawned uWSGI" ynh_supervisor_action --service_name="$app" --action="restart" --log_path="/var/log/supervisor/supervisord.log" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 40d84b1..c40f3e5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,6 +8,7 @@ source _common.sh source ynh_supervisor +source ynh_redis source /usr/share/yunohost/helpers #================================================= @@ -29,6 +30,7 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir) api_key=$(ynh_app_setting_get --app=$app --key=api_key) session_secret=$(ynh_app_setting_get --app=$app --key=session_secret) website_title=$(ynh_app_setting_get --app=$app --key=website_title) +redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) #================================================= # CHECK VERSION @@ -200,7 +202,7 @@ ln -sf /etc/uwsgi/apps-available/$app-caldav.ini /etc/uwsgi/apps-enabled/$app-ca #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add uwsgi --log="/var/log/uwsgi/app/$app.log" +yunohost service add uwsgi --log="/var/log/uwsgi/app/$app-web.log" yunohost service add supervisor --log="/var/log/supervisor/supervisord.log" #================================================= @@ -209,7 +211,7 @@ yunohost service add supervisor --log="/var/log/supervisor/supervisord.log" ynh_script_progression --message="Starting a systemd service..." # Start a systemd service -ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app.log" --line_match="spawned uWSGI" +ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app-web.log" --line_match="spawned uWSGI" ynh_supervisor_action --service_name="$app" --action="restart" --log_path="/var/log/supervisor/supervisord.log" #================================================= diff --git a/scripts/ynh_redis b/scripts/ynh_redis new file mode 100644 index 0000000..9d6257d --- /dev/null +++ b/scripts/ynh_redis @@ -0,0 +1,39 @@ +#!/bin/bash + +# get the first available redis database +# +# usage: ynh_redis_get_free_db +# | returns: the database number to use +ynh_redis_get_free_db() { + local result max db + result=$(redis-cli INFO keyspace) + + # get the num + max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") + + db=0 + # default Debian setting is 15 databases + for i in $(seq 0 "$max") + do + if ! echo "$result" | grep -q "db$i" + then + db=$i + break 1 + fi + db=-1 + done + + test "$db" -eq -1 && ynh_die --message="No available Redis databases..." + + echo "$db" +} + +# Create a master password and set up global settings +# Please always call this script in install and restore scripts +# +# usage: ynh_redis_remove_db database +# | arg: database - the database to erase +ynh_redis_remove_db() { + local db=$1 + redis-cli -n "$db" flushall +}