1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dont-code_ynh.git synced 2024-09-03 18:26:34 +02:00

Several fixes

This commit is contained in:
Gérard Collin 2022-12-30 10:21:10 +01:00
parent 52e6dcc7a0
commit 58b419b5c3
5 changed files with 96 additions and 86 deletions

View file

@ -8,6 +8,12 @@ java_version=17
# Java dependencies used by the app will be installed through the Java helper
pkg_dependencies=""
# List of services to be installed
SERVICES_LIST=(ide preview project data)
# List of Mongo databases to manage
MONGO_DB_LIST=(dontCodeProjects dontCodeDemoProjects dontCodeData)
#=================================================
# PERSONAL HELPERS
#=================================================

View file

@ -8,6 +8,7 @@
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_mongo_db__2
source /usr/share/yunohost/helpers
#=================================================
@ -30,9 +31,7 @@ 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)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
@ -51,10 +50,10 @@ ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE DATA DIR
# BACKUP THE DOCUMENT DIR
#=================================================
ynh_backup --src_path="$datadir" --is_big
ynh_backup --src_path="$document_path" --is_big
#=================================================
# BACKUP THE NGINX CONFIGURATION
@ -62,19 +61,6 @@ ynh_backup --src_path="$datadir" --is_big
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#=================================================
# BACKUP FAIL2BAN CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
@ -84,28 +70,29 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
# BACKUP SYSTEMD services
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
for service_name in "${SERVICES_LIST[@]}"
do
ynh_backup --src_path="/etc/systemd/system/${app}-${service_name}.service"
done
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/etc/$app/"
# ynh_backup --src_path="/etc/cron.d/$app"
#=================================================
# BACKUP THE MYSQL DATABASE
# BACKUP THE MONGO DATABASES
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_print_info --message="Backing up the Mongo databases..."
### (However, things like MySQL dumps *do* take some time to run, though the
### copy of the generated dump to the archive still happens later)
ynh_mysql_dump_db --database="$db_name" > db.sql
for db_name in "${MONGO_DB_LIST[@]}"
do
ynh_mongo_dump_db --database=$db_name > ./dump-${db_name}.bson
done
#=================================================
# END OF SCRIPT

View file

@ -22,8 +22,6 @@ ynh_clean_setup () {
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
SERVICES_LIST=(ide preview project data)
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
@ -139,8 +137,6 @@ ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell --gr
#=================================================
ynh_script_progression --message="Creating the Mongo databases..." --weight=1
# No need to create the database for data and demoProjects, and the user is not used
#db_project_name=$(ynh_sanitize_dbid --db_name="${app}-projects")
#db_demo_project_name=$(ynh_sanitize_dbid --db_name="${app}-demo-projects")
#db_data_name=$(ynh_sanitize_dbid --db_name="${app}-data")
@ -148,10 +144,11 @@ db_user=$(ynh_sanitize_dbid --db_name="${app}")
#ynh_app_setting_set --app=$app --key=db_project_name --value=$db_project_name
#ynh_app_setting_set --app=$app --key=db_demo_project_name --value=$db_demo_project_name
#ynh_app_setting_set --app=$app --key=db_data_name --value=$db_data_name
#ynh_app_setting_set --app=$app --key=db_user --value=$db_user
ynh_app_setting_set --app=$app --key=db_user --value=$db_user
#We should probably enable databases to the user, but for now, we connect through admin
ynh_mongo_setup_db --db_user=$db_user --db_name=dontCodeProjects
ynh_mongo_setup_db --db_user=$db_user --db_name=${MONGO_DB_LIST[0]}
#No need to create other databases: Mongo creates them on the fly
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -210,12 +207,16 @@ document_path=/var/www/$app/documents
test ! -e "$document_path" || ynh_die --message="This path already contains a folder"
mkdir --parents $document_path
ynh_app_setting_set --app=$app --key=document_path --value=$document_path
chmod 750 "$document_path"
chmod -R o-rwx "$document_path"
chown -R $app:www-data "$document_path"
document_url=https://${domain}${path_url}/documents
ynh_app_setting_set --app=$app --key=document_url --value=$document_url
#=================================================
# DONT CREATE A DATA DIRECTORY
#=================================================

View file

@ -23,11 +23,10 @@ port_ide=$(ynh_app_setting_get --app=$app --key=port_ide)
port_preview=$(ynh_app_setting_get --app=$app --key=port_preview)
port_project=$(ynh_app_setting_get --app=$app --key=port_project)
port_data=$(ynh_app_setting_get --app=$app --key=port_data)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
SERVICES_LIST=(ide preview project data)
PORT_LIST=($port_ide $port_preview $port_project $port_data)
#=================================================
@ -71,10 +70,10 @@ ynh_remove_logrotate
ynh_script_progression --message="Removing the Mongo database..." --weight=1
# Remove a database if it exists, along with the associated user
ynh_mongo_remove_db --db_user=$db_user --db_name=dontCodeProjects
ynh_mongo_remove_db --db_user=$db_user --db_name=dontCodeDemoProjects
ynh_mongo_remove_db --db_user=$db_user --db_name=dontCodeData
for db_name in "${MONGO_DB_LIST[@]}"
do
ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name
done
# Remove mongo itself if not used anymore
ynh_remove_mongo
@ -86,6 +85,14 @@ ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE DOCUMENT DIR
#=================================================
ynh_script_progression --message="Removing document directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$document_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================

View file

@ -8,6 +8,8 @@
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_mongo_db__2
source ../settings/scripts/ynh_java
source /usr/share/yunohost/helpers
#=================================================
@ -31,10 +33,9 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
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
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
public_key=$(ynh_app_setting_get --app=$app --key=public_key)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
@ -69,16 +70,24 @@ ynh_restore_file --origin_path="$final_path"
# this will be treated as a security issue.
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
chown -R $app:$app "$final_path"
#Make sure the .ssh and files have the correct access rights
if [ -n "$public_key" ]
then
chown -R $app:$app "$final_path/.ssh"
chmod 700 "$final_path/.ssh"
chmod 600 "$final_path/.ssh/authorized_keys"
fi
#=================================================
# RESTORE THE DATA DIRECTORY
# RESTORE THE DOCUMENTS DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=1
ynh_script_progression --message="Restoring the document directory..." --weight=1
ynh_restore_file --origin_path="$datadir" --not_mandatory
ynh_restore_file --origin_path="$document_path" --not_mandatory
mkdir -p $datadir
mkdir -p $document_path
# FIXME: this should be managed by the core in the future
# Here, as a packager, you may have to tweak the ownerhsip/permissions
@ -86,18 +95,9 @@ mkdir -p $datadir
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
chmod 750 "$document_path"
chmod -R o-rwx "$document_path"
chown -R $app:www-data "$document_path"
#=================================================
# SPECIFIC RESTORATION
@ -106,15 +106,14 @@ ynh_systemd_action --action=restart --service_name=fail2ban
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
# Install the required version of Java
ynh_install_java --java_version=17 --jdk_type=jre
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the PHP-FPM configuration..." --time --weight=1
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
# Install the required version of Mongo
ynh_install_mongo --mongo_version=6.0
#=================================================
# RESTORE THE NGINX CONFIGURATION
@ -124,30 +123,35 @@ ynh_script_progression --message="Restoring the NGINX web server configuration..
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE MYSQL DATABASE
# RESTORE THE MONGO DATABASES
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
ynh_script_progression --message="Restoring the Mongo database..." --weight=1
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
ynh_mongo_setup_db --db_user=$db_user --db_name=${MONGO_DB_LIST[0]} --db_pwd=$db_pwd
for db_name in "${MONGO_DB_LIST[@]}"
do
ynh_mongo_restore_db --database="$db_name" < ./dump-${db_name}.bson
done
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..." --weight=1
ynh_restore_file --origin_path="/etc/cron.d/$app"
ynh_restore_file --origin_path="/etc/$app/"
# ynh_restore_file --origin_path="/etc/cron.d/$app"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
for service_name in "${SERVICES_LIST[@]}"
do
ynh_restore_file --origin_path="/etc/systemd/system/${app}-${service_name}.service"
systemctl enable "${app}-${service_name}.service" --quiet
done
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
@ -157,27 +161,32 @@ ynh_script_progression --message="Restoring the logrotate configuration..." --we
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
# INTEGRATE SERVICES IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression --message="Integrating services in YunoHost..." --weight=1
yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
for service_name in "${SERVICES_LIST[@]}"
do
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
done
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression --message="Starting systemd services..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
for service_name in "${SERVICES_LIST[@]}"
do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
done
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload
#=================================================