mirror of
https://github.com/YunoHost-Apps/pleroma_ynh.git
synced 2024-09-03 20:15:59 +02:00
Added option for cache
This commit is contained in:
parent
9be3bffef3
commit
daa502814c
9 changed files with 74 additions and 1 deletions
|
@ -9,6 +9,8 @@
|
|||
admin="john" (USER)
|
||||
name="pleroma"
|
||||
registration=0 (BOOLEAN)
|
||||
cache=1 (BOOLEAN)
|
||||
size="5g"
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
|
|
2
conf/cache.conf
Normal file
2
conf/cache.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
proxy_cache_path /tmp/{APP}-media-cache levels=1:2 keys_zone={APP}_media_cache:10m max_size=__SIZE__
|
||||
inactive=720m use_temp_path=off;
|
6
conf/media.conf
Normal file
6
conf/media.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
location /proxy {
|
||||
proxy_cache {APP}_media_cache;
|
||||
proxy_cache_lock on;
|
||||
proxy_ignore_client_abort on;
|
||||
proxy_pass http://localhost:__PORT__;
|
||||
}
|
|
@ -51,6 +51,22 @@
|
|||
},
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"name": "cache",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Enable media-chache for your instance"
|
||||
},
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"name": "size",
|
||||
"ask": {
|
||||
"en": "Select the cache size (2g,5g,10g,20g,40g,80g)"
|
||||
},
|
||||
"choices": ["2g","5g","10g","20g","40g","80g"],
|
||||
"default": "5g"
|
||||
},
|
||||
{
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
|
|
|
@ -33,6 +33,7 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
db_name=$(ynh_app_setting_get "$app" psql_db)
|
||||
cache=$(ynh_app_setting_get "$app" cache)
|
||||
|
||||
# Stop Pleroma for backup
|
||||
systemctl stop "$app"
|
||||
|
@ -51,6 +52,11 @@ ynh_backup "$final_path"
|
|||
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
if [ $cache -eq 1 ]
|
||||
then
|
||||
ynh_backup "/etc/nginx/conf.d/$app-cache.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE PostgreSQL DATABASE
|
||||
#=================================================
|
||||
|
|
|
@ -30,7 +30,8 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
|
|||
random_key=$(ynh_random 64)
|
||||
name=$YNH_APP_ARG_NAME
|
||||
registration=$YNH_APP_ARG_REGISTRATION
|
||||
|
||||
cache=$YNH_APP_ARG_CACHE
|
||||
size=$YNH_APP_ARG_SIZE
|
||||
|
||||
# This is a multi-instance app, meaning it can be installed several times independently
|
||||
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||
|
@ -67,6 +68,9 @@ ynh_app_setting_set "$app" random_key "$random_key"
|
|||
ynh_app_setting_set "$app" admin "$admin"
|
||||
ynh_app_setting_set "$app" name "$name"
|
||||
ynh_app_setting_set "$app" registration "$registration"
|
||||
ynh_app_setting_set "$app" cache "$cache"
|
||||
ynh_app_setting_set "$app" size "$size"
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
|
@ -139,6 +143,17 @@ git clone https://git.pleroma.social/pleroma/pleroma "$final_path/$app"
|
|||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
if [ $cache -eq 1 ]
|
||||
then
|
||||
cp -rf "../conf/cache.conf" "/etc/nginx/conf.d/$app-cache.conf"
|
||||
ynh_replace_string "{APP}" "$app" "/etc/nginx/conf.d/$app-cache.conf"
|
||||
ynh_replace_string "__SIZE__" "$size" "/etc/nginx/conf.d/$app-cache.conf"
|
||||
ynh_store_file_checksum "/etc/nginx/conf.d/$app-cache.conf"
|
||||
ynh_replace_string "{APP}" "$app" "../conf/media.conf"
|
||||
ynh_replace_string "__PORT__" "$port" "../conf/media.conf"
|
||||
sudo su -c "cat ../conf/media.conf >> /etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
|
|
|
@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get "$app" domain)
|
|||
port=$(ynh_app_setting_get "$app" port)
|
||||
db_name=$(ynh_app_setting_get "$app" psql_db)
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
cache=$(ynh_app_setting_get "$app" cache)
|
||||
|
||||
# STOP AND REMOVE SERVICE
|
||||
#=================================================
|
||||
|
@ -57,6 +58,7 @@ ynh_psql_remove_db "$db_name" "$app"
|
|||
# Remove the app directory securely
|
||||
ynh_secure_remove "$final_path"
|
||||
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
@ -64,6 +66,11 @@ ynh_secure_remove "$final_path"
|
|||
# Remove the dedicated nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
if [ $cache -eq 1 ]
|
||||
then
|
||||
rm -f /etc/nginx/conf.d/$app-cache.conf
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# CLOSE A PORT
|
||||
#=================================================
|
||||
|
|
|
@ -37,6 +37,7 @@ final_path=$(ynh_app_setting_get "$app" final_path)
|
|||
port=$(ynh_app_setting_get "$app" port)
|
||||
db_name=$(ynh_app_setting_get "$app" psql_db)
|
||||
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
|
||||
cache=$(ynh_app_setting_get "$app" cache)
|
||||
|
||||
|
||||
#=================================================
|
||||
|
@ -55,6 +56,10 @@ test ! -d "$final_path" \
|
|||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
if [ $cache -eq 1 ]
|
||||
then
|
||||
ynh_restore_file "/etc/nginx/conf.d/$app-cache.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
|
|
|
@ -27,6 +27,8 @@ name=$(ynh_app_setting_get "$app" name)
|
|||
port=$(ynh_app_setting_get "$app" port)
|
||||
db_name=$(ynh_app_setting_get "$app" psql_db)
|
||||
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
|
||||
cache=$(ynh_app_setting_get "$app" cache)
|
||||
size=$(ynh_app_setting_get "$app" size)
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
|
@ -118,6 +120,18 @@ chown -R "$app":"$app" "$final_path"
|
|||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
if [ $cache -eq 1 ]
|
||||
then
|
||||
rm -f /etc/nginx/conf.d/$app-cache.conf
|
||||
cp -rf "../conf/cache.conf" "/etc/nginx/conf.d/$app-cache.conf"
|
||||
ynh_replace_string "{APP}" "$app" "/etc/nginx/conf.d/$app-cache.conf"
|
||||
ynh_replace_string "__SIZE__" "$size" "/etc/nginx/conf.d/$app-cache.conf"
|
||||
ynh_store_file_checksum "/etc/nginx/conf.d/$app-cache.conf"
|
||||
ynh_replace_string "{APP}" "$app" "../conf/media.conf"
|
||||
ynh_replace_string "__PORT__" "$port" "../conf/media.conf"
|
||||
sudo su -c "cat ../conf/media.conf >> /etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
fi
|
||||
|
||||
|
||||
# Recalculate and store the config file checksum into the app settings
|
||||
|
|
Loading…
Add table
Reference in a new issue