1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/snipeit_ynh.git synced 2024-09-03 20:26:16 +02:00
* Add redis (#25)
This commit is contained in:
Éric Gaspar 2021-11-19 15:05:33 +01:00 committed by GitHub
parent 5b31dced63
commit 7461b1d0f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 90 additions and 49 deletions

View file

@ -17,7 +17,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
Manage assets for IT operations Manage assets for IT operations
**Shipped version:** 5.3.1~ynh1 **Shipped version:** 5.3.1~ynh2
**Demo:** https://snipeitapp.com/demo/ **Demo:** https://snipeitapp.com/demo/

View file

@ -13,7 +13,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour
Gestionnaire de ressources informatiques Gestionnaire de ressources informatiques
**Version incluse :** 5.3.1~ynh1 **Version incluse :** 5.3.1~ynh2
**Démo :** https://snipeitapp.com/demo/ **Démo :** https://snipeitapp.com/demo/

View file

@ -3,7 +3,7 @@
# -------------------------------------------- # --------------------------------------------
APP_ENV=production APP_ENV=production
APP_DEBUG=false APP_DEBUG=false
APP_KEY=ChangeMe APP_KEY=__KEY__
APP_URL=http://__DOMAIN__ APP_URL=http://__DOMAIN__
APP_TIMEZONE='UTC' APP_TIMEZONE='UTC'
APP_LOCALE=__LANGUAGE__ APP_LOCALE=__LANGUAGE__
@ -77,9 +77,9 @@ CACHE_PREFIX=snipeit
# -------------------------------------------- # --------------------------------------------
# OPTIONAL: REDIS SETTINGS # OPTIONAL: REDIS SETTINGS
# -------------------------------------------- # --------------------------------------------
REDIS_HOST=null REDIS_HOST="127.0.0.1"
REDIS_PASSWORD=null REDIS_PASSWORD=null
REDIS_PORT=null REDIS_PORT=__REDIS_DB__
# -------------------------------------------- # --------------------------------------------
# OPTIONAL: MEMCACHED SETTINGS # OPTIONAL: MEMCACHED SETTINGS

View file

@ -4,11 +4,6 @@ location ^~ __PATH__/ {
# Path to source # Path to source
alias __FINALPATH__/public/; alias __FINALPATH__/public/;
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
index index.php; index index.php;
# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file

View file

@ -6,7 +6,7 @@
"en": "Manage assets for IT operations", "en": "Manage assets for IT operations",
"fr": "Gestionnaire de ressources informatiques" "fr": "Gestionnaire de ressources informatiques"
}, },
"version": "5.3.1~ynh1", "version": "5.3.1~ynh2",
"url": "https://snipeitapp.com/", "url": "https://snipeitapp.com/",
"upstream": { "upstream": {
"license": "MIT", "license": "MIT",

View file

@ -21,5 +21,43 @@ YNH_COMPOSER_VERSION=2.0.14
#================================================= #=================================================
#================================================= #=================================================
# FUTURE OFFICIAL HELPERS # REDIS 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
}

View file

@ -29,7 +29,8 @@ admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE language=$YNH_APP_ARG_LANGUAGE
email=$(ynh_user_get_info --username=$admin --key=mail) email=$(ynh_user_get_info --username=$admin --key=mail)
key= key=$(ynh_string_random --length=24)
phpversion=$YNH_PHP_VERSION
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -53,6 +54,7 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=language --value=$language ynh_app_setting_set --app=$app --key=language --value=$language
ynh_app_setting_set --app=$app --key=phpversion --value=$phpversion
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
@ -73,6 +75,14 @@ db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
@ -90,14 +100,6 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=5
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create --username=$app
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
#================================================= #=================================================
@ -105,7 +107,6 @@ ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
# Create a dedicated PHP-FPM config # Create a dedicated PHP-FPM config
ynh_add_fpm_config --usage=low --footprint=low ynh_add_fpm_config --usage=low --footprint=low
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
@ -122,6 +123,10 @@ ynh_install_composer
#================================================= #=================================================
ynh_script_progression --message="Building..." ynh_script_progression --message="Building..."
# Configure redis
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
ynh_add_config --template="../conf/.env" --destination="$final_path/.env" ynh_add_config --template="../conf/.env" --destination="$final_path/.env"
chmod 600 "$final_path/.env" chmod 600 "$final_path/.env"
@ -143,7 +148,7 @@ popd
ynh_script_progression --message="Securing files and directories..." --weight=1 ynh_script_progression --message="Securing files and directories..." --weight=1
# Set permissions to app files # Set permissions to app files
chown -R $app: $final_path chown -R $app:www-data $final_path
chmod -R o-rwx $final_path chmod -R o-rwx $final_path
chmod -R 755 $final_path/storage chmod -R 755 $final_path/storage
chmod -R 755 $final_path/public/uploads chmod -R 755 $final_path/public/uploads
@ -151,7 +156,7 @@ chmod -R 755 $final_path/public/uploads
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Configuring SSOwat..." --weight=3 ynh_script_progression --message="Configuring permissions..." --weight=3
# Make app public if necessary or protect it # Make app public if necessary or protect it
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]

View file

@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -31,6 +32,13 @@ ynh_script_progression --message="Removing the MySQL database" --weight=1
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE THE REDIS DATABASE
#=================================================
ynh_script_progression --message="Removing the redis database..."
ynh_redis_remove_db "$redis_db"
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================

View file

@ -50,6 +50,14 @@ ynh_script_progression --message="Restoring the nginx configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=2
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
@ -57,22 +65,9 @@ ynh_script_progression --message="Restoring Snipe-IT main directory..." --weight
ynh_restore_file --origin_path="$final_path" ynh_restore_file --origin_path="$final_path"
#================================================= chmod 750 "$final_path"
# RECREATE THE DEDICATED USER chmod -R o-rwx "$final_path"
#================================================= chown -R $app:www-data "$final_path"
ynh_script_progression --message="Recreating the dedicated system user..." --weight=2
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# RESTORE USER RIGHTS
#=================================================
ynh_script_progression --message="Restoring user rights..."
# Restore permissions on app files
chown -R $app: $final_path
chmod -R o-rwx $final_path
#================================================= #=================================================
# RESTORE THE PHP-FPM CONFIGURATION # RESTORE THE PHP-FPM CONFIGURATION

View file

@ -68,6 +68,14 @@ if ynh_legacy_permissions_exists; then
ynh_app_setting_delete --app=$app --key=is_public ynh_app_setting_delete --app=$app --key=is_public
fi fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#================================================= #=================================================
@ -97,14 +105,6 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=3
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
#================================================= #=================================================
@ -143,7 +143,7 @@ ynh_store_file_checksum --file="$final_path/.env"
ynh_script_progression --message="Securing files and directories..." --weight=1 ynh_script_progression --message="Securing files and directories..." --weight=1
# Set permissions on app files # Set permissions on app files
chown -R $app: $final_path chown -R $app:www-data $final_path
chmod -R o-rwx $final_path chmod -R o-rwx $final_path
chmod -R 755 $final_path/storage chmod -R 755 $final_path/storage
chmod -R 755 $final_path/public/uploads chmod -R 755 $final_path/public/uploads