mirror of
https://github.com/YunoHost-Apps/etherpad_ynh.git
synced 2024-09-03 18:36:10 +02:00
Add redis
This commit is contained in:
parent
a0b53c5036
commit
d0fae45719
6 changed files with 65 additions and 48 deletions
|
@ -20,14 +20,12 @@
|
|||
* https://www.npmjs.com/package/ueberdb2
|
||||
*/
|
||||
|
||||
/* An Example of MySQL Configuration */
|
||||
"dbType" : "postgres",
|
||||
/* An Example of Redis Configuration */
|
||||
"dbType" : "redis",
|
||||
"dbSettings" : {
|
||||
"user" : "__DB_NAME__",
|
||||
"host" : "localhost",
|
||||
"port" : 5432,
|
||||
"password": "__DB_PWD__",
|
||||
"database": "__DB_NAME__"
|
||||
"port" : 6379,
|
||||
"database": "__REDIS_DB__"
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
||||
# dependencies used by the app
|
||||
pkg_dependencies="postgresql postgresql-contrib"
|
||||
|
||||
nodejs_version=14
|
||||
|
||||
# Dependencies for AbiWord
|
||||
|
@ -26,3 +23,41 @@ libreoffice_app_dependencies="unoconv libreoffice-writer"
|
|||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
#=================================================
|
||||
|
||||
# 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
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
|
||||
#=================================================
|
||||
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||
|
@ -57,13 +56,6 @@ ynh_backup --src_path="/etc/logrotate.d/$app"
|
|||
|
||||
ynh_backup --src_path="/etc/systemd/system/$app.service"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE POSTQRESQL DATABASE
|
||||
#=================================================
|
||||
ynh_print_info --message="Backing up the PostgreSQL database..."
|
||||
|
||||
ynh_psql_dump_db --database="$db_name" > db.sql
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
|
|
@ -72,8 +72,6 @@ ynh_app_setting_set --app=$app --key=port --value=$port
|
|||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..." --weight=6
|
||||
|
||||
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
|
||||
if [ "$export" = "abiword" ]; then
|
||||
|
@ -93,13 +91,11 @@ ynh_system_user_create --username=$app --home_dir=$final_path
|
|||
#=================================================
|
||||
# CREATE A POSTQRESQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=5
|
||||
ynh_script_progression --message="Creating a Redis database..." --weight=5
|
||||
|
||||
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
||||
db_user=$db_name
|
||||
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
||||
ynh_psql_test_if_first_run
|
||||
ynh_psql_setup_db --db_user=$db_name --db_name=$db_name
|
||||
# Configure redis
|
||||
redis_db=$(ynh_redis_get_free_db)
|
||||
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
|
@ -207,7 +203,7 @@ then
|
|||
ynh_permission_update --permission="main" --add="visitors"
|
||||
fi
|
||||
|
||||
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --auth_header=false
|
||||
ynh_permission_create --permission="admin" --url="/admin" --allowed="$admin" --auth_header="false"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
|
|
|
@ -19,9 +19,9 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
db_user=$db_name
|
||||
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
||||
export=$(ynh_app_setting_get --app=$app --key=export)
|
||||
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
|
@ -63,12 +63,11 @@ ynh_script_progression --message="Removing NodeJS version for Etherpad..." --wei
|
|||
ynh_remove_nodejs
|
||||
|
||||
#=================================================
|
||||
# REMOVE THE POSTQRESQL DATABASE
|
||||
# REMOVE THE REDIS DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing the PostgreSQL database..." --weight=2
|
||||
ynh_script_progression --message="Removing the redis database..."
|
||||
|
||||
# Remove a database if it exists, along with the associated user
|
||||
ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
|
||||
ynh_redis_remove_db "$redis_db"
|
||||
|
||||
#=================================================
|
||||
# REMOVE ETHERPAD MAIN DIR
|
||||
|
|
|
@ -23,8 +23,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|||
language=$(ynh_app_setting_get --app=$app --key=language)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
password=$(ynh_app_setting_get --app=$app --key=password)
|
||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
||||
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
|
@ -37,18 +36,18 @@ upgrade_type=$(ynh_check_app_version_changed)
|
|||
#=================================================
|
||||
ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
|
||||
|
||||
# If db_name doesn't exist, create it
|
||||
if [ -z "$db_name" ]; then
|
||||
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
||||
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
||||
fi
|
||||
|
||||
# If final_path doesn't exist, create it
|
||||
if [ -z "$final_path" ]; then
|
||||
final_path=/var/www/$app
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
fi
|
||||
|
||||
# If redis_db doesn't exist, create it
|
||||
if [ -z "$redis_db" ]; then
|
||||
redis_db=$(ynh_redis_get_free_db)
|
||||
ynh_app_setting_get --app=$app --key=redis_db --value=$redis_db
|
||||
fi
|
||||
|
||||
# Cleaning legacy permissions
|
||||
if ynh_legacy_permissions_exists; then
|
||||
ynh_legacy_permissions_delete_all
|
||||
|
@ -58,7 +57,7 @@ fi
|
|||
|
||||
if ! ynh_permission_exists --permission="admin"; then
|
||||
# Create the required permissions
|
||||
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --auth_header=false
|
||||
ynh_permission_create --permission="admin" --url="/admin" --allowed="$admin" --auth_header="false"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -101,7 +100,7 @@ then
|
|||
ynh_script_progression --message="Upgrading source files..." --weight=1
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$final_path"
|
||||
ynh_setup_source --dest_dir="$final_path" --keep="$final_path/settings.json $final_path/credentials.json"
|
||||
fi
|
||||
|
||||
# Set permissions on app files
|
||||
|
@ -122,18 +121,16 @@ ynh_add_nginx_config
|
|||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..." --weight=12
|
||||
|
||||
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reconfiguring Etherpad..." --weight=6
|
||||
# ynh_script_progression --message="Reconfiguring Etherpad..." --weight=6
|
||||
|
||||
ynh_add_config --template="../conf/settings.json" --destination="$final_path/settings.json"
|
||||
ynh_add_config --template="../conf/credentials.json" --destination="$final_path/credentials.json"
|
||||
chmod 400 "$final_path/credentials.json"
|
||||
# ynh_add_config --template="../conf/settings.json" --destination="$final_path/settings.json"
|
||||
# ynh_add_config --template="../conf/credentials.json" --destination="$final_path/credentials.json"
|
||||
# chmod 400 "$final_path/credentials.json"
|
||||
|
||||
#=================================================
|
||||
# INSTALL ETHERPAD
|
||||
|
|
Loading…
Add table
Reference in a new issue